fix: code review notes

This commit is contained in:
Nikita Semenov 2022-08-11 00:31:36 +03:00
parent ab9fafeb19
commit 08fdb69d68
9 changed files with 48 additions and 36 deletions

View File

@ -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)
}
}

View File

@ -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

View File

@ -40,6 +40,7 @@ public extension DefaultFilterPropertyValue {
}
}
@available(iOS 13, *)
extension DefaultFilterPropertyValue: Identifiable { }
extension DefaultFilterPropertyValue: Hashable {

View File

@ -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
}

View File

@ -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()
}
}

View File

@ -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()
}

View File

@ -21,6 +21,4 @@
//
@available(iOS 13.0, *)
open class DefaultFiltersCollectionView: BaseFiltersCollectionView<DefaultFilterCollectionCell, DefaultFilterPropertyValue> {
}
typealias DefaultFiltersCollectionView = BaseFiltersCollectionView<DefaultFilterCollectionCell, DefaultFilterPropertyValue>

View File

@ -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)
}
}

View File

@ -21,5 +21,5 @@
//
public protocol UpdatableView: AnyObject {
func updateView()
func update()
}