fix: access to view model initializer + renames
This commit is contained in:
parent
4c525b8dad
commit
6ef2c83990
|
|
@ -26,6 +26,17 @@ public struct DefaultFilterRowViewModel: FilterRowRepresentable, Equatable {
|
|||
public var appearance: FilterCellAppearanceProtocol
|
||||
public var isSelected: Bool
|
||||
|
||||
public init(id: String,
|
||||
title: String,
|
||||
appearance: FilterCellAppearanceProtocol,
|
||||
isSelected: Bool) {
|
||||
|
||||
self.id = id
|
||||
self.title = title
|
||||
self.appearance = appearance
|
||||
self.isSelected = isSelected
|
||||
}
|
||||
|
||||
public static func == (lhs: Self, rhs: Self) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@
|
|||
|
||||
public protocol FilterListPickerConfigurator: AnyObject {
|
||||
|
||||
associatedtype CellViewModel: FilterRowRepresentable & Equatable
|
||||
associatedtype RowViewModel: FilterRowRepresentable & Equatable
|
||||
|
||||
var visibleValues: [CellViewModel] { get }
|
||||
var visibleValues: [RowViewModel] { get }
|
||||
var isMultiselectionEnabled: Bool { get set }
|
||||
var isFinishWithSeparator: Bool { get }
|
||||
|
||||
func setSelected(model: CellViewModel, isSelected: Bool)
|
||||
func setSelected(model: RowViewModel, isSelected: Bool)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,4 +25,9 @@ public protocol FilterRowRepresentable {
|
|||
var title: String { get }
|
||||
var isSelected: Bool { get set }
|
||||
var appearance: FilterCellAppearanceProtocol { get set }
|
||||
|
||||
init(id: String,
|
||||
title: String,
|
||||
appearance: FilterCellAppearanceProtocol,
|
||||
isSelected: Bool)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,5 +26,5 @@ import TIUIElements
|
|||
public protocol FilterTableSectionBuilder {
|
||||
associatedtype CellType: BaseSeparatorCell & ConfigurableCell
|
||||
|
||||
func makeSection<ViewModel: FilterListPickerConfigurator>(with viewModel: ViewModel) -> TableSection where ViewModel.CellViewModel == CellType.CellData
|
||||
func makeSection<ViewModel: FilterListPickerConfigurator>(with viewModel: ViewModel) -> TableSection where ViewModel.RowViewModel == CellType.CellData
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,15 +20,15 @@
|
|||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
open class BaseListFilterViewModel<CellViewModelType: FilterRowRepresentable & Equatable>: FilterListPickerConfigurator {
|
||||
open class BaseListFilterViewModel<RowViewModelType: FilterRowRepresentable & Equatable>: FilterListPickerConfigurator {
|
||||
|
||||
public typealias CellViewModel = CellViewModelType
|
||||
public typealias RowViewModel = RowViewModelType
|
||||
|
||||
public var rowViewModels: [CellViewModelType]
|
||||
public var rowViewModels: [RowViewModelType]
|
||||
|
||||
public weak var delegate: FiltersPickerDelegate?
|
||||
|
||||
public var initiallySelectedValues: [CellViewModelType]?
|
||||
public var initiallySelectedValues: [RowViewModelType]?
|
||||
|
||||
open var isFinishWithSeparator: Bool {
|
||||
true
|
||||
|
|
@ -52,11 +52,11 @@ open class BaseListFilterViewModel<CellViewModelType: FilterRowRepresentable & E
|
|||
return true
|
||||
}
|
||||
|
||||
open var selectedValues: [CellViewModelType] {
|
||||
open var selectedValues: [RowViewModelType] {
|
||||
rowViewModels.filter { $0.isSelected }
|
||||
}
|
||||
|
||||
open var visibleValues: [CellViewModelType] {
|
||||
open var visibleValues: [RowViewModelType] {
|
||||
rowViewModels
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ open class BaseListFilterViewModel<CellViewModelType: FilterRowRepresentable & E
|
|||
}
|
||||
}
|
||||
|
||||
public init(rowViewModels: [CellViewModelType], isMultiselectionEnabled: Bool) {
|
||||
public init(rowViewModels: [RowViewModelType], isMultiselectionEnabled: Bool) {
|
||||
self.rowViewModels = rowViewModels
|
||||
self.isMultiselectionEnabled = isMultiselectionEnabled
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@ open class BaseListFilterViewModel<CellViewModelType: FilterRowRepresentable & E
|
|||
initiallySelectedValues = selectedValues
|
||||
}
|
||||
|
||||
open func setSelected(model: CellViewModelType, isSelected: Bool) {
|
||||
open func setSelected(model: RowViewModelType, isSelected: Bool) {
|
||||
if !isMultiselectionEnabled {
|
||||
rowViewModels.enumerated().forEach {
|
||||
rowViewModels[$0.offset].isSelected = false
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import TIUIElements
|
|||
|
||||
open class DefaultFilterListSectionBuilder<CellType: BaseSeparatorCell & ConfigurableCell>: FilterTableSectionBuilder {
|
||||
|
||||
open func makeSection<ViewModel: FilterListPickerConfigurator>(with viewModel: ViewModel) -> TableSection where ViewModel.CellViewModel == CellType.CellData {
|
||||
open func makeSection<ViewModel: FilterListPickerConfigurator>(with viewModel: ViewModel) -> TableSection where ViewModel.RowViewModel == CellType.CellData {
|
||||
let rows = viewModel.visibleValues.map { item in
|
||||
TableRow<CellType>(item: item)
|
||||
.on(.select) { [weak viewModel] _ in
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ import Foundation
|
|||
public protocol FiltersViewModelProtocol: AnyObject {
|
||||
|
||||
associatedtype Filter: FilterPropertyValueRepresenter, Hashable
|
||||
associatedtype CellViewModel: FilterCellViewModelProtocol & Hashable
|
||||
associatedtype RowViewModel: FilterCellViewModelProtocol & Hashable
|
||||
|
||||
typealias Change = (indexPath: IndexPath, viewModel: CellViewModel)
|
||||
typealias Change = (indexPath: IndexPath, viewModel: RowViewModel)
|
||||
|
||||
var filters: [Filter] { get set }
|
||||
var selectedFilters: Set<Filter> { get set }
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@
|
|||
import TIUIKitCore
|
||||
import UIKit
|
||||
|
||||
open class DefaultFiltersViewModel<CellViewModelType: FilterCellViewModelProtocol & Hashable>: NSObject,
|
||||
open class DefaultFiltersViewModel<RowViewModelType: FilterCellViewModelProtocol & Hashable>: NSObject,
|
||||
FiltersViewModelProtocol {
|
||||
|
||||
public typealias CellViewModel = CellViewModelType
|
||||
public typealias RowViewModel = RowViewModelType
|
||||
|
||||
private var cellsViewModels: [CellViewModelType]
|
||||
private var cellsViewModels: [RowViewModelType]
|
||||
|
||||
public var filters: [DefaultFilterPropertyValue] {
|
||||
didSet {
|
||||
|
|
@ -50,7 +50,7 @@ open class DefaultFiltersViewModel<CellViewModelType: FilterCellViewModelProtoco
|
|||
public init(filters: [DefaultFilterPropertyValue]) {
|
||||
self.filters = filters
|
||||
self.cellsViewModels = filters.compactMap {
|
||||
CellViewModelType(id: $0.id,
|
||||
RowViewModelType(id: $0.id,
|
||||
title: $0.title,
|
||||
appearance: $0.cellAppearance,
|
||||
isSelected: $0.isSelected)
|
||||
|
|
@ -82,7 +82,7 @@ open class DefaultFiltersViewModel<CellViewModelType: FilterCellViewModelProtoco
|
|||
|
||||
open func rebuildCellsViewModels() {
|
||||
cellsViewModels = filters.compactMap {
|
||||
CellViewModelType(id: $0.id,
|
||||
RowViewModelType(id: $0.id,
|
||||
title: $0.title,
|
||||
appearance: $0.cellAppearance,
|
||||
isSelected: $0.isSelected)
|
||||
|
|
|
|||
Loading…
Reference in New Issue