forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASCollectionLayoutState.h
111 lines (89 loc) · 3.64 KB
/
ASCollectionLayoutState.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// ASCollectionLayoutState.h
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <AsyncDisplayKit/ASBaseDefines.h>
@class ASCollectionLayoutContext, ASLayout, ASCollectionElement;
NS_ASSUME_NONNULL_BEGIN
typedef ASCollectionElement * _Nullable (^ASCollectionLayoutStateGetElementBlock)(ASLayout *);
@interface NSMapTable (ASCollectionLayoutConvenience)
+ (NSMapTable<ASCollectionElement *, UICollectionViewLayoutAttributes *> *)elementToLayoutAttributesTable;
@end
AS_SUBCLASSING_RESTRICTED
/// An immutable state of the collection layout
@interface ASCollectionLayoutState : NSObject
/// The context used to calculate this object
@property (readonly) ASCollectionLayoutContext *context;
/// The final content size of the collection's layout
@property (readonly) CGSize contentSize;
- (instancetype)init NS_UNAVAILABLE;
/**
* Designated initializer.
*
* @param context The context used to calculate this object
*
* @param contentSize The content size of the collection's layout
*
* @param table A map between elements to their layout attributes. It must contain all elements.
* It should have NSMapTableObjectPointerPersonality and NSMapTableWeakMemory as key options.
*/
- (instancetype)initWithContext:(ASCollectionLayoutContext *)context
contentSize:(CGSize)contentSize
elementToLayoutAttributesTable:(NSMapTable<ASCollectionElement *, UICollectionViewLayoutAttributes *> *)table NS_DESIGNATED_INITIALIZER;
/**
* Convenience initializer. Returns an object with zero content size and an empty table.
*
* @param context The context used to calculate this object
*/
- (instancetype)initWithContext:(ASCollectionLayoutContext *)context;
/**
* Convenience initializer.
*
* @param context The context used to calculate this object
*
* @param layout The layout describes size and position of all elements.
*
* @param getElementBlock A block that can retrieve the collection element from a sublayout of the root layout.
*/
- (instancetype)initWithContext:(ASCollectionLayoutContext *)context
layout:(ASLayout *)layout
getElementBlock:(ASCollectionLayoutStateGetElementBlock)getElementBlock;
/**
* Returns all layout attributes present in this object.
*/
- (NSArray<UICollectionViewLayoutAttributes *> *)allLayoutAttributes;
/**
* Returns layout attributes of elements in the specified rect.
*
* @param rect The rect containing the target elements.
*/
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect;
/**
* Returns layout attributes of the element at the specified index path.
*
* @param indexPath The index path of the item.
*/
- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath;
/**
* Returns layout attributes of the specified supplementary element.
*
* @param kind A string that identifies the type of the supplementary element.
*
* @param indexPath The index path of the element.
*/
- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath;
/**
* Returns layout attributes of the specified element.
*
* @element The element.
*/
- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForElement:(ASCollectionElement *)element;
@end
NS_ASSUME_NONNULL_END