forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASCollectionNode.mm
732 lines (618 loc) · 21.8 KB
/
ASCollectionNode.mm
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
//
// ASCollectionNode.mm
// AsyncDisplayKit
//
// Created by Scott Goodson on 9/5/15.
//
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
#import <AsyncDisplayKit/ASCollectionNode.h>
#import <AsyncDisplayKit/ASCollectionNode+Beta.h>
#import <AsyncDisplayKit/ASCollectionElement.h>
#import <AsyncDisplayKit/ASElementMap.h>
#import <AsyncDisplayKit/ASCollectionInternal.h>
#import <AsyncDisplayKit/ASCollectionLayout.h>
#import <AsyncDisplayKit/ASCollectionViewLayoutFacilitatorProtocol.h>
#import <AsyncDisplayKit/ASDisplayNode+Beta.h>
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h>
#import <AsyncDisplayKit/ASInternalHelpers.h>
#import <AsyncDisplayKit/ASCellNode+Internal.h>
#import <AsyncDisplayKit/AsyncDisplayKit+Debug.h>
#import <AsyncDisplayKit/ASSectionContext.h>
#import <AsyncDisplayKit/ASDataController.h>
#import <AsyncDisplayKit/ASCollectionView+Undeprecated.h>
#import <AsyncDisplayKit/ASThread.h>
#import <AsyncDisplayKit/ASRangeController.h>
#pragma mark - _ASCollectionPendingState
@interface _ASCollectionPendingState : NSObject
@property (weak, nonatomic) id <ASCollectionDelegate> delegate;
@property (weak, nonatomic) id <ASCollectionDataSource> dataSource;
@property (strong, nonatomic) UICollectionViewLayout *collectionViewLayout;
@property (nonatomic, assign) ASLayoutRangeMode rangeMode;
@property (nonatomic, assign) BOOL allowsSelection; // default is YES
@property (nonatomic, assign) BOOL allowsMultipleSelection; // default is NO
@property (nonatomic, assign) BOOL inverted; //default is NO
@end
@implementation _ASCollectionPendingState
- (instancetype)init
{
self = [super init];
if (self) {
_rangeMode = ASLayoutRangeModeUnspecified;
_allowsSelection = YES;
_allowsMultipleSelection = NO;
_inverted = NO;
}
return self;
}
@end
// TODO: Add support for tuning parameters in the pending state
#if 0 // This is not used yet, but will provide a way to avoid creating the view to set range values.
@implementation _ASCollectionPendingState {
std::vector<std::vector<ASRangeTuningParameters>> _tuningParameters;
}
- (instancetype)init
{
self = [super init];
if (self) {
_tuningParameters = std::vector<std::vector<ASRangeTuningParameters>> (ASLayoutRangeModeCount, std::vector<ASRangeTuningParameters> (ASLayoutRangeTypeCount));
_rangeMode = ASLayoutRangeModeUnspecified;
}
return self;
}
- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType
{
return [self tuningParametersForRangeMode:ASLayoutRangeModeFull rangeType:rangeType];
}
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
{
return [self setTuningParameters:tuningParameters forRangeMode:ASLayoutRangeModeFull rangeType:rangeType];
}
- (ASRangeTuningParameters)tuningParametersForRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType
{
ASDisplayNodeAssert(rangeMode < _tuningParameters.size() && rangeType < _tuningParameters[rangeMode].size(), @"Requesting a range that is OOB for the configured tuning parameters");
return _tuningParameters[rangeMode][rangeType];
}
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType
{
ASDisplayNodeAssert(rangeMode < _tuningParameters.size() && rangeType < _tuningParameters[rangeMode].size(), @"Setting a range that is OOB for the configured tuning parameters");
_tuningParameters[rangeMode][rangeType] = tuningParameters;
}
@end
#endif
#pragma mark - ASCollectionNode
@interface ASCollectionNode ()
{
ASDN::RecursiveMutex _environmentStateLock;
Class _collectionViewClass;
}
@property (nonatomic) _ASCollectionPendingState *pendingState;
@end
@implementation ASCollectionNode
#pragma mark Lifecycle
- (Class)collectionViewClass
{
return _collectionViewClass ? : [ASCollectionView class];
}
- (void)setCollectionViewClass:(Class)collectionViewClass
{
if (_collectionViewClass != collectionViewClass) {
ASDisplayNodeAssert([collectionViewClass isSubclassOfClass:[ASCollectionView class]] || collectionViewClass == Nil, @"ASCollectionNode requires that .collectionViewClass is an ASCollectionView subclass");
ASDisplayNodeAssert([self isNodeLoaded] == NO, @"ASCollectionNode's .collectionViewClass cannot be changed after the view is loaded");
_collectionViewClass = collectionViewClass;
}
}
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout
{
return [self initWithFrame:CGRectZero collectionViewLayout:layout layoutFacilitator:nil];
}
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
return [self initWithFrame:frame collectionViewLayout:layout layoutFacilitator:nil];
}
- (instancetype)initWithLayoutDelegate:(id<ASCollectionLayoutDelegate>)layoutDelegate layoutFacilitator:(id<ASCollectionViewLayoutFacilitatorProtocol>)layoutFacilitator
{
return [self initWithFrame:CGRectZero collectionViewLayout:[[ASCollectionLayout alloc] initWithLayoutDelegate:layoutDelegate] layoutFacilitator:layoutFacilitator];
}
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout layoutFacilitator:(id<ASCollectionViewLayoutFacilitatorProtocol>)layoutFacilitator
{
if (self = [super init]) {
// Must call the setter here to make sure pendingState is created and the layout is configured.
[self setCollectionViewLayout:layout];
__weak __typeof__(self) weakSelf = self;
[self setViewBlock:^{
__typeof__(self) strongSelf = weakSelf;
return [[[strongSelf collectionViewClass] alloc] _initWithFrame:frame collectionViewLayout:strongSelf->_pendingState.collectionViewLayout layoutFacilitator:layoutFacilitator eventLog:ASDisplayNodeGetEventLog(strongSelf)];
}];
}
return self;
}
#pragma mark ASDisplayNode
- (void)didLoad
{
[super didLoad];
ASCollectionView *view = self.view;
view.collectionNode = self;
if (_pendingState) {
_ASCollectionPendingState *pendingState = _pendingState;
self.pendingState = nil;
view.asyncDelegate = pendingState.delegate;
view.asyncDataSource = pendingState.dataSource;
view.inverted = pendingState.inverted;
view.allowsSelection = pendingState.allowsSelection;
view.allowsMultipleSelection = pendingState.allowsMultipleSelection;
if (pendingState.rangeMode != ASLayoutRangeModeUnspecified) {
[view.rangeController updateCurrentRangeWithMode:pendingState.rangeMode];
}
// Don't need to set collectionViewLayout to the view as the layout was already used to init the view in view block.
}
}
- (ASCollectionView *)view
{
return (ASCollectionView *)[super view];
}
- (void)clearContents
{
[super clearContents];
[self.rangeController clearContents];
}
- (void)interfaceStateDidChange:(ASInterfaceState)newState fromState:(ASInterfaceState)oldState
{
[super interfaceStateDidChange:newState fromState:oldState];
[ASRangeController layoutDebugOverlayIfNeeded];
}
- (void)didEnterPreloadState
{
// Intentionally allocate the view here so that super will trigger a layout pass on it which in turn will trigger the intial data load.
// We can get rid of this call later when ASDataController, ASRangeController and ASCollectionLayout can operate without the view.
[self view];
[super didEnterPreloadState];
}
#if ASRangeControllerLoggingEnabled
- (void)didEnterVisibleState
{
[super didEnterVisibleState];
NSLog(@"%@ - visible: YES", self);
}
- (void)didExitVisibleState
{
[super didExitVisibleState];
NSLog(@"%@ - visible: NO", self);
}
#endif
- (void)didExitPreloadState
{
[super didExitPreloadState];
[self.rangeController clearPreloadedData];
}
#pragma mark Setter / Getter
// TODO: Implement this without the view. Then revisit ASLayoutElementCollectionTableSetTraitCollection
- (ASDataController *)dataController
{
return self.view.dataController;
}
// TODO: Implement this without the view.
- (ASRangeController *)rangeController
{
return self.view.rangeController;
}
- (_ASCollectionPendingState *)pendingState
{
if (!_pendingState && ![self isNodeLoaded]) {
self.pendingState = [[_ASCollectionPendingState alloc] init];
}
ASDisplayNodeAssert(![self isNodeLoaded] || !_pendingState, @"ASCollectionNode should not have a pendingState once it is loaded");
return _pendingState;
}
- (void)setInverted:(BOOL)inverted
{
self.transform = inverted ? CATransform3DMakeScale(1, -1, 1) : CATransform3DIdentity;
if ([self pendingState]) {
_pendingState.inverted = inverted;
} else {
ASDisplayNodeAssert([self isNodeLoaded], @"ASCollectionNode should be loaded if pendingState doesn't exist");
self.view.inverted = inverted;
}
}
- (BOOL)inverted
{
if ([self pendingState]) {
return _pendingState.inverted;
} else {
return self.view.inverted;
}
}
- (void)setDelegate:(id <ASCollectionDelegate>)delegate
{
if ([self pendingState]) {
_pendingState.delegate = delegate;
} else {
ASDisplayNodeAssert([self isNodeLoaded], @"ASCollectionNode should be loaded if pendingState doesn't exist");
// Manually trampoline to the main thread. The view requires this be called on main
// and asserting here isn't an option – it is a common pattern for users to clear
// the delegate/dataSource in dealloc, which may be running on a background thread.
// It is important that we avoid retaining self in this block, so that this method is dealloc-safe.
ASCollectionView *view = self.view;
ASPerformBlockOnMainThread(^{
view.asyncDelegate = delegate;
});
}
}
- (id <ASCollectionDelegate>)delegate
{
if ([self pendingState]) {
return _pendingState.delegate;
} else {
return self.view.asyncDelegate;
}
}
- (void)setDataSource:(id <ASCollectionDataSource>)dataSource
{
if ([self pendingState]) {
_pendingState.dataSource = dataSource;
} else {
ASDisplayNodeAssert([self isNodeLoaded], @"ASCollectionNode should be loaded if pendingState doesn't exist");
// Manually trampoline to the main thread. The view requires this be called on main
// and asserting here isn't an option – it is a common pattern for users to clear
// the delegate/dataSource in dealloc, which may be running on a background thread.
// It is important that we avoid retaining self in this block, so that this method is dealloc-safe.
ASCollectionView *view = self.view;
ASPerformBlockOnMainThread(^{
view.asyncDataSource = dataSource;
});
}
}
- (id <ASCollectionDataSource>)dataSource
{
if ([self pendingState]) {
return _pendingState.dataSource;
} else {
return self.view.asyncDataSource;
}
}
- (void)setAllowsSelection:(BOOL)allowsSelection
{
if ([self pendingState]) {
_pendingState.allowsSelection = allowsSelection;
} else {
ASDisplayNodeAssert([self isNodeLoaded], @"ASCollectionNode should be loaded if pendingState doesn't exist");
self.view.allowsSelection = allowsSelection;
}
}
- (BOOL)allowsSelection
{
if ([self pendingState]) {
return _pendingState.allowsSelection;
} else {
return self.view.allowsSelection;
}
}
- (void)setAllowsMultipleSelection:(BOOL)allowsMultipleSelection
{
if ([self pendingState]) {
_pendingState.allowsMultipleSelection = allowsMultipleSelection;
} else {
ASDisplayNodeAssert([self isNodeLoaded], @"ASCollectionNode should be loaded if pendingState doesn't exist");
self.view.allowsMultipleSelection = allowsMultipleSelection;
}
}
- (BOOL)allowsMultipleSelection
{
if ([self pendingState]) {
return _pendingState.allowsMultipleSelection;
} else {
return self.view.allowsMultipleSelection;
}
}
- (void)setCollectionViewLayout:(UICollectionViewLayout *)layout
{
if ([self pendingState]) {
[self _configureCollectionViewLayout:layout];
_pendingState.collectionViewLayout = layout;
} else {
[self _configureCollectionViewLayout:layout];
self.view.collectionViewLayout = layout;
}
}
- (UICollectionViewLayout *)collectionViewLayout
{
if ([self pendingState]) {
return _pendingState.collectionViewLayout;
} else {
return self.view.collectionViewLayout;
}
}
- (ASElementMap *)visibleElements
{
ASDisplayNodeAssertMainThread();
// TODO Own the data controller when view is not yet loaded
return self.dataController.visibleMap;
}
- (id<ASCollectionLayoutDelegate>)layoutDelegate
{
UICollectionViewLayout *layout = self.collectionViewLayout;
if ([layout isKindOfClass:[ASCollectionLayout class]]) {
return ((ASCollectionLayout *)layout).layoutDelegate;
}
return nil;
}
#pragma mark - Range Tuning
- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType
{
return [self.rangeController tuningParametersForRangeMode:ASLayoutRangeModeFull rangeType:rangeType];
}
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType
{
[self.rangeController setTuningParameters:tuningParameters forRangeMode:ASLayoutRangeModeFull rangeType:rangeType];
}
- (ASRangeTuningParameters)tuningParametersForRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType
{
return [self.rangeController tuningParametersForRangeMode:rangeMode rangeType:rangeType];
}
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType
{
return [self.rangeController setTuningParameters:tuningParameters forRangeMode:rangeMode rangeType:rangeType];
}
#pragma mark - Selection
- (NSArray<NSIndexPath *> *)indexPathsForSelectedItems
{
ASDisplayNodeAssertMainThread();
ASCollectionView *view = self.view;
return [view convertIndexPathsToCollectionNode:view.indexPathsForSelectedItems];
}
- (void)selectItemAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition
{
ASDisplayNodeAssertMainThread();
ASCollectionView *collectionView = self.view;
indexPath = [collectionView convertIndexPathFromCollectionNode:indexPath waitingIfNeeded:YES];
if (indexPath != nil) {
[collectionView selectItemAtIndexPath:indexPath animated:animated scrollPosition:scrollPosition];
} else {
NSLog(@"Failed to select item at index path %@ because the item never reached the view.", indexPath);
}
}
- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated
{
ASDisplayNodeAssertMainThread();
ASCollectionView *collectionView = self.view;
indexPath = [collectionView convertIndexPathFromCollectionNode:indexPath waitingIfNeeded:YES];
if (indexPath != nil) {
[collectionView deselectItemAtIndexPath:indexPath animated:animated];
} else {
NSLog(@"Failed to deselect item at index path %@ because the item never reached the view.", indexPath);
}
}
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated
{
ASDisplayNodeAssertMainThread();
ASCollectionView *collectionView = self.view;
indexPath = [collectionView convertIndexPathFromCollectionNode:indexPath waitingIfNeeded:YES];
if (indexPath != nil) {
[collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated];
} else {
NSLog(@"Failed to scroll to item at index path %@ because the item never reached the view.", indexPath);
}
}
#pragma mark - Querying Data
- (void)reloadDataInitiallyIfNeeded
{
if (!self.dataController.initialReloadDataHasBeenCalled) {
[self reloadData];
}
}
- (NSInteger)numberOfItemsInSection:(NSInteger)section
{
[self reloadDataInitiallyIfNeeded];
return [self.dataController.pendingMap numberOfItemsInSection:section];
}
- (NSInteger)numberOfSections
{
[self reloadDataInitiallyIfNeeded];
return self.dataController.pendingMap.numberOfSections;
}
- (NSArray<__kindof ASCellNode *> *)visibleNodes
{
ASDisplayNodeAssertMainThread();
return self.isNodeLoaded ? [self.view visibleNodes] : @[];
}
- (ASCellNode *)nodeForItemAtIndexPath:(NSIndexPath *)indexPath
{
[self reloadDataInitiallyIfNeeded];
return [self.dataController.pendingMap elementForItemAtIndexPath:indexPath].node;
}
- (NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode
{
return [self.dataController.pendingMap indexPathForElement:cellNode.collectionElement];
}
- (NSArray<NSIndexPath *> *)indexPathsForVisibleItems
{
ASDisplayNodeAssertMainThread();
NSMutableArray *indexPathsArray = [NSMutableArray new];
for (ASCellNode *cell in [self visibleNodes]) {
NSIndexPath *indexPath = [self indexPathForNode:cell];
if (indexPath) {
[indexPathsArray addObject:indexPath];
}
}
return indexPathsArray;
}
- (nullable NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point
{
ASDisplayNodeAssertMainThread();
ASCollectionView *collectionView = self.view;
NSIndexPath *indexPath = [collectionView indexPathForItemAtPoint:point];
if (indexPath != nil) {
return [collectionView convertIndexPathToCollectionNode:indexPath];
}
return indexPath;
}
- (nullable UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ASDisplayNodeAssertMainThread();
ASCollectionView *collectionView = self.view;
indexPath = [collectionView convertIndexPathFromCollectionNode:indexPath waitingIfNeeded:YES];
if (indexPath == nil) {
return nil;
}
return [collectionView cellForItemAtIndexPath:indexPath];
}
- (id<ASSectionContext>)contextForSection:(NSInteger)section
{
ASDisplayNodeAssertMainThread();
return [self.dataController.pendingMap contextForSection:section];
}
#pragma mark - Editing
- (void)registerSupplementaryNodeOfKind:(NSString *)elementKind
{
[self.view registerSupplementaryNodeOfKind:elementKind];
}
- (void)performBatchAnimated:(BOOL)animated updates:(void (^)())updates completion:(void (^)(BOOL))completion
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view performBatchAnimated:animated updates:updates completion:completion];
} else {
if (updates) {
updates();
}
if (completion) {
completion(YES);
}
}
}
- (void)performBatchUpdates:(void (^)())updates completion:(void (^)(BOOL))completion
{
[self performBatchAnimated:UIView.areAnimationsEnabled updates:updates completion:completion];
}
- (void)waitUntilAllUpdatesAreCommitted
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view waitUntilAllUpdatesAreCommitted];
}
}
- (void)reloadDataWithCompletion:(void (^)())completion
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view reloadDataWithCompletion:completion];
}
}
- (void)reloadData
{
[self reloadDataWithCompletion:nil];
}
- (void)relayoutItems
{
[self.view relayoutItems];
}
- (void)reloadDataImmediately
{
[self.view reloadDataImmediately];
}
- (void)beginUpdates
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view beginUpdates];
}
}
- (void)endUpdatesAnimated:(BOOL)animated
{
[self endUpdatesAnimated:animated completion:nil];
}
- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^)(BOOL))completion
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view endUpdatesAnimated:animated completion:completion];
}
}
- (void)insertSections:(NSIndexSet *)sections
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view insertSections:sections];
}
}
- (void)deleteSections:(NSIndexSet *)sections
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view deleteSections:sections];
}
}
- (void)reloadSections:(NSIndexSet *)sections
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view reloadSections:sections];
}
}
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view moveSection:section toSection:newSection];
}
}
- (void)insertItemsAtIndexPaths:(NSArray *)indexPaths
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view insertItemsAtIndexPaths:indexPaths];
}
}
- (void)deleteItemsAtIndexPaths:(NSArray *)indexPaths
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view deleteItemsAtIndexPaths:indexPaths];
}
}
- (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view reloadItemsAtIndexPaths:indexPaths];
}
}
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
{
ASDisplayNodeAssertMainThread();
if (self.nodeLoaded) {
[self.view moveItemAtIndexPath:indexPath toIndexPath:newIndexPath];
}
}
#pragma mark - ASRangeControllerUpdateRangeProtocol
- (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode;
{
if ([self pendingState]) {
_pendingState.rangeMode = rangeMode;
} else {
[self.rangeController updateCurrentRangeWithMode:rangeMode];
}
}
#pragma mark - ASPrimitiveTraitCollection
ASLayoutElementCollectionTableSetTraitCollection(_environmentStateLock)
#pragma mark - Debugging (Private)
- (NSMutableArray<NSDictionary *> *)propertiesForDebugDescription
{
NSMutableArray<NSDictionary *> *result = [super propertiesForDebugDescription];
[result addObject:@{ @"dataSource" : ASObjectDescriptionMakeTiny(self.dataSource) }];
[result addObject:@{ @"delegate" : ASObjectDescriptionMakeTiny(self.delegate) }];
return result;
}
#pragma mark - Private methods
- (void)_configureCollectionViewLayout:(UICollectionViewLayout *)layout
{
if ([layout isKindOfClass:[ASCollectionLayout class]]) {
ASCollectionLayout *collectionLayout = (ASCollectionLayout *)layout;
collectionLayout.collectionNode = self;
}
}
@end