diff --git a/TIEcommerce/Sources/Filters/FiltersCollectionCell/Models/BaseFilterCellAppearance.swift b/TIEcommerce/Sources/Filters/FiltersCollectionCell/Models/BaseFilterCellAppearance.swift index f3a49222..53229444 100644 --- a/TIEcommerce/Sources/Filters/FiltersCollectionCell/Models/BaseFilterCellAppearance.swift +++ b/TIEcommerce/Sources/Filters/FiltersCollectionCell/Models/BaseFilterCellAppearance.swift @@ -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) - } -} diff --git a/TIEcommerce/Sources/Filters/FiltersCollectionCell/Views/DefaultFilterCollectionCell.swift b/TIEcommerce/Sources/Filters/FiltersCollectionCell/Views/DefaultFilterCollectionCell.swift index 7650dd85..556f03e7 100644 --- a/TIEcommerce/Sources/Filters/FiltersCollectionCell/Views/DefaultFilterCollectionCell.swift +++ b/TIEcommerce/Sources/Filters/FiltersCollectionCell/Views/DefaultFilterCollectionCell.swift @@ -25,20 +25,24 @@ import TIUIElements import UIKit open class DefaultFilterCollectionCell: ContainerCollectionViewCell, - 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, 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 diff --git a/TIEcommerce/Sources/Filters/FiltersCollectionView/Models/DefaultFilterPropertyValue.swift b/TIEcommerce/Sources/Filters/FiltersCollectionView/Models/DefaultFilterPropertyValue.swift index 2ecb1dc2..55ee1907 100644 --- a/TIEcommerce/Sources/Filters/FiltersCollectionView/Models/DefaultFilterPropertyValue.swift +++ b/TIEcommerce/Sources/Filters/FiltersCollectionView/Models/DefaultFilterPropertyValue.swift @@ -40,6 +40,7 @@ public extension DefaultFilterPropertyValue { } } +@available(iOS 13, *) extension DefaultFilterPropertyValue: Identifiable { } extension DefaultFilterPropertyValue: Hashable { diff --git a/TIEcommerce/Sources/Filters/FiltersCollectionView/Protocols/FilterViewModelProtocol.swift b/TIEcommerce/Sources/Filters/FiltersCollectionView/Protocols/FilterViewModelProtocol.swift index 3cd71bdd..925c752a 100644 --- a/TIEcommerce/Sources/Filters/FiltersCollectionView/Protocols/FilterViewModelProtocol.swift +++ b/TIEcommerce/Sources/Filters/FiltersCollectionView/Protocols/FilterViewModelProtocol.swift @@ -93,7 +93,7 @@ public extension FilterViewModelProtocol { } private func getPropertySafely(_ index: Int) -> Property? { - guard index >= 0 && index < properties.count else { + guard (0..: UICollectionView, InitializableViewProtocol, UpdatableView, @@ -103,7 +103,7 @@ open class BaseFiltersCollectionView { - -} +typealias DefaultFiltersCollectionView = BaseFiltersCollectionView diff --git a/TIUIKitCore/Sources/Protocols/ReuseIdentifierProtocol.swift b/TIUIKitCore/Sources/Protocols/ReuseIdentifierProtocol.swift index a7442509..46e7e17f 100644 --- a/TIUIKitCore/Sources/Protocols/ReuseIdentifierProtocol.swift +++ b/TIUIKitCore/Sources/Protocols/ReuseIdentifierProtocol.swift @@ -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) + } +} diff --git a/TIUIKitCore/Sources/UpdatableView/UpdatableView.swift b/TIUIKitCore/Sources/UpdatableView/UpdatableView.swift index 42d376ff..f2d9c510 100644 --- a/TIUIKitCore/Sources/UpdatableView/UpdatableView.swift +++ b/TIUIKitCore/Sources/UpdatableView/UpdatableView.swift @@ -21,5 +21,5 @@ // public protocol UpdatableView: AnyObject { - func updateView() + func update() }