Skip to content

Commit bc45204

Browse files
author
Martin Barreto
authored
Merge pull request #47 from loryhuz/master
default implementation of insetForSectionAt, UICollectionViewDelegate…
2 parents 0ad038e + 6660e69 commit bc45204

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Example/CustomActionControllers/Tweetbot.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ open class TweetbotActionController: DynamicsActionController<TweetbotCell, Stri
6464
settings.behavior.bounces = true
6565
settings.behavior.useDynamics = true
6666
collectionView.contentInset = UIEdgeInsets(top: 0.0, left: 12.0, bottom: 6.0, right: 12.0)
67-
(collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.sectionInset = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 6.0, right: 0.0)
6867

6968
cellSpec = .nibFile(nibName: "TweetbotCell", bundle: Bundle(for: TweetbotCell.self), height: { _ in 50 })
7069

@@ -100,4 +99,10 @@ open class TweetbotActionController: DynamicsActionController<TweetbotCell, Stri
10099
required public init?(coder aDecoder: NSCoder) {
101100
super.init(coder: aDecoder)
102101
}
102+
103+
// MARK: - UICollectionViewDelegateFlowLayout
104+
105+
open override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
106+
return UIEdgeInsets(top: 0.0, left: 0.0, bottom: 6.0, right: 0.0)
107+
}
103108
}

Source/ActionController.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ open class ActionController<ActionViewType: UICollectionViewCell, ActionDataType
488488
return CGSize.zero
489489
}
490490

491+
open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
492+
return self.collectionViewLayout.sectionInset
493+
}
494+
491495
// MARK: - UIViewControllerTransitioningDelegate
492496

493497
open func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
@@ -723,8 +727,12 @@ open class DynamicsActionController<ActionViewType: UICollectionViewCell, Action
723727
super.viewDidLoad()
724728

725729
collectionView.frame = view.bounds
726-
727-
contentHeight = CGFloat(numberOfActions()) * settings.collectionView.cellHeightWhenDynamicsIsUsed + (CGFloat(_sections.count) * (collectionViewLayout.sectionInset.top + collectionViewLayout.sectionInset.bottom))
730+
731+
contentHeight = CGFloat(numberOfActions()) * settings.collectionView.cellHeightWhenDynamicsIsUsed
732+
for index in 0..<_sections.count {
733+
let sectionInset = collectionView(collectionView, layout: collectionViewLayout, insetForSectionAt: index)
734+
contentHeight += sectionInset.top + sectionInset.bottom
735+
}
728736
contentHeight += collectionView.contentInset.bottom
729737

730738
setUpContentInsetForHeight(view.frame.height)

0 commit comments

Comments
 (0)