fix: code review notes
This commit is contained in:
parent
ab9fafeb19
commit
08fdb69d68
|
|
@ -23,24 +23,28 @@
|
|||
import UIKit
|
||||
|
||||
open class BaseFilterCellAppearance {
|
||||
|
||||
/// The color of the border in selected state
|
||||
public var selectedColor: UIColor
|
||||
/// The color of the background in the selected state
|
||||
|
||||
public var selectedBgColor: UIColor
|
||||
/// The color of the background in the deselected state
|
||||
public var deselectedBgColor: UIColor
|
||||
|
||||
public var selectedFontColor: UIColor
|
||||
public var deselectedFontColor: UIColor
|
||||
|
||||
public var contentInsets: UIEdgeInsets
|
||||
public var cornerRadius: CGFloat
|
||||
|
||||
public init(selectedColor: UIColor,
|
||||
selectedBgColor: UIColor,
|
||||
deselectedBgColor: UIColor,
|
||||
selectedFontColor: UIColor,
|
||||
deselectedFontColor: UIColor,
|
||||
contentInsets: UIEdgeInsets,
|
||||
cornerRadius: CGFloat) {
|
||||
public init(selectedColor: UIColor = .systemGreen,
|
||||
selectedBgColor: UIColor = .white,
|
||||
deselectedBgColor: UIColor = .lightGray,
|
||||
selectedFontColor: UIColor = .systemGreen,
|
||||
deselectedFontColor: UIColor = .black,
|
||||
contentInsets: UIEdgeInsets = .init(top: 4, left: 8, bottom: 4, right: 8),
|
||||
cornerRadius: CGFloat = 6) {
|
||||
|
||||
self.selectedColor = selectedColor
|
||||
self.selectedBgColor = selectedBgColor
|
||||
|
|
@ -51,17 +55,3 @@ open class BaseFilterCellAppearance {
|
|||
self.cornerRadius = cornerRadius
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Default appearance
|
||||
|
||||
public extension BaseFilterCellAppearance {
|
||||
static var defaultFilterCellAppearance: BaseFilterCellAppearance {
|
||||
.init(selectedColor: .systemGreen,
|
||||
selectedBgColor: .white,
|
||||
deselectedBgColor: .lightGray,
|
||||
selectedFontColor: .systemGreen,
|
||||
deselectedFontColor: .black,
|
||||
contentInsets: .init(top: 4, left: 8, bottom: 4, right: 8),
|
||||
cornerRadius: 6)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,20 +25,24 @@ import TIUIElements
|
|||
import UIKit
|
||||
|
||||
open class DefaultFilterCollectionCell: ContainerCollectionViewCell<UILabel>,
|
||||
ReuseIdentifierProtocol,
|
||||
ConfigurableView {
|
||||
|
||||
open class var reuseIdentifier: String {
|
||||
"default-filter-cell"
|
||||
public enum SelectionState {
|
||||
case normal
|
||||
case selected
|
||||
}
|
||||
|
||||
public var currentSelectionState: SelectionState {
|
||||
isSelected ? .selected : .normal
|
||||
}
|
||||
|
||||
open var cellAppearance: BaseFilterCellAppearance {
|
||||
.defaultFilterCellAppearance
|
||||
.init()
|
||||
}
|
||||
|
||||
open override var isSelected: Bool {
|
||||
didSet {
|
||||
isSelected ? setSelectedAppearance() : setDeselectAppearance()
|
||||
setAppearance()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +61,21 @@ open class DefaultFilterCollectionCell: ContainerCollectionViewCell<UILabel>,
|
|||
wrappedView.text = viewModel.title
|
||||
}
|
||||
|
||||
// MARK: - Open methdos
|
||||
open func setAppearance() {
|
||||
switch currentSelectionState {
|
||||
case .normal:
|
||||
wrappedView.textColor = cellAppearance.deselectedFontColor
|
||||
layer.borderWidth = 0
|
||||
backgroundColor = cellAppearance.deselectedBgColor
|
||||
case .selected:
|
||||
wrappedView.textColor = cellAppearance.selectedFontColor
|
||||
backgroundColor = cellAppearance.selectedBgColor
|
||||
layer.borderColor = cellAppearance.selectedColor.cgColor
|
||||
layer.borderWidth = 1
|
||||
}
|
||||
}
|
||||
|
||||
open func setSelectedAppearance() {
|
||||
wrappedView.textColor = cellAppearance.selectedFontColor
|
||||
backgroundColor = cellAppearance.selectedBgColor
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ public extension DefaultFilterPropertyValue {
|
|||
}
|
||||
}
|
||||
|
||||
@available(iOS 13, *)
|
||||
extension DefaultFilterPropertyValue: Identifiable { }
|
||||
|
||||
extension DefaultFilterPropertyValue: Hashable {
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public extension FilterViewModelProtocol {
|
|||
}
|
||||
|
||||
private func getPropertySafely(_ index: Int) -> Property? {
|
||||
guard index >= 0 && index < properties.count else {
|
||||
guard (0..<properties.count).contains(index) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,12 +33,12 @@ open class BaseFilterViewModel<CellViewModelType: FilterCellViewModelProtocol &
|
|||
|
||||
public var properties: [PropertyValue] = [] {
|
||||
didSet {
|
||||
filtersCollection?.updateView()
|
||||
filtersCollection?.update()
|
||||
}
|
||||
}
|
||||
public var selectedProperties: [PropertyValue] = [] {
|
||||
didSet {
|
||||
filtersCollection?.updateView()
|
||||
filtersCollection?.update()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import TIUIKitCore
|
|||
import UIKit
|
||||
|
||||
@available(iOS 13.0, *)
|
||||
open class BaseFiltersCollectionView<CellType: ReuseIdentifiableCollectionCell & ConfigurableView,
|
||||
open class BaseFiltersCollectionView<CellType: UICollectionViewCell & ConfigurableView,
|
||||
PropertyValue: FilterPropertyValueRepresenter & Hashable>: UICollectionView,
|
||||
InitializableViewProtocol,
|
||||
UpdatableView,
|
||||
|
|
@ -103,7 +103,7 @@ open class BaseFiltersCollectionView<CellType: ReuseIdentifiableCollectionCell &
|
|||
|
||||
// MARK: - UpdatableView
|
||||
|
||||
open func updateView() {
|
||||
open func update() {
|
||||
applySnapshot()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,4 @@
|
|||
//
|
||||
|
||||
@available(iOS 13.0, *)
|
||||
open class DefaultFiltersCollectionView: BaseFiltersCollectionView<DefaultFilterCollectionCell, DefaultFilterPropertyValue> {
|
||||
|
||||
}
|
||||
typealias DefaultFiltersCollectionView = BaseFiltersCollectionView<DefaultFilterCollectionCell, DefaultFilterPropertyValue>
|
||||
|
|
|
|||
|
|
@ -27,4 +27,8 @@ public protocol ReuseIdentifierProtocol {
|
|||
static var reuseIdentifier: String { get }
|
||||
}
|
||||
|
||||
public typealias ReuseIdentifiableCollectionCell = UICollectionViewCell & ReuseIdentifierProtocol
|
||||
extension UICollectionViewCell: ReuseIdentifierProtocol {
|
||||
public static var reuseIdentifier: String {
|
||||
.init(describing: Self.self)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,5 +21,5 @@
|
|||
//
|
||||
|
||||
public protocol UpdatableView: AnyObject {
|
||||
func updateView()
|
||||
func update()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue