Skip to content

Commit

Permalink
Introduce ASCellLayoutMode (TextureGroup#1273)
Browse files Browse the repository at this point in the history
* Introduce ASCellLayoutMode

* Some smaller improvements

* Improve logic around _superPerformBatchUpdates:completion:

* Add comment about default values for ASCellLayoutModeNone

* Always call _superReloadData:completion: within UICollectionView

* Add initial range test for ASCellLayoutModeNone
  • Loading branch information
maicki authored and wsdwsd0829 committed Mar 15, 2019
1 parent 61d6ebf commit b8b69c7
Show file tree
Hide file tree
Showing 18 changed files with 356 additions and 129 deletions.
26 changes: 13 additions & 13 deletions Source/ASCollectionNode+Beta.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ NS_ASSUME_NONNULL_BEGIN
@property (nullable, nonatomic, weak) id<ASBatchFetchingDelegate> batchFetchingDelegate;

/**
* When this mode is enabled, ASCollectionView matches the timing of UICollectionView as closely as possible,
* ensuring that all reload and edit operations are performed on the main thread as blocking calls.
* When this mode is enabled, ASCollectionView matches the timing of UICollectionView as closely as
* possible, ensuring that all reload and edit operations are performed on the main thread as
* blocking calls.
*
* This mode is useful for applications that are debugging issues with their collection view implementation.
* In particular, some applications do not properly conform to the API requirement of UICollectionView, and these
* applications may experience difficulties with ASCollectionView. Providing this mode allows for developers to
* work towards resolving technical debt in their collection view data source, while ramping up asynchronous
* collection layout.
* This mode is useful for applications that are debugging issues with their collection view
* implementation. In particular, some applications do not properly conform to the API requirement
* of UICollectionView, and these applications may experience difficulties with ASCollectionView.
* Providing this mode allows for developers to work towards resolving technical debt in their
* collection view data source, while ramping up asynchronous collection layout.
*
* NOTE: Because this mode results in expensive operations like cell layout being performed on the main thread,
* it should be used as a tool to resolve data source conformance issues with Apple collection view API.
* NOTE: Because this mode results in expensive operations like cell layout being performed on the
* main thread, it should be used as a tool to resolve data source conformance issues with Apple
* collection view API.
*
* @default defaults to NO.
* @default defaults to ASCellLayoutModeNone.
*/
@property (nonatomic) BOOL usesSynchronousDataLoading;
@property (nonatomic) ASCellLayoutMode cellLayoutMode;

/**
* Returns YES if the ASCollectionNode contents are completely synchronized with the underlying collection-view layout.
Expand All @@ -72,8 +74,6 @@ NS_ASSUME_NONNULL_BEGIN

- (void)endUpdatesAnimated:(BOOL)animated completion:(nullable void (^)(BOOL))completion ASDISPLAYNODE_DEPRECATED_MSG("Use -performBatchUpdates:completion: instead.");

- (void)invalidateFlowLayoutDelegateMetrics;

@end

NS_ASSUME_NONNULL_END
16 changes: 8 additions & 8 deletions Source/ASCollectionNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ @interface _ASCollectionPendingState : NSObject {
@property (nonatomic) BOOL allowsSelection; // default is YES
@property (nonatomic) BOOL allowsMultipleSelection; // default is NO
@property (nonatomic) BOOL inverted; //default is NO
@property (nonatomic) BOOL usesSynchronousDataLoading;
@property (nonatomic) ASCellLayoutMode cellLayoutMode;
@property (nonatomic) CGFloat leadingScreensForBatching;
@property (nonatomic, weak) id <ASCollectionViewLayoutInspecting> layoutInspector;
@property (nonatomic) BOOL alwaysBounceVertical;
Expand Down Expand Up @@ -193,7 +193,7 @@ - (void)didLoad
view.inverted = pendingState.inverted;
view.allowsSelection = pendingState.allowsSelection;
view.allowsMultipleSelection = pendingState.allowsMultipleSelection;
view.usesSynchronousDataLoading = pendingState.usesSynchronousDataLoading;
view.cellLayoutMode = pendingState.cellLayoutMode;
view.layoutInspector = pendingState.layoutInspector;
view.showsVerticalScrollIndicator = pendingState.showsVerticalScrollIndicator;
view.showsHorizontalScrollIndicator = pendingState.showsHorizontalScrollIndicator;
Expand Down Expand Up @@ -628,21 +628,21 @@ - (void)setBatchFetchingDelegate:(id<ASBatchFetchingDelegate>)batchFetchingDeleg
return _batchFetchingDelegate;
}

- (BOOL)usesSynchronousDataLoading
- (ASCellLayoutMode)cellLayoutMode
{
if ([self pendingState]) {
return _pendingState.usesSynchronousDataLoading;
return _pendingState.cellLayoutMode;
} else {
return self.view.usesSynchronousDataLoading;
return self.view.cellLayoutMode;
}
}

- (void)setUsesSynchronousDataLoading:(BOOL)usesSynchronousDataLoading
- (void)setCellLayoutMode:(ASCellLayoutMode)cellLayoutMode
{
if ([self pendingState]) {
_pendingState.usesSynchronousDataLoading = usesSynchronousDataLoading;
_pendingState.cellLayoutMode = cellLayoutMode;
} else {
self.view.usesSynchronousDataLoading = usesSynchronousDataLoading;
self.view.cellLayoutMode = cellLayoutMode;
}
}

Expand Down
Loading

0 comments on commit b8b69c7

Please sign in to comment.