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
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { | |
let attributes = super.preferredLayoutAttributesFitting(layoutAttributes) | |
attributes.size = .init(width: 250, height: 100) | |
return attributes | |
} |
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
extension ProfileViewController: UICollectionViewDelegateFlowLayout { | |
func collectionView( | |
_ collectionView: UICollectionView, | |
layout collectionViewLayout: UICollectionViewLayout, | |
referenceSizeForHeaderInSection section: Int | |
) -> CGSize { | |
.init(width: 1.0, height: 30.0) | |
} | |
func collectionView( |
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
let dependencies: [ViewDependency] = [ | |
.init("TextCell", withNib: false), | |
.init("NamedImageCell", withNib: false), | |
.init("AttributeCell", withNib: false), | |
.init("TextHeaderView", viewKind: UICollectionView.elementKindSectionHeader) | |
] |
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
let profileImagePath = Bundle.main.path(forResource: profile.imageFileName, ofType: nil) ?? "" | |
collectionData.onNext([ | |
.init( | |
model: TextHeaderViewModel(text: "Main Info"), | |
items: [NamedImageCellModel(name: profile.name, imageFilePath: profileImagePath)] | |
), | |
.init( | |
model: TextHeaderViewModel(text: "About Me"), | |
items: [TextCellModel(text: profile.about)] |
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
class NamedImageCell: UICollectionViewCell, ViewRepresentable { | |
private weak var imageView: UIImageView! | |
private weak var nameLabel: UILabel! | |
var model: NamedImageCellModel! { | |
didSet { | |
setupViewModel() | |
} | |
} | |
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
class NamedImageCellModel: CollectionItemViewModel { | |
let name: String | |
let imageFilePath: String | |
init(name: String, imageFilePath: String) { | |
self.name = name | |
self.imageFilePath = imageFilePath | |
} | |
} |
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
import UIKit | |
import RxSwift | |
class ProfileViewController: | |
UICollectionViewController, | |
ViewRepresentable, | |
RxDataSourceRepresentableView | |
{ | |
var model: ProfileViewModel! | |
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
import RxSwift | |
class ProfileViewModel: ViewModel, RxDataSourceProvider { | |
let collectionData = BehaviorSubject<[SectionData]>(value: []) | |
lazy var profile: Profile = { | |
let decoder = JSONDecoder() | |
let url = Bundle.main.url(forResource: "info", withExtension: "json")! | |
return try! decoder.decode(Profile.self, from: .init(contentsOf: url)) |
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
protocol RxDataSourceProvider { | |
var collectionData: BehaviorSubject<[SectionData]> { get } | |
} | |
protocol RxDataSourceRepresentableView: CollectionItemsViewDependenciesContainable { | |
var dataProvider: RxDataSourceProvider! { get } | |
var disposeBag: DisposeBag { get } | |
} |
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
import RxDataSources | |
import UIKit | |
typealias SectionData = SectionModel<CollectionItemViewModel, CollectionItemViewModel> | |
typealias PreReturnHandler = ( | |
CollectionViewSectionedDataSource<SectionData>, | |
IndexPath, | |
UICollectionViewCell | |
) -> Void |