Skip to content

Commit

Permalink
Simplify by using 0 inset when autoIgnoreContentInset and proper in…
Browse files Browse the repository at this point in the history
…set otherwise
  • Loading branch information
nighthawk committed Mar 13, 2024
1 parent 39e2196 commit e834ddf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
20 changes: 4 additions & 16 deletions Sources/TGCardViewController/cards/TGCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,17 @@ open class TGCard: UIResponder, TGPreferrableView {
/// - headerView: The header view, typically used by `TGPageCard`.
open func didBuild(cardView: TGCardView?, headerView: TGHeaderView?) {
if title.isExtended, let cardView {
cardView.contentScrollView?.contentInset.top = cardView.headerHeight
if autoIgnoreContentInset {
cardView.contentScrollView?.contentOffset.y = 0
}
cardView.contentScrollView?.contentInset.top = autoIgnoreContentInset ? 0 : cardView.headerHeight
}
}

public var autoIgnoreContentInset: Bool = false {
didSet {
guard autoIgnoreContentInset != oldValue, title.isExtended, let cardView, let scrollView = cardView.contentScrollView else { return }

if autoIgnoreContentInset, scrollView.contentOffset.y < 0 {
scrollView.contentOffset.y = 0
cardView.showSeparator(true, offset: 0)

} else if !autoIgnoreContentInset, scrollView.contentOffset.y > cardView.headerHeight * -1 {
scrollView.contentOffset.y = cardView.headerHeight * -1
cardView.showSeparator(true, offset: cardView.headerHeight * -1)
}
scrollView.contentInset.top = autoIgnoreContentInset ? 0 : cardView.headerHeight
scrollView.contentOffset.y = autoIgnoreContentInset ? 0 : cardView.headerHeight * -1
cardView.showSeparator(true, offset: scrollView.contentOffset.y)
}
}

Expand Down Expand Up @@ -277,10 +269,6 @@ open class TGCard: UIResponder, TGPreferrableView {
open func willAppear(animated: Bool) {
// print("+. \(title) will appear")

if autoIgnoreContentInset {
cardView?.contentScrollView?.contentOffset.y = 0
}

viewIsVisible = true
}

Expand Down
5 changes: 1 addition & 4 deletions Sources/TGCardViewController/cards/TGScrollCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ public class TGScrollCardView: TGCardView {
contentScrollView = scrollView

if card.title.isExtended {
scrollView.contentInset.top = headerHeight
if card.autoIgnoreContentInset {
scrollView.contentOffset.y = 0
}
scrollView.contentInset.top = card.autoIgnoreContentInset ? 0 : headerHeight
}
}

Expand Down

0 comments on commit e834ddf

Please sign in to comment.