1313#import " ASCollectionDataController.h"
1414#import " ASCollectionViewLayoutController.h"
1515#import " ASCollectionViewFlowLayoutInspector.h"
16+ #import " ASCollectionViewLayoutFacilitatorProtocol.h"
1617#import " ASDisplayNode+FrameworkPrivate.h"
1718#import " ASDisplayNode+Beta.h"
1819#import " ASInternalHelpers.h"
@@ -67,6 +68,8 @@ @interface ASCollectionView () <ASRangeControllerDataSource, ASRangeControllerDe
6768 ASRangeController *_rangeController;
6869 ASCollectionViewLayoutController *_layoutController;
6970 ASCollectionViewFlowLayoutInspector *_flowLayoutInspector;
71+
72+ id <ASCollectionViewLayoutFacilitatorProtocol> _layoutFacilitator;
7073
7174 BOOL _performingBatchUpdates;
7275 NSMutableArray *_batchUpdateBlocks;
@@ -137,13 +140,25 @@ - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionVi
137140 return [self _initWithFrame: frame collectionViewLayout: layout ownedByNode: NO ];
138141}
139142
143+ - (instancetype )initWithFrame : (CGRect)frame collectionViewLayout : (UICollectionViewLayout *)layout layoutFacilitator : (id <ASCollectionViewLayoutFacilitatorProtocol>)layoutFacilitator
144+ {
145+ self = [self _initWithFrame: frame collectionViewLayout: layout ownedByNode: NO ];
146+ _layoutFacilitator = layoutFacilitator;
147+ return self;
148+ }
149+
140150// FIXME: This method is deprecated and will probably be removed in or shortly after 2.0.
141151- (instancetype )initWithFrame : (CGRect)frame collectionViewLayout : (UICollectionViewLayout *)layout asyncDataFetching : (BOOL )asyncDataFetchingEnabled
142152{
143153 return [self _initWithFrame: frame collectionViewLayout: layout ownedByNode: NO ];
144154}
145155
146156- (instancetype )_initWithFrame : (CGRect)frame collectionViewLayout : (UICollectionViewLayout *)layout ownedByNode : (BOOL )ownedByNode
157+ {
158+ return [self _initWithFrame: frame collectionViewLayout: layout layoutFacilitator: nil ownedByNode: ownedByNode];
159+ }
160+
161+ - (instancetype )_initWithFrame : (CGRect)frame collectionViewLayout : (UICollectionViewLayout *)layout layoutFacilitator : (id <ASCollectionViewLayoutFacilitatorProtocol>)layoutFacilitator ownedByNode : (BOOL )ownedByNode
147162{
148163 if (!(self = [super initWithFrame: frame collectionViewLayout: layout]))
149164 return nil ;
@@ -195,6 +210,7 @@ - (instancetype)_initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionV
195210 if ([layout asdk_isFlowLayout ]) {
196211 _layoutInspector = [self flowLayoutInspector ];
197212 }
213+ _layoutFacilitator = layoutFacilitator;
198214
199215 _proxyDelegate = [[ASCollectionViewProxy alloc ] initWithTarget: nil interceptor: self ];
200216 super.delegate = (id <UICollectionViewDelegate>)_proxyDelegate;
@@ -833,7 +849,7 @@ - (void)didBeginUpdatesInRangeController:(ASRangeController *)rangeController
833849- (void )rangeController : (ASRangeController *)rangeController didEndUpdatesAnimated : (BOOL )animated completion : (void (^)(BOOL ))completion
834850{
835851 ASDisplayNodeAssertMainThread ();
836-
852+
837853 if (!self.asyncDataSource || _superIsPendingDataLoad) {
838854 if (completion) {
839855 completion (NO );
@@ -856,7 +872,7 @@ - (void)rangeController:(ASRangeController *)rangeController didEndUpdatesAnimat
856872- (void )rangeController : (ASRangeController *)rangeController didInsertNodes : (NSArray *)nodes atIndexPaths : (NSArray *)indexPaths withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
857873{
858874 ASDisplayNodeAssertMainThread ();
859-
875+ [_layoutFacilitator collectionViewEditingCellsAtIndexPaths: indexPaths];
860876 if (!self.asyncDataSource || _superIsPendingDataLoad) {
861877 return ; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes
862878 }
@@ -875,7 +891,7 @@ - (void)rangeController:(ASRangeController *)rangeController didInsertNodes:(NSA
875891- (void )rangeController : (ASRangeController *)rangeController didDeleteNodes : (NSArray *)nodes atIndexPaths : (NSArray *)indexPaths withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
876892{
877893 ASDisplayNodeAssertMainThread ();
878-
894+ [_layoutFacilitator collectionViewEditingCellsAtIndexPaths: indexPaths];
879895 if (!self.asyncDataSource || _superIsPendingDataLoad) {
880896 return ; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes
881897 }
@@ -894,7 +910,7 @@ - (void)rangeController:(ASRangeController *)rangeController didDeleteNodes:(NSA
894910- (void )rangeController : (ASRangeController *)rangeController didInsertSectionsAtIndexSet : (NSIndexSet *)indexSet withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
895911{
896912 ASDisplayNodeAssertMainThread ();
897-
913+ [_layoutFacilitator collectionViewEditingSectionsAtIndexSet: indexSet];
898914 if (!self.asyncDataSource || _superIsPendingDataLoad) {
899915 return ; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes
900916 }
@@ -913,7 +929,7 @@ - (void)rangeController:(ASRangeController *)rangeController didInsertSectionsAt
913929- (void )rangeController : (ASRangeController *)rangeController didDeleteSectionsAtIndexSet : (NSIndexSet *)indexSet withAnimationOptions : (ASDataControllerAnimationOptions)animationOptions
914930{
915931 ASDisplayNodeAssertMainThread ();
916-
932+ [_layoutFacilitator collectionViewEditingSectionsAtIndexSet: indexSet];
917933 if (!self.asyncDataSource || _superIsPendingDataLoad) {
918934 return ; // if the asyncDataSource has become invalid while we are processing, ignore this request to avoid crashes
919935 }
0 commit comments