-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: I started working on adding support for dequeuing cells created from nibs (issue #1). Additionally I extended `IGListSingleSectionController` so that it can be used with nibs too. I don't know if you had this also in mind. - [x] I'm currently thinking about the best way to test these changes. - [x] I was not able to update the documentation (issue #55). - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/CONTRIBUTING.md) Closes #56 Reviewed By: dshahidehpour Differential Revision: D4023746 Pulled By: rnystrom fbshipit-source-id: 6a8b4cfb4dba38ea6e9870a9a4506288ee155cfe
- Loading branch information
Showing
32 changed files
with
682 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
Example/IGListKitExamples/ViewControllers/SingleSectionViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
Copyright (c) 2016-present, Facebook, Inc. All rights reserved. | ||
|
||
The examples provided by Facebook are for non-commercial testing and evaluation | ||
purposes only. Facebook reserves all rights not expressly granted. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import UIKit | ||
import IGListKit | ||
|
||
final class SingleSectionViewController: UIViewController, IGListAdapterDataSource, IGListSingleSectionControllerDelegate { | ||
|
||
lazy var adapter: IGListAdapter = { | ||
return IGListAdapter(updater: IGListAdapterUpdater(), viewController: self, workingRangeSize: 0) | ||
}() | ||
|
||
let collectionView = IGListCollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout()) | ||
|
||
var data = [Int]() | ||
|
||
// MARK: - Lifecycle | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
for index in 0..<20 { | ||
data.append(index) | ||
} | ||
|
||
view.addSubview(collectionView) | ||
adapter.collectionView = collectionView | ||
adapter.dataSource = self | ||
} | ||
|
||
override func viewDidLayoutSubviews() { | ||
super.viewDidLayoutSubviews() | ||
collectionView.frame = view.bounds | ||
} | ||
|
||
//MARK: - IGListAdapterDataSource | ||
|
||
func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] { | ||
return data as [IGListDiffable] | ||
} | ||
|
||
func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController { | ||
let configureBlock = { (data: Any, cell: UICollectionViewCell) in | ||
guard let cell = cell as? NibCell, let number = data as? Int else { return } | ||
cell.textLabel.text = "Cell: \(number + 1)" | ||
} | ||
|
||
let sizeBlock = { (context: IGListCollectionContext) -> CGSize in | ||
return CGSize(width: context.containerSize.width, height: 44) | ||
} | ||
let sectionController = IGListSingleSectionController(nibName: NibCell.nibName, | ||
bundle: nil, | ||
configureBlock: configureBlock, | ||
sizeBlock: sizeBlock) | ||
sectionController.selectionDelegate = self | ||
|
||
return sectionController | ||
} | ||
|
||
func emptyView(for listAdapter: IGListAdapter) -> UIView? { | ||
return nil | ||
} | ||
|
||
// MARK: - IGListSingleSectionControllerDelegate | ||
|
||
func didSelect(_ sectionController: IGListSingleSectionController) { | ||
let section = adapter.section(for: sectionController) + 1 | ||
let alert = UIAlertController(title: "Section \(section) was selected 🎉", message: nil, preferredStyle: .alert) | ||
alert.addAction(UIAlertAction(title: "Dismiss", style: .default, handler: nil)) | ||
present(alert, animated: true, completion: nil) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
Copyright (c) 2016-present, Facebook, Inc. All rights reserved. | ||
|
||
The examples provided by Facebook are for non-commercial testing and evaluation | ||
purposes only. Facebook reserves all rights not expressly granted. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import UIKit | ||
|
||
final class NibCell: UICollectionViewCell { | ||
static let nibName = "NibCell" | ||
@IBOutlet var textLabel: UILabel! | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="Bsi-Xi-IXl" customClass="NibCell" customModule="IGListKitExamples" customModuleProvider="target"> | ||
<rect key="frame" x="0.0" y="0.0" width="626" height="116"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | ||
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center"> | ||
<rect key="frame" x="0.0" y="0.0" width="626" height="116"/> | ||
<autoresizingMask key="autoresizingMask"/> | ||
<subviews> | ||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KmO-E2-9FY" userLabel="Separator"> | ||
<color key="backgroundColor" white="0.94999999999999996" alpha="1" colorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstAttribute="height" constant="1" id="DGO-9u-efg"/> | ||
</constraints> | ||
</view> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fAB-2v-237"> | ||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> | ||
<nil key="textColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="🎉" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qTT-Ka-LDD"> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<nil key="textColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
</view> | ||
<constraints> | ||
<constraint firstItem="KmO-E2-9FY" firstAttribute="trailing" secondItem="qTT-Ka-LDD" secondAttribute="trailing" id="BRa-QC-qg0"/> | ||
<constraint firstAttribute="bottom" secondItem="KmO-E2-9FY" secondAttribute="bottom" id="Uac-CQ-cJ8"/> | ||
<constraint firstItem="qTT-Ka-LDD" firstAttribute="centerY" secondItem="fAB-2v-237" secondAttribute="centerY" id="VFC-J9-qNd"/> | ||
<constraint firstItem="KmO-E2-9FY" firstAttribute="leading" secondItem="fAB-2v-237" secondAttribute="leading" id="WqJ-nx-XeD"/> | ||
<constraint firstAttribute="trailing" secondItem="qTT-Ka-LDD" secondAttribute="trailing" constant="15" id="XaH-vp-MoX"/> | ||
<constraint firstItem="fAB-2v-237" firstAttribute="leading" secondItem="Bsi-Xi-IXl" secondAttribute="leading" constant="15" id="h0E-pO-BbL"/> | ||
<constraint firstItem="fAB-2v-237" firstAttribute="centerY" secondItem="Bsi-Xi-IXl" secondAttribute="centerY" id="oqm-jR-6tv"/> | ||
</constraints> | ||
<size key="customSize" width="626" height="116"/> | ||
<connections> | ||
<outlet property="textLabel" destination="fAB-2v-237" id="0k5-X7-Ifn"/> | ||
</connections> | ||
<point key="canvasLocation" x="164" y="-249"/> | ||
</collectionViewCell> | ||
</objects> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.