-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π²[Native Checkout] "Peek" functionality using hidden scroll view #665
Changes from 1 commit
9406300
b0aa974
85db760
48a3e1f
5fcf780
21216ac
2e4ddc2
8b7f848
a405611
7aa0272
6c92d7d
992f1e4
21ba760
88ef739
a31a1ae
d60f4aa
1037763
e5d3515
c9eb6ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ final class RewardsCollectionViewController: UICollectionViewController { | |
}() | ||
|
||
private var flowLayout: UICollectionViewFlowLayout? { | ||
return self.collectionViewLayout as? UICollectionViewFlowLayout | ||
return self.collectionView.collectionViewLayout as? UICollectionViewFlowLayout | ||
} | ||
|
||
static func instantiate(with project: Project, refTag: RefTag?) -> RewardsCollectionViewController { | ||
|
@@ -65,7 +65,7 @@ final class RewardsCollectionViewController: UICollectionViewController { | |
super.viewDidLoad() | ||
|
||
_ = self.collectionView | ||
|> \.dataSource .~ dataSource | ||
|> \.dataSource .~ self.dataSource | ||
|
||
self.collectionView.register(RewardCell.self) | ||
|
||
|
@@ -79,11 +79,15 @@ final class RewardsCollectionViewController: UICollectionViewController { | |
|
||
guard let layout = self.flowLayout else { return } | ||
|
||
layout.itemSize = self.calculateItemSize(from: layout, using: self.collectionView) | ||
|
||
self.updateHiddenScrollViewBoundsIfNeeded(for: layout) | ||
} | ||
|
||
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { | ||
super.viewWillTransition(to: size, with: coordinator) | ||
|
||
self.flowLayout?.invalidateLayout() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've noticed that no matter what the current horizontal offset rotating the device always resets it to 0 therefore scrolls back to the very first reward. There should be a way to either cache current page and upon rotation restore the scroll offset (maybe inside the coordinator completion handler)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd prefer to implement this separately as an enhancement. I'll create a card π |
||
} | ||
|
||
override func bindStyles() { | ||
super.bindStyles() | ||
|
||
|
@@ -170,21 +174,29 @@ final class RewardsCollectionViewController: UICollectionViewController { | |
|
||
private func calculateItemSize(from layout: UICollectionViewFlowLayout, | ||
using collectionView: UICollectionView) -> CGSize { | ||
let cardWidth: CGFloat = RewardCell.fixedCardWidth | ||
let cardWidth: CGFloat = Layout.Card.width | ||
|
||
let sectionInsets = layout.sectionInset | ||
let topBottomInsets = sectionInsets.top + sectionInsets.bottom | ||
var adjustedContentInset = UIEdgeInsets.zero | ||
|
||
if #available(iOS 11.0, *) { | ||
adjustedContentInset = collectionView.adjustedContentInset | ||
} | ||
|
||
let topBottomSectionInsets = sectionInsets.top + sectionInsets.bottom | ||
let topBottomContentInsets = adjustedContentInset.top + adjustedContentInset.bottom | ||
let leftRightInsets = sectionInsets.left + sectionInsets.right | ||
|
||
let itemHeight = collectionView.contentSize.height - topBottomInsets | ||
let itemHeight = collectionView.frame.height - topBottomSectionInsets - topBottomContentInsets | ||
let itemWidth = cardWidth - leftRightInsets | ||
|
||
return CGSize(width: itemWidth, height: itemHeight) | ||
} | ||
|
||
// MARK: - Public Functions | ||
|
||
@objc func closeButtonTapped() { | ||
self.navigationController?.dismiss(animated: true, completion: nil) | ||
self.navigationController?.dismiss(animated: true) | ||
} | ||
} | ||
|
||
|
@@ -198,7 +210,22 @@ extension RewardsCollectionViewController { | |
} | ||
} | ||
|
||
extension RewardsCollectionViewController: UICollectionViewDelegateFlowLayout { | ||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, | ||
sizeForItemAt indexPath: IndexPath) -> CGSize { | ||
guard let layout = collectionViewLayout as? UICollectionViewFlowLayout else { | ||
return .zero | ||
} | ||
|
||
// Cache the itemSize so we can recalculate hidden scroll view data efficiently | ||
layout.itemSize = self.calculateItemSize(from: layout, using: collectionView) | ||
|
||
return layout.itemSize | ||
} | ||
} | ||
|
||
// MARK: Styles | ||
|
||
private var collectionViewStyle = { collectionView -> UICollectionView in | ||
collectionView | ||
|> \.backgroundColor .~ .ksr_grey_200 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an ideal scenario...this
guard
is repeated twice in the flow...first time here...second time inupdateHiddenScrollViewBoundsIfNeeded
. In order to make each function independent of the state of the view controller could we do thisor even something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, will update the
updateHiddenScrollViewBoundsIfNeeded
to acceptlayout
as an argument π