From cc867e018c2a8ba39e9cbc97ae773e2ce5fcab4f Mon Sep 17 00:00:00 2001 From: Vlad Bokov Date: Tue, 25 Mar 2025 16:20:21 +0000 Subject: [PATCH] =?UTF-8?q?Vibe-refactor=20=F0=9F=92=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PercentageFlowLayoutPlugin.swift | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/Sources/PluginableFlowLayout/PercentageFlowLayoutPlugin.swift b/Sources/PluginableFlowLayout/PercentageFlowLayoutPlugin.swift index 8504232..214adce 100644 --- a/Sources/PluginableFlowLayout/PercentageFlowLayoutPlugin.swift +++ b/Sources/PluginableFlowLayout/PercentageFlowLayoutPlugin.swift @@ -74,6 +74,30 @@ open class PercentageFlowLayoutPlugin: FlowLayoutPlugin { alignment: PluginableFlowLayoutAlignment?, sectionInset: UIEdgeInsets ) -> PluginableFlowLayoutAttributes { + let context = createContext( + attributes: attributes, + collectionView: collectionView, + scrollDirection: scrollDirection, + alignment: alignment, + sectionInset: sectionInset + ) + + attributes.collectionVisibility = getCollectionVisibilityWithSign(context: context) + attributes.idealFrameVisibility = getIdealFrameVisibilityWithSign(context: context) + attributes.idealFrameAndCollectionVisibility = getIdealFrameAndCollectionVisibilityWithSign(context: context) + + return attributes + } + + // MARK: - Private Methods + + private func createContext( + attributes: PluginableFlowLayoutAttributes, + collectionView: UICollectionView, + scrollDirection: UICollectionView.ScrollDirection, + alignment: PluginableFlowLayoutAlignment?, + sectionInset: UIEdgeInsets + ) -> Context { let collectionSizeValue = collectionView.bounds.size.value(scrollDirection: scrollDirection) let halfCollectionSizeValue = collectionSizeValue / 2 let itemSizeValue = attributes.size.value(scrollDirection: scrollDirection) @@ -83,7 +107,7 @@ open class PercentageFlowLayoutPlugin: FlowLayoutPlugin { let sectionInsetBeforeValue = sectionInset.beforeValue(scrollDirection: scrollDirection) let sectionInsetAfterValue = sectionInset.beforeValue(scrollDirection: scrollDirection) - let context = Context( + return Context( alignment: alignment, collectionSizeValue: collectionSizeValue, halfCollectionSizeValue: halfCollectionSizeValue, @@ -94,18 +118,6 @@ open class PercentageFlowLayoutPlugin: FlowLayoutPlugin { sectionInsetBeforeValue: sectionInsetBeforeValue, sectionInsetAfterValue: sectionInsetAfterValue ) - - attributes.collectionVisibility = getCollectionVisibilityWithSign( - context: context - ) - attributes.idealFrameVisibility = getIdealFrameVisibilityWithSign( - context: context - ) - attributes.idealFrameAndCollectionVisibility = getIdealFrameAndCollectionVisibilityWithSign( - context: context - ) - - return attributes } // MARK: - Private Properties