From 0534d41bae050c9188ec01724d8450d978d110ab Mon Sep 17 00:00:00 2001 From: Nikita Semenov Date: Thu, 4 Aug 2022 16:44:19 +0300 Subject: [PATCH] fix: update collection view with diffable data source --- .../{ => Cart}/Classes/RequestExecutor.swift | 0 .../Models/BaseErrorResponseBody.swift | 0 .../Sources/{ => Cart}/Models/Cart.swift | 0 .../{ => Cart}/Models/CartProduct.swift | 0 .../{ => Cart}/Models/CartService.swift | 0 .../Sources/{ => Cart}/Models/Promocode.swift | 0 ...UICollectionViewLayout+DefaultLayout.swift | 10 +-- .../Filters/Models/DefaultFilterModel.swift | 2 +- .../Models/DefaultFilterPropertyValue.swift | 4 +- .../Models/FiltersLayoutConfiguration.swift | 0 .../FilterPropertyValueRepresenter.swift | 0 .../Filters/Protocols/FilterRepresenter.swift | 0 .../Protocols/FiltersCollectionHolder.swift | 0 .../Protocols/FiltersViewModelProtocol.swift | 0 .../ViewModels/DefaultCellViewModel.swift | 0 .../ViewModels/DefaultFiltersViewModel.swift | 0 .../Views/BaseFiltersCollectionView.swift | 63 ++++++++++++++----- .../Views/DefaultFilterCollectionCell.swift | 22 ++----- TIEcommerce/TIEcommerce.podspec | 2 + .../NSDirectionalEdgeInsets+Init.swift | 32 ++++++++++ 20 files changed, 90 insertions(+), 45 deletions(-) rename TIEcommerce/Sources/{ => Cart}/Classes/RequestExecutor.swift (100%) rename TIEcommerce/Sources/{ => Cart}/Models/BaseErrorResponseBody.swift (100%) rename TIEcommerce/Sources/{ => Cart}/Models/Cart.swift (100%) rename TIEcommerce/Sources/{ => Cart}/Models/CartProduct.swift (100%) rename TIEcommerce/Sources/{ => Cart}/Models/CartService.swift (100%) rename TIEcommerce/Sources/{ => Cart}/Models/Promocode.swift (100%) rename {TIUIElements => TIEcommerce}/Sources/Filters/Helpers/UICollectionViewLayout+DefaultLayout.swift (91%) rename {TIUIElements => TIEcommerce}/Sources/Filters/Models/DefaultFilterModel.swift (96%) rename {TIUIElements => TIEcommerce}/Sources/Filters/Models/DefaultFilterPropertyValue.swift (95%) rename {TIUIElements => TIEcommerce}/Sources/Filters/Models/FiltersLayoutConfiguration.swift (100%) rename {TIUIElements => TIEcommerce}/Sources/Filters/Protocols/FilterPropertyValueRepresenter.swift (100%) rename {TIUIElements => TIEcommerce}/Sources/Filters/Protocols/FilterRepresenter.swift (100%) rename {TIUIElements => TIEcommerce}/Sources/Filters/Protocols/FiltersCollectionHolder.swift (100%) rename {TIUIElements => TIEcommerce}/Sources/Filters/Protocols/FiltersViewModelProtocol.swift (100%) rename {TIUIElements => TIEcommerce}/Sources/Filters/ViewModels/DefaultCellViewModel.swift (100%) rename {TIUIElements => TIEcommerce}/Sources/Filters/ViewModels/DefaultFiltersViewModel.swift (100%) rename {TIUIElements => TIEcommerce}/Sources/Filters/Views/BaseFiltersCollectionView.swift (67%) rename TIUIElements/Sources/Filters/Views/BaseFilterCollectionCell.swift => TIEcommerce/Sources/Filters/Views/DefaultFilterCollectionCell.swift (84%) create mode 100644 TIUIKitCore/Sources/Extensions/UICollectionView/Layout Helpers/NSDirectionalEdgeInsets+Init.swift diff --git a/TIEcommerce/Sources/Classes/RequestExecutor.swift b/TIEcommerce/Sources/Cart/Classes/RequestExecutor.swift similarity index 100% rename from TIEcommerce/Sources/Classes/RequestExecutor.swift rename to TIEcommerce/Sources/Cart/Classes/RequestExecutor.swift diff --git a/TIEcommerce/Sources/Models/BaseErrorResponseBody.swift b/TIEcommerce/Sources/Cart/Models/BaseErrorResponseBody.swift similarity index 100% rename from TIEcommerce/Sources/Models/BaseErrorResponseBody.swift rename to TIEcommerce/Sources/Cart/Models/BaseErrorResponseBody.swift diff --git a/TIEcommerce/Sources/Models/Cart.swift b/TIEcommerce/Sources/Cart/Models/Cart.swift similarity index 100% rename from TIEcommerce/Sources/Models/Cart.swift rename to TIEcommerce/Sources/Cart/Models/Cart.swift diff --git a/TIEcommerce/Sources/Models/CartProduct.swift b/TIEcommerce/Sources/Cart/Models/CartProduct.swift similarity index 100% rename from TIEcommerce/Sources/Models/CartProduct.swift rename to TIEcommerce/Sources/Cart/Models/CartProduct.swift diff --git a/TIEcommerce/Sources/Models/CartService.swift b/TIEcommerce/Sources/Cart/Models/CartService.swift similarity index 100% rename from TIEcommerce/Sources/Models/CartService.swift rename to TIEcommerce/Sources/Cart/Models/CartService.swift diff --git a/TIEcommerce/Sources/Models/Promocode.swift b/TIEcommerce/Sources/Cart/Models/Promocode.swift similarity index 100% rename from TIEcommerce/Sources/Models/Promocode.swift rename to TIEcommerce/Sources/Cart/Models/Promocode.swift diff --git a/TIUIElements/Sources/Filters/Helpers/UICollectionViewLayout+DefaultLayout.swift b/TIEcommerce/Sources/Filters/Helpers/UICollectionViewLayout+DefaultLayout.swift similarity index 91% rename from TIUIElements/Sources/Filters/Helpers/UICollectionViewLayout+DefaultLayout.swift rename to TIEcommerce/Sources/Filters/Helpers/UICollectionViewLayout+DefaultLayout.swift index bca75cec..004ac01e 100644 --- a/TIUIElements/Sources/Filters/Helpers/UICollectionViewLayout+DefaultLayout.swift +++ b/TIEcommerce/Sources/Filters/Helpers/UICollectionViewLayout+DefaultLayout.swift @@ -21,6 +21,7 @@ // import UIKit +import TIUIKitCore @available(iOS 13, *) public extension UICollectionViewLayout { @@ -55,12 +56,3 @@ public extension UICollectionViewLayout { return UICollectionViewCompositionalLayout(section: section) } } - -private extension NSDirectionalEdgeInsets { - init(insets: UIEdgeInsets) { - self.init(top: insets.top, - leading: insets.left, - bottom: insets.bottom, - trailing: insets.right) - } -} diff --git a/TIUIElements/Sources/Filters/Models/DefaultFilterModel.swift b/TIEcommerce/Sources/Filters/Models/DefaultFilterModel.swift similarity index 96% rename from TIUIElements/Sources/Filters/Models/DefaultFilterModel.swift rename to TIEcommerce/Sources/Filters/Models/DefaultFilterModel.swift index 94ebaaa7..2f116ded 100644 --- a/TIUIElements/Sources/Filters/Models/DefaultFilterModel.swift +++ b/TIEcommerce/Sources/Filters/Models/DefaultFilterModel.swift @@ -20,7 +20,7 @@ // THE SOFTWARE. // -public struct DefaultFilterModel: FilterRepresenter, Codable { +public struct DefaultFilterModel: FilterRepresenter { public let id: String public let property: DefaultFilterPropertyValue? public let properties: [DefaultFilterPropertyValue]? diff --git a/TIUIElements/Sources/Filters/Models/DefaultFilterPropertyValue.swift b/TIEcommerce/Sources/Filters/Models/DefaultFilterPropertyValue.swift similarity index 95% rename from TIUIElements/Sources/Filters/Models/DefaultFilterPropertyValue.swift rename to TIEcommerce/Sources/Filters/Models/DefaultFilterPropertyValue.swift index 107847b1..b5a23494 100644 --- a/TIUIElements/Sources/Filters/Models/DefaultFilterPropertyValue.swift +++ b/TIEcommerce/Sources/Filters/Models/DefaultFilterPropertyValue.swift @@ -22,9 +22,7 @@ import UIKit -public struct DefaultFilterPropertyValue: FilterPropertyValueRepresenter, - Codable, - Identifiable { +public struct DefaultFilterPropertyValue: FilterPropertyValueRepresenter, Identifiable { public let id: String public let title: String diff --git a/TIUIElements/Sources/Filters/Models/FiltersLayoutConfiguration.swift b/TIEcommerce/Sources/Filters/Models/FiltersLayoutConfiguration.swift similarity index 100% rename from TIUIElements/Sources/Filters/Models/FiltersLayoutConfiguration.swift rename to TIEcommerce/Sources/Filters/Models/FiltersLayoutConfiguration.swift diff --git a/TIUIElements/Sources/Filters/Protocols/FilterPropertyValueRepresenter.swift b/TIEcommerce/Sources/Filters/Protocols/FilterPropertyValueRepresenter.swift similarity index 100% rename from TIUIElements/Sources/Filters/Protocols/FilterPropertyValueRepresenter.swift rename to TIEcommerce/Sources/Filters/Protocols/FilterPropertyValueRepresenter.swift diff --git a/TIUIElements/Sources/Filters/Protocols/FilterRepresenter.swift b/TIEcommerce/Sources/Filters/Protocols/FilterRepresenter.swift similarity index 100% rename from TIUIElements/Sources/Filters/Protocols/FilterRepresenter.swift rename to TIEcommerce/Sources/Filters/Protocols/FilterRepresenter.swift diff --git a/TIUIElements/Sources/Filters/Protocols/FiltersCollectionHolder.swift b/TIEcommerce/Sources/Filters/Protocols/FiltersCollectionHolder.swift similarity index 100% rename from TIUIElements/Sources/Filters/Protocols/FiltersCollectionHolder.swift rename to TIEcommerce/Sources/Filters/Protocols/FiltersCollectionHolder.swift diff --git a/TIUIElements/Sources/Filters/Protocols/FiltersViewModelProtocol.swift b/TIEcommerce/Sources/Filters/Protocols/FiltersViewModelProtocol.swift similarity index 100% rename from TIUIElements/Sources/Filters/Protocols/FiltersViewModelProtocol.swift rename to TIEcommerce/Sources/Filters/Protocols/FiltersViewModelProtocol.swift diff --git a/TIUIElements/Sources/Filters/ViewModels/DefaultCellViewModel.swift b/TIEcommerce/Sources/Filters/ViewModels/DefaultCellViewModel.swift similarity index 100% rename from TIUIElements/Sources/Filters/ViewModels/DefaultCellViewModel.swift rename to TIEcommerce/Sources/Filters/ViewModels/DefaultCellViewModel.swift diff --git a/TIUIElements/Sources/Filters/ViewModels/DefaultFiltersViewModel.swift b/TIEcommerce/Sources/Filters/ViewModels/DefaultFiltersViewModel.swift similarity index 100% rename from TIUIElements/Sources/Filters/ViewModels/DefaultFiltersViewModel.swift rename to TIEcommerce/Sources/Filters/ViewModels/DefaultFiltersViewModel.swift diff --git a/TIUIElements/Sources/Filters/Views/BaseFiltersCollectionView.swift b/TIEcommerce/Sources/Filters/Views/BaseFiltersCollectionView.swift similarity index 67% rename from TIUIElements/Sources/Filters/Views/BaseFiltersCollectionView.swift rename to TIEcommerce/Sources/Filters/Views/BaseFiltersCollectionView.swift index ea37a951..aae7d771 100644 --- a/TIUIElements/Sources/Filters/Views/BaseFiltersCollectionView.swift +++ b/TIEcommerce/Sources/Filters/Views/BaseFiltersCollectionView.swift @@ -23,15 +23,28 @@ import TIUIKitCore import UIKit +@available(iOS 13.0, *) open class BaseFiltersCollectionView: UICollectionView, InitializableViewProtocol, - ConfigurableView, - FiltersCollectionHolder where CellType.ViewModelType: FilterCellViewModelProtocol { + FiltersCollectionHolder where CellType.ViewModelType: Hashable { + + public enum Section { + case main + } + + public typealias DataSource = UICollectionViewDiffableDataSource + public typealias Snapshot = NSDiffableDataSourceSnapshot public var layout: UICollectionViewLayout public weak var viewModel: DefaultFiltersViewModel? + public lazy var collectionViewDataSource = createDataSource() + + open var cellsReusedIdentifier: String { + "filter-cells-identifier" + } + // MARK: - Init public init(layout: UICollectionViewLayout, viewModel: DefaultFiltersViewModel? = nil) { @@ -54,8 +67,8 @@ open class BaseFiltersCollectionView DataSource { + let cellProvider: DataSource.CellProvider = { [weak self] collectionView, indexPath, itemIdentifier in + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: self?.cellsReusedIdentifier ?? "", + for: indexPath) as? CellType + + cell?.configure(with: itemIdentifier) + + return cell + } + + return DataSource(collectionView: self, cellProvider: cellProvider) + } } diff --git a/TIUIElements/Sources/Filters/Views/BaseFilterCollectionCell.swift b/TIEcommerce/Sources/Filters/Views/DefaultFilterCollectionCell.swift similarity index 84% rename from TIUIElements/Sources/Filters/Views/BaseFilterCollectionCell.swift rename to TIEcommerce/Sources/Filters/Views/DefaultFilterCollectionCell.swift index f54245cf..d6abb5b0 100644 --- a/TIUIElements/Sources/Filters/Views/BaseFilterCollectionCell.swift +++ b/TIEcommerce/Sources/Filters/Views/DefaultFilterCollectionCell.swift @@ -22,22 +22,16 @@ import UIKit import TIUIKitCore +import TIUIElements -open class BaseFilterCollectionCell: ContainerCollectionViewCell, - ConfigurableView { +open class DefaultFilterCollectionCell: ContainerCollectionViewCell, + ConfigurableView { public var viewModel: DefaultFilterCellViewModel? - open var isLabelHidden: Bool { - get { - wrappedView.isHidden - } - set { - wrappedView.isHidden = newValue - } - } - open override func configureAppearance() { + super.configureAppearance() + layer.round(corners: .allCorners, radius: 6) } @@ -52,12 +46,6 @@ open class BaseFilterCollectionCell: ContainerCollectionViewCell, setSelected(isSelected: viewModel.isSelected) } - // MARK: - ContainerCollectionViewCell - - open override func createView() -> UILabel { - UILabel() - } - // MARK: - Public methods open func setSelected(isSelected: Bool) { diff --git a/TIEcommerce/TIEcommerce.podspec b/TIEcommerce/TIEcommerce.podspec index 6aa4922b..481f80b3 100644 --- a/TIEcommerce/TIEcommerce.podspec +++ b/TIEcommerce/TIEcommerce.podspec @@ -14,4 +14,6 @@ Pod::Spec.new do |s| s.dependency 'TIFoundationUtils', s.version.to_s s.dependency 'TINetworking', s.version.to_s + s.dependency 'TIUIKitCore', s.version.to_s + s.dependency 'TIUIElements', version.to_s end diff --git a/TIUIKitCore/Sources/Extensions/UICollectionView/Layout Helpers/NSDirectionalEdgeInsets+Init.swift b/TIUIKitCore/Sources/Extensions/UICollectionView/Layout Helpers/NSDirectionalEdgeInsets+Init.swift new file mode 100644 index 00000000..025378b7 --- /dev/null +++ b/TIUIKitCore/Sources/Extensions/UICollectionView/Layout Helpers/NSDirectionalEdgeInsets+Init.swift @@ -0,0 +1,32 @@ +// +// Copyright (c) 2022 Touch Instinct +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import UIKit + +public extension NSDirectionalEdgeInsets { + init(insets: UIEdgeInsets) { + self.init(top: insets.top, + leading: insets.left, + bottom: insets.bottom, + trailing: insets.right) + } +} \ No newline at end of file