Skip to content

Instantly share code, notes, and snippets.

View IsaAliev's full-sized avatar

Isa Aliev IsaAliev

  • Moscow, Russia
View GitHub Profile
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
let attributes = super.preferredLayoutAttributesFitting(layoutAttributes)
attributes.size = .init(width: 250, height: 100)
return attributes
}
extension ProfileViewController: UICollectionViewDelegateFlowLayout {
func collectionView(
_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
referenceSizeForHeaderInSection section: Int
) -> CGSize {
.init(width: 1.0, height: 30.0)
}
func collectionView(
let dependencies: [ViewDependency] = [
.init("TextCell", withNib: false),
.init("NamedImageCell", withNib: false),
.init("AttributeCell", withNib: false),
.init("TextHeaderView", viewKind: UICollectionView.elementKindSectionHeader)
]
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)]
class NamedImageCell: UICollectionViewCell, ViewRepresentable {
private weak var imageView: UIImageView!
private weak var nameLabel: UILabel!
var model: NamedImageCellModel! {
didSet {
setupViewModel()
}
}
class NamedImageCellModel: CollectionItemViewModel {
let name: String
let imageFilePath: String
init(name: String, imageFilePath: String) {
self.name = name
self.imageFilePath = imageFilePath
}
}
import UIKit
import RxSwift
class ProfileViewController:
UICollectionViewController,
ViewRepresentable,
RxDataSourceRepresentableView
{
var model: ProfileViewModel!
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))
protocol RxDataSourceProvider {
var collectionData: BehaviorSubject<[SectionData]> { get }
}
protocol RxDataSourceRepresentableView: CollectionItemsViewDependenciesContainable {
var dataProvider: RxDataSourceProvider! { get }
var disposeBag: DisposeBag { get }
}
import RxDataSources
import UIKit
typealias SectionData = SectionModel<CollectionItemViewModel, CollectionItemViewModel>
typealias PreReturnHandler = (
CollectionViewSectionedDataSource<SectionData>,
IndexPath,
UICollectionViewCell
) -> Void