forked from GeekTree0101/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASThrashUtility.h
111 lines (89 loc) · 4.13 KB
/
ASThrashUtility.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
//
// Tests/ASThrashUtility.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 <AsyncDisplayKit/AsyncDisplayKit.h>
#import <stdatomic.h>
NS_ASSUME_NONNULL_BEGIN
#define kInitialSectionCount 10
#define kInitialItemCount 10
#define kMinimumItemCount 5
#define kMinimumSectionCount 3
#define kFickleness 0.1
#define kThrashingIterationCount 10
// Set to 1 to use UITableView and see if the issue still exists.
#define USE_UIKIT_REFERENCE 0
#if USE_UIKIT_REFERENCE
#define TableView UITableView
#define CollectionView UICollectionView
#define kCellReuseID @"ASThrashTestCellReuseID"
#else
#define TableView ASTableView
#define CollectionView ASCollectionNode
#endif
static NSInteger ASThrashUpdateCurrentSerializationVersion = 1;
@class ASThrashTestSection;
static atomic_uint ASThrashTestItemNextID;
@interface ASThrashTestItem: NSObject <NSSecureCoding>
@property (nonatomic, readonly) NSInteger itemID;
+ (NSMutableArray <ASThrashTestItem *> *)itemsWithCount:(NSInteger)count;
- (CGFloat)rowHeight;
@end
@interface ASThrashTestSection: NSObject <NSCopying, NSSecureCoding>
@property (nonatomic, readonly) NSMutableArray *items;
@property (nonatomic, readonly) NSInteger sectionID;
+ (NSMutableArray <ASThrashTestSection *> *)sectionsWithCount:(NSInteger)count;
- (instancetype)initWithCount:(NSInteger)count;
- (CGFloat)headerHeight;
@end
@interface ASThrashDataSource: NSObject
#if USE_UIKIT_REFERENCE
<UITableViewDataSource, UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate>
#else
<ASTableDataSource, ASTableDelegate, ASCollectionDelegate, ASCollectionDataSource>
#endif
@property (nonatomic, readonly) UIWindow *window;
@property (nonatomic, readonly) TableView *tableView;
@property (nonatomic, readonly) CollectionView *collectionView;
@property (nonatomic) NSArray <ASThrashTestSection *> *data;
// Only access on main
@property (nonatomic) ASWeakSet *allNodes;
- (instancetype)initTableViewDataSourceWithData:(NSArray <ASThrashTestSection *> *)data;
- (instancetype)initCollectionViewDataSourceWithData:(NSArray <ASThrashTestSection *> * _Nullable)data;
- (NSPredicate *)predicateForDeallocatedHierarchy;
@end
@interface NSIndexSet (ASThrashHelpers)
- (NSArray <NSIndexPath *> *)indexPathsInSection:(NSInteger)section;
/// `insertMode` means that for each index selected, the max goes up by one.
+ (NSMutableIndexSet *)randomIndexesLessThan:(NSInteger)max probability:(float)probability insertMode:(BOOL)insertMode;
@end
#if !USE_UIKIT_REFERENCE
@interface ASThrashTestNode: ASCellNode
@property (nonatomic) ASThrashTestItem *item;
@end
#endif
@interface ASThrashUpdate : NSObject <NSSecureCoding>
@property (nonatomic, readonly) NSArray<ASThrashTestSection *> *oldData;
@property (nonatomic, readonly) NSMutableArray<ASThrashTestSection *> *data;
@property (nonatomic, readonly) NSMutableIndexSet *deletedSectionIndexes;
@property (nonatomic, readonly) NSMutableIndexSet *replacedSectionIndexes;
/// The sections used to replace the replaced sections.
@property (nonatomic, readonly) NSMutableArray<ASThrashTestSection *> *replacingSections;
@property (nonatomic, readonly) NSMutableIndexSet *insertedSectionIndexes;
@property (nonatomic, readonly) NSMutableArray<ASThrashTestSection *> *insertedSections;
@property (nonatomic, readonly) NSMutableArray<NSMutableIndexSet *> *deletedItemIndexes;
@property (nonatomic, readonly) NSMutableArray<NSMutableIndexSet *> *replacedItemIndexes;
/// The items used to replace the replaced items.
@property (nonatomic, readonly) NSMutableArray<NSArray <ASThrashTestItem *> *> *replacingItems;
@property (nonatomic, readonly) NSMutableArray<NSMutableIndexSet *> *insertedItemIndexes;
@property (nonatomic, readonly) NSMutableArray<NSArray <ASThrashTestItem *> *> *insertedItems;
- (instancetype)initWithData:(NSArray<ASThrashTestSection *> *)data;
+ (ASThrashUpdate *)thrashUpdateWithBase64String:(NSString *)base64;
- (NSString *)base64Representation;
- (NSString *)logFriendlyBase64Representation;
@end
NS_ASSUME_NONNULL_END