This file contains hidden or 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
| protocol BulletAdapter: CollectionAdapter { | |
| var identifier: String | |
| var className: String | |
| var height: Float | |
| var bullet: UIImage { get } | |
| var label: NSAttributedString { get } | |
| } | |
| // Descriptor | |
| final class BulletDescriptor: CollectionCellDescribable { |
This file contains hidden or 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
| class MainColorSectionDescriptor: CollectionSectionDescribable { | |
| let backgroundInset = UIEdgeInsetsMake(10, 10, 10, 10) | |
| } | |
| class MyLayout: UICollectionViewFlowLayout { | |
| //... | |
| var backgroundAttributes = [IndexPath:UICollectionViewLayoutAttributes]() | |
| override func prepare() { |
This file contains hidden or 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
| import Foundation | |
| struct Style { | |
| let styling : (String) -> NSMutableAttributedString | |
| } | |
| extension Style { | |
| static let myStyle = Style { (string) -> NSMutableAttributedString in | |
| return NSMutableAttributedString(string: string) // add your attributes here | |
| } |
This file contains hidden or 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
| func fetch() { | |
| realTimeService.getRecentTweets { [weak self] response in | |
| switch response { | |
| case .success(let data): | |
| self?.collectionData.update(model: data) | |
| let result = self?.collectionData.update { updater in | |
| updater.diff() | |
| } | |
| if let result = result { | |
| self?.collectionView.performUpdates(with: result) |
This file contains hidden or 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
| struct TweetAdapter: CollectionAdapter, Diffable { | |
| let label:NSAttributedString | |
| let imageURL:URL | |
| let backgroundColor:UIColor | |
| init(tweet:Tweet) { | |
| label = ... | |
| imageURL = ... | |
| backgroundColor = ... |
This file contains hidden or 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
| final class RealTimeCollectionData : CollectionData { | |
| var model:RealTimeModel? | |
| func update(model:RealTimeModel) { | |
| self.model = model | |
| } | |
| override func reloadData() { | |
| super.reloadData() |
This file contains hidden or 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
| fileprivate lazy var decorationViewHandler:DecorationViewsHandler = DecorationViewsHandler(collectionViewLayout: self) | |
| // ... | |
| decorationViewHandler.register(viewClass: SimpleDecorationView.self, for: sectionBackgroundKind) |
This file contains hidden or 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
| override func prepare() { | |
| super.prepare() | |
| decorationViewHandler.prepare() | |
| //... | |
| let backgroundAttributes = SimpleDecorationViewLayoutAttributes(forDecorationViewOfKind: sectionBackgroundKind, with: firstCellIndexPath) | |
| decorationViewHandler.add(attributes: backgroundAttributes) | |
| } | |
| override func layoutAttributesForDecorationView(ofKind elementKind: String, at atIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? { | |
| return decorationViewHandler.attributes(for: elementKind, at: atIndexPath) |
This file contains hidden or 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
| let decorationAttributes = decorationViewHandler.attributes(in:rect) |
This file contains hidden or 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
| override func prepare(forCollectionViewUpdates updateItems: [UICollectionViewUpdateItem]) { | |
| super.prepare(forCollectionViewUpdates: updateItems) | |
| decorationViewHandler.prepare(forCollectionViewUpdates: updateItems) | |
| } | |
| override func indexPathsToInsertForDecorationView(ofKind elementKind: String) -> [IndexPath] { | |
| return decorationViewHandler.inserted(for: elementKind) | |
| } | |
| override func indexPathsToDeleteForDecorationView(ofKind elementKind: String) -> [IndexPath] { |