Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import UIKit
import RxSwift
import RxCocoa
import RxDataSources
private let reuseIdentifier = "OrderProductItemCell"
class OrderProductItemView: UICollectionViewController {
var viewModel:
OrderProductsViewModel!
var delegate: ProductPicturesDelegate?
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = .white
collectionView?.register(OrderProductItemCell.self, forCellWithReuseIdentifier: reuseIdentifier)
if let layout = collectionViewLayout as? UICollectionViewFlowLayout {
layout.scrollDirection = .horizontal
layout.minimumLineSpacing = 8
layout.itemSize = CGSize(width: 100, height: 100)
layout.minimumInteritemSpacing = 5
}
collectionView?.showsHorizontalScrollIndicator = false
collectionView.dataSource = nil
collectionView.delegate = nil
}
func bindViewModel() {
viewModel.transform().asDriver(onErrorJustReturn: [])
.drive(self.collectionView.rx.items(cellIdentifier: reuseIdentifier, cellType: OrderProductItemCell.self)) { collectionView, viewModel, cell in
cell.bind(to: viewModel)
}.disposed(by: rx.disposeBag)
collectionView.rx.modelSelected(ProductPicturesItemViewModel.self)
.bind { vm in
self.delegate?.didTapOnItem(p: vm.proudctImage)
}.disposed(by: rx.disposeBag)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment