Skip to content

Commit f1807f1

Browse files
author
Bluelich
committed
support custom animation configuration for elements
1 parent 9988e46 commit f1807f1

File tree

2 files changed

+61
-18
lines changed

2 files changed

+61
-18
lines changed

BLCollectionViewTagLayout/Classes/BLCollectionViewTagLayout.h

+25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ typedef NS_ENUM (NSUInteger, BLCollectionViewTagLayoutItemRenderPolicy) {
1818

1919
UIKIT_EXTERN NSString *const BLCollectionElementKindSectionDecoration;
2020

21+
typedef NS_ENUM(NSUInteger, BLCollectionViewTagLayoutAnimationState) {
22+
BLCollectionViewTagLayoutAnimationStateInitial,
23+
BLCollectionViewTagLayoutAnimationStateFinal,
24+
};
25+
26+
27+
/**
28+
* Animation configuration for elemets appearing or disappearing
29+
*
30+
* @param indexPath NSIndexPath
31+
* @param kind kind of the element, or nil if the catrgory is cell
32+
* @param catrgory UICollectionElementCategory
33+
*/
34+
typedef
35+
UICollectionViewLayoutAttributes * _Nullable(^BLCollectionViewTagLayoutAnimation)
36+
(NSIndexPath *indexPath,NSString * _Nullable kind,UICollectionElementCategory catrgory);
37+
2138
#pragma mark - UICollectionViewTagStyleLayout
2239
#pragma mark -
2340
IB_DESIGNABLE NS_CLASS_AVAILABLE_IOS(8_0)
@@ -78,6 +95,14 @@ IB_DESIGNABLE NS_CLASS_AVAILABLE_IOS(8_0)
7895
* The default value of this property is NO.
7996
*/
8097
@property (nonatomic) BOOL sectionDecorationVisiable;
98+
/**
99+
* Animation attributes for elements (item|supplementary|decoration) appearing.
100+
*/
101+
@property (nonatomic,copy,nullable) BLCollectionViewTagLayoutAnimation elementAppearingAnimationFromValue;
102+
/**
103+
* Animation attributes for elements (item|supplementary|decoration) disappearing.
104+
*/
105+
@property (nonatomic,copy,nullable) BLCollectionViewTagLayoutAnimation elementDisappearingAnimationToValue;
81106
@end
82107

83108
@interface BLCollectionViewTagLayout (UICollectionViewContentInsetAdjustment)

BLCollectionViewTagLayout/Classes/BLCollectionViewTagLayout.m

+36-18
Original file line numberDiff line numberDiff line change
@@ -831,39 +831,57 @@ - (void)finalizeLayoutTransition
831831
*/
832832
- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
833833
{
834-
UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath].copy;
835-
attributes.alpha = 0.1;
836-
return attributes;
834+
if (self.elementAppearingAnimationFromValue) {
835+
self.elementAppearingAnimationFromValue(itemIndexPath,
836+
nil,
837+
UICollectionElementCategoryCell);
838+
}
839+
return [super initialLayoutAttributesForAppearingItemAtIndexPath:itemIndexPath];
837840
}
838841
- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
839842
{
840-
UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath].copy;
841-
attributes.alpha = 0.1;
842-
return attributes;
843+
if (self.elementDisappearingAnimationToValue) {
844+
self.elementDisappearingAnimationToValue(itemIndexPath,
845+
nil,
846+
UICollectionElementCategoryCell);
847+
}
848+
return [super finalLayoutAttributesForDisappearingItemAtIndexPath:itemIndexPath];
843849
}
844850
- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingSupplementaryElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)elementIndexPath
845851
{
846-
UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForSupplementaryViewOfKind:elementKind atIndexPath:elementIndexPath].copy;
847-
attributes.alpha = 0.1;
848-
return attributes;
852+
if (self.elementAppearingAnimationFromValue) {
853+
self.elementAppearingAnimationFromValue(elementIndexPath,
854+
elementKind,
855+
UICollectionElementCategorySupplementaryView);
856+
}
857+
return [super initialLayoutAttributesForAppearingSupplementaryElementOfKind:elementKind atIndexPath:elementIndexPath];
849858
}
850859
- (nullable UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingSupplementaryElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)elementIndexPath
851860
{
852-
UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForSupplementaryViewOfKind:elementKind atIndexPath:elementIndexPath].copy;
853-
attributes.alpha = 0.1;
854-
return attributes;
861+
if (self.elementDisappearingAnimationToValue) {
862+
self.elementDisappearingAnimationToValue(elementIndexPath,
863+
elementKind,
864+
UICollectionElementCategorySupplementaryView);
865+
}
866+
return [super finalLayoutAttributesForDisappearingSupplementaryElementOfKind:elementKind atIndexPath:elementIndexPath];
855867
}
856868
- (nullable UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingDecorationElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)decorationIndexPath
857869
{
858-
UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForDecorationViewOfKind:elementKind atIndexPath:decorationIndexPath].copy;
859-
attributes.alpha = 0.1;
860-
return attributes;
870+
if (self.elementAppearingAnimationFromValue) {
871+
self.elementAppearingAnimationFromValue(decorationIndexPath,
872+
elementKind,
873+
UICollectionElementCategoryDecorationView);
874+
}
875+
return [super initialLayoutAttributesForAppearingDecorationElementOfKind:elementKind atIndexPath:decorationIndexPath];
861876
}
862877
- (nullable UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingDecorationElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)decorationIndexPath
863878
{
864-
UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForDecorationViewOfKind:elementKind atIndexPath:decorationIndexPath].copy;
865-
attributes.alpha = 0.1;
866-
return attributes;
879+
if (self.elementDisappearingAnimationToValue) {
880+
self.elementDisappearingAnimationToValue(decorationIndexPath,
881+
elementKind,
882+
UICollectionElementCategoryDecorationView);
883+
}
884+
return [super finalLayoutAttributesForDisappearingDecorationElementOfKind:elementKind atIndexPath:decorationIndexPath];
867885
}
868886

869887

0 commit comments

Comments
 (0)