Skip to content

Instantly share code, notes, and snippets.

@alouanemed
Created December 11, 2019 21:02
Show Gist options
  • Save alouanemed/11135d30245dd44a720960d8c96104b1 to your computer and use it in GitHub Desktop.
Save alouanemed/11135d30245dd44a720960d8c96104b1 to your computer and use it in GitHub Desktop.
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