jsdw_ios/QuickLocation/Section/Group/GroupViewController.swift

114 lines
3.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// GroupViewController.swift
// QuickLocation
//
import UIKit
import RxSwift
import RxCocoa
import RxDataSources
final class GroupViewController: BaseViewController {
override var isNavigationBarHidden: Bool { true }
fileprivate var rootView: GroupView!
private let viewModel = GroupViewModel()
override func loadView() {
rootView = GroupView(frame: UIScreen.main.bounds)
view = rootView
}
override func viewDidLoad() {
super.viewDidLoad()
bindViewModel()
reactiveAction()
observeTableViews()
viewModel.loadMockData()
}
// MARK: - Bindings
private func bindViewModel() {
//
viewModel.output.hotGroups
.drive(rootView.hotGroupsCollectionView.rx.items(
cellIdentifier: HotGroupCell.reuseId,
cellType: HotGroupCell.self
)) { _, item, cell in
cell.configure(item)
}
.disposed(by: disposeBag)
//
let createdDataSource = RxTableViewSectionedReloadDataSource<CircleListSectionModel>(
configureCell: { (_, tableView, indexPath, model) in
let cell: CircleGroupCell = tableView.dequeueReusableCell(for: indexPath)
cell.configure(model)
return cell
})
viewModel.output.createdSections
.bind(to: rootView.createdTableView.rx.items(dataSource: createdDataSource))
.disposed(by: disposeBag)
//
let joinedDataSource = RxTableViewSectionedReloadDataSource<CircleListSectionModel>(
configureCell: { (_, tableView, indexPath, model) in
let cell: CircleGroupCell = tableView.dequeueReusableCell(for: indexPath)
cell.configure(model)
return cell
})
viewModel.output.joinedSections
.bind(to: rootView.joinedTableView.rx.items(dataSource: joinedDataSource))
.disposed(by: disposeBag)
}
private func reactiveAction() {
rootView.createGroupBtn.rx.tapGesture
.subscribe(onNext: { _ in
// TODO:
})
.disposed(by: disposeBag)
rootView.joinGroupBtn.rx.tapGesture
.subscribe(onNext: { _ in
// TODO:
})
.disposed(by: disposeBag)
rootView.createdTabLabel.rx.tapGesture
.subscribe(onNext: { [weak self] _ in self?.switchToSegment(0) })
.disposed(by: disposeBag)
rootView.joinedTabLabel.rx.tapGesture
.subscribe(onNext: { [weak self] _ in self?.switchToSegment(1) })
.disposed(by: disposeBag)
}
private func switchToSegment(_ index: Int) {
rootView.selectSegment(at: index)
let offset = CGPoint(x: CGFloat(index) * rootView.segmentScrollView.bounds.width, y: 0)
rootView.segmentScrollView.setContentOffset(offset, animated: false)
}
// MARK: - tableView /
private func observeTableViews() {
rootView.createdTableView.rx.didScroll
.subscribe(onNext: { [weak self] in
guard let self = self else { return }
self.rootView.childTableViewDidScroll(self.rootView.createdTableView)
})
.disposed(by: disposeBag)
rootView.joinedTableView.rx.didScroll
.subscribe(onNext: { [weak self] in
guard let self = self else { return }
self.rootView.childTableViewDidScroll(self.rootView.joinedTableView)
})
.disposed(by: disposeBag)
}
}