You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.9 KiB
103 lines
2.9 KiB
![]()
2 years ago
|
//
|
||
|
// SinglePickerCell.swift
|
||
![]()
1 year ago
|
// FireBoltt
|
||
![]()
2 years ago
|
//
|
||
|
// Created by lemo on 2018/5/11.
|
||
|
// Copyright © 2020年 ecell. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import UIKit
|
||
|
|
||
|
fileprivate struct Metric {
|
||
|
static let textColor = kHexColor(0x2A2A2A)
|
||
|
static let textFont = SystemLightFont(14)
|
||
|
static let topspace = kScaleHeight(15.0)
|
||
|
}
|
||
|
|
||
|
class SinglePickerCell: TableViewCell {
|
||
|
|
||
![]()
1 year ago
|
var functionType: FunctionTypeFireBoltt? {
|
||
![]()
2 years ago
|
didSet {
|
||
![]()
1 year ago
|
loadFunctionTypeFireBoltt()
|
||
![]()
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
var selectedItem: String? {
|
||
|
didSet {
|
||
|
selectItem()
|
||
|
}
|
||
|
}
|
||
|
|
||
![]()
1 year ago
|
let fbtitleLabel = UILabel().then {
|
||
![]()
2 years ago
|
$0.textColor = Metric.textColor
|
||
|
$0.font = Metric.textFont
|
||
|
$0.textAlignment = .center
|
||
|
}
|
||
|
|
||
![]()
1 year ago
|
let fbpickerView = UIPickerView().then { _ in
|
||
![]()
2 years ago
|
}
|
||
|
|
||
|
typealias SinglePickerClosure = (String) -> Void
|
||
|
var singlePickerClosure: SinglePickerClosure?
|
||
|
let subject = PublishSubject<String>()
|
||
![]()
2 years ago
|
var viewModel = SinglePickerViewModels()
|
||
![]()
2 years ago
|
|
||
|
override func makeUI() {
|
||
|
super.makeUI()
|
||
![]()
1 year ago
|
contentView.addSubview(fbtitleLabel)
|
||
|
contentView.addSubview(fbpickerView)
|
||
![]()
2 years ago
|
}
|
||
|
|
||
|
override func layoutSubviews() {
|
||
|
super.layoutSubviews()
|
||
|
|
||
![]()
1 year ago
|
fbtitleLabel.snp.makeConstraints { (make) in
|
||
![]()
2 years ago
|
make.top.equalToSuperview().offset(Metric.topspace)
|
||
|
make.left.right.equalToSuperview()
|
||
|
}
|
||
|
|
||
|
|
||
![]()
1 year ago
|
fbpickerView.snp.makeConstraints { (make) in
|
||
![]()
2 years ago
|
make.top.equalToSuperview().offset(kScaleHeight(20.0))
|
||
|
make.left.right.equalToSuperview()
|
||
|
make.bottom.equalToSuperview().offset(-kScaleHeight(10.0))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
extension SinglePickerCell {
|
||
|
|
||
|
func selectItem() {
|
||
|
if selectedItem?.count == 1 {
|
||
|
if let idx = viewModel.dataSourceVariable.value.firstIndex(of: selectedItem!) {
|
||
![]()
1 year ago
|
fbpickerView.selectRow(idx, inComponent: 0, animated: false)
|
||
![]()
2 years ago
|
}
|
||
|
}
|
||
|
if let selectedItem = self.selectedItem {
|
||
|
if let idx = viewModel.dataSourceVariable.value.firstIndex(of: selectedItem) {
|
||
![]()
1 year ago
|
fbpickerView.selectRow(idx, inComponent: 0, animated: false)
|
||
![]()
2 years ago
|
}
|
||
|
}else {
|
||
![]()
1 year ago
|
fbpickerView.selectRow(1, inComponent: 0, animated: false)
|
||
![]()
2 years ago
|
}
|
||
|
}
|
||
|
|
||
![]()
1 year ago
|
func loadFunctionTypeFireBoltt() {
|
||
![]()
2 years ago
|
viewModel = SinglePickerViewModels(funtionType: functionType!)
|
||
![]()
2 years ago
|
viewModel.dataSourceVariable.asObservable()
|
||
![]()
1 year ago
|
.bind(to: fbpickerView.rx.items(adapter: SinglePickerViewViewAdapter()))
|
||
![]()
2 years ago
|
.disposed(by: cellDisposeBag)
|
||
![]()
1 year ago
|
fbpickerView.rx.modelSelected(String.self)
|
||
![]()
2 years ago
|
.subscribe(onNext: { [weak self] item in
|
||
|
guard let `self` = self else { return }
|
||
|
if let singlePicker = self.singlePickerClosure {
|
||
|
singlePicker(item.first!)
|
||
|
}
|
||
|
self.subject.onNext(item.first!)
|
||
|
})
|
||
|
.disposed(by: cellDisposeBag)
|
||
|
}
|
||
|
|
||
|
}
|