From 1b105d70e41137a87ae65ad45dae435dca2ffa81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 13 Jun 2023 20:36:55 +0800 Subject: [PATCH] iOS: add enable gallery --- .../Pod/Classes/Shader/DoricSliderLayout.h | 1 + .../Pod/Classes/Shader/DoricSliderLayout.m | 50 ++++++++++--------- .../Pod/Classes/Shader/DoricSliderNode.m | 1 + 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.h b/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.h index a9c39964..93a14d49 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.h +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.h @@ -25,5 +25,6 @@ @property(nonatomic, assign) CGFloat galleryItemWidth; @property(nonatomic, assign) CGFloat galleryMinScale; @property(nonatomic, assign) CGFloat galleryMinAlpha; +@property(nonatomic, assign) BOOL enableGallery; @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.m b/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.m index 1d685ea4..1332cc81 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.m @@ -24,32 +24,36 @@ @implementation DoricSliderLayout - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { - NSArray *attributes = [super layoutAttributesForElementsInRect:rect]; - CGRect visitRect = {self.collectionView.contentOffset,self.collectionView.bounds.size}; - NSMutableArray *attributesCopy = [NSMutableArray array]; - for (UICollectionViewLayoutAttributes *attribute in attributes) { - UICollectionViewLayoutAttributes *attributeCopy = [attribute copy]; - [attributesCopy addObject:attributeCopy]; - } - - for (UICollectionViewLayoutAttributes *attribute in attributesCopy) { - CGFloat distance = CGRectGetMidX(visitRect) - attribute.center.x; - float diff = fabs(distance); - CATransform3D scaleTransform = CATransform3DIdentity; - - if (diff >= 0 && diff <= self.galleryItemWidth) { - float scale = 1 - (1 - self.galleryMinScale) * (diff / self.galleryItemWidth); - scaleTransform = CATransform3DMakeScale(scale, scale, scale); - attribute.alpha = 1 - (1 - self.galleryMinAlpha) * (diff / self.galleryItemWidth); - } else { - float scale = self.galleryMinScale; - scaleTransform = CATransform3DMakeScale(scale, scale, scale); - attribute.alpha = self.galleryMinAlpha; + if (self.enableGallery) { + NSArray *attributes = [super layoutAttributesForElementsInRect:rect]; + CGRect visitRect = {self.collectionView.contentOffset, self.collectionView.bounds.size}; + NSMutableArray *attributesCopy = [NSMutableArray array]; + for (UICollectionViewLayoutAttributes *attribute in attributes) { + UICollectionViewLayoutAttributes *attributeCopy = [attribute copy]; + [attributesCopy addObject:attributeCopy]; } - attribute.transform3D = scaleTransform; + for (UICollectionViewLayoutAttributes *attribute in attributesCopy) { + CGFloat distance = CGRectGetMidX(visitRect) - attribute.center.x; + float diff = fabs(distance); + CATransform3D scaleTransform = CATransform3DIdentity; + + if (diff >= 0 && diff <= self.galleryItemWidth) { + float scale = 1 - (1 - self.galleryMinScale) * (diff / self.galleryItemWidth); + scaleTransform = CATransform3DMakeScale(scale, scale, scale); + attribute.alpha = 1 - (1 - self.galleryMinAlpha) * (diff / self.galleryItemWidth); + } else { + float scale = self.galleryMinScale; + scaleTransform = CATransform3DMakeScale(scale, scale, scale); + attribute.alpha = self.galleryMinAlpha; + } + + attribute.transform3D = scaleTransform; + } + return attributesCopy; + } else { + return [super layoutAttributesForElementsInRect:rect]; } - return attributesCopy; } - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m index f464bda4..63151c05 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -131,6 +131,7 @@ - (void)blendView:(UICollectionView *)view forPropName:(NSString *)name propValu layout.galleryItemWidth = self.galleryItemWidth; layout.galleryMinScale = self.galleryMinScale; layout.galleryMinAlpha = self.galleryMinAlpha; + layout.enableGallery = YES; } } else if ([prop isKindOfClass:NSString.class]) {