Skip to content

Commit a4bd1f2

Browse files
committed
fix: Fix Launch screen constraints, unify all binding calls in providers
1 parent 74d3490 commit a4bd1f2

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

Sample/LaunchScreen.storyboard

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17126"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17125"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -33,16 +33,19 @@
3333
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
3434
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
3535
<subviews>
36-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="GRProvider" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Px6-L0-JnI">
37-
<rect key="frame" x="122" y="429" width="170" height="39"/>
38-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
36+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="GRProvider" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Px6-L0-JnI">
37+
<rect key="frame" x="122" y="428.5" width="170" height="39"/>
3938
<fontDescription key="fontDescription" type="boldSystem" pointSize="32"/>
4039
<nil key="textColor"/>
4140
<nil key="highlightedColor"/>
4241
</label>
4342
</subviews>
4443
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
4544
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
45+
<constraints>
46+
<constraint firstItem="Px6-L0-JnI" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="yUC-P9-88F"/>
47+
<constraint firstItem="Px6-L0-JnI" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="z2X-ul-Lcb"/>
48+
</constraints>
4649
</view>
4750
<navigationItem key="navigationItem" id="XII-iU-jW1"/>
4851
</viewController>

Sample/View Controllers/Collection View/DiffableCollectionProviderViewSampleController.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class DiffableCollectionProviderViewSampleController: UIViewController {
1717
@IBOutlet weak var slider: DiffableItemsGeneratorSlider!
1818
@IBOutlet weak var stepLabel: UILabel!
1919

20-
fileprivate lazy var provider = GRDiffableCollectionViewProvider<DiffableSection>()
20+
fileprivate lazy var provider = GRDiffableCollectionViewProvider<DiffableSection>(collectionView: collectionView)
2121

2222
override func viewDidLoad() {
2323
super.viewDidLoad()
@@ -48,7 +48,6 @@ final class DiffableCollectionProviderViewSampleController: UIViewController {
4848
alert.addAction(.init(title: "Cancel", style: .cancel, handler: nil))
4949
self.present(alert, animated: true)
5050
}
51-
provider.bindCollectionView(collectionView)
5251
}
5352

5453
func createLayout() -> UICollectionViewLayout {
@@ -124,13 +123,13 @@ final class DiffableCollectionProviderViewSampleController: UIViewController {
124123
guard let `self` = self else { return }
125124

126125
UIView.animate(withDuration: 0.6) {
127-
self.provider.apply(configurator.sections)
126+
self.provider.bind(to: self.collectionView, sections: configurator.sections)
128127
}
129128
self.stepLabel.text = "Step \(step)/\(steps.count)"
130129
}
131130

132131
DispatchQueue.main.async { [unowned self] in
133-
self.provider.apply(steps[0].sections)
132+
self.provider.bind(to: collectionView, sections: steps[0].sections)
134133
self.stepLabel.text = "Step 1/\(steps.count)"
135134
}
136135
}

Sources/GRProvider/Collection View/Diffable/GRDiffableCollectionViewProvider.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ open class GRDiffableCollectionViewProvider<Section: Sectionable>: NSObject, UIC
2323
public typealias DidEndDraggingProvider = (UIScrollView, Bool) -> ()
2424
public typealias WillEndDraggingProvider = (UIScrollView, CGPoint, UnsafeMutablePointer<CGPoint>) -> ()
2525

26+
public init(collectionView: UICollectionView) {
27+
super.init()
28+
29+
dataSource = DataSource(collectionView: collectionView) { (collectionView, indexPath, item) -> UICollectionViewCell? in
30+
return self.configureCell?(self, collectionView, indexPath, item)
31+
}
32+
33+
dataSource?.supplementaryViewProvider = { (collectionView, string, indexPath) -> UICollectionReusableView? in
34+
return self.configureSupplementaryElementOfKind?(self, collectionView, indexPath, string)
35+
}
36+
}
37+
2638
///Data source
2739
private(set) var dataSource: DataSource?
2840

@@ -55,16 +67,6 @@ open class GRDiffableCollectionViewProvider<Section: Sectionable>: NSObject, UIC
5567
public var count: Int {
5668
return sections.map { $0.items.count }.reduce(0, +)
5769
}
58-
59-
open func bindCollectionView(_ collectionView: UICollectionView) {
60-
dataSource = DataSource(collectionView: collectionView) { (collectionView, indexPath, item) -> UICollectionViewCell? in
61-
return self.configureCell?(self, collectionView, indexPath, item)
62-
}
63-
dataSource?.supplementaryViewProvider = { (collectionView, string, indexPath) -> UICollectionReusableView? in
64-
return self.configureSupplementaryElementOfKind?(self, collectionView, indexPath, string)
65-
}
66-
collectionView.delegate = self
67-
}
6870

6971
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
7072
let selectedItem = sections[indexPath]
@@ -104,8 +106,13 @@ open class GRDiffableCollectionViewProvider<Section: Sectionable>: NSObject, UIC
104106
// MARK: - Binding
105107

106108
/// Binds items to collection view with default reload animation
107-
public func apply(_ sections: [Section], animated: Bool = true, onComplete: @escaping () -> () = {}) {
109+
public func bind(to collectionView: UICollectionView,
110+
sections: [Section],
111+
animated: Bool = true,
112+
onComplete: @escaping () -> () = {}) {
108113
var snapshot = Snapshot()
114+
115+
collectionView.delegate = self
109116

110117
snapshot.appendSections(sections)
111118
for section in sections {

Sources/GRProvider/Table View/Diffable/GRDiffableTableViewProvider.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ open class GRDiffableTableViewProvider<Section: Sectionable>: TableViewProvider<
1515

1616
public init(tableView: UITableView) {
1717
super.init()
18-
self.configureCell = configureCell
1918
self.diffableTableViewProvider = .init(tableView: tableView, cellProvider: { [unowned self] tv, indexPath, item in
2019
self.configureCell?(self, tv, indexPath, item) ?? UITableViewCell()
2120
})

0 commit comments

Comments
 (0)