Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASCollectionView] synchronous mode #332

Merged
merged 5 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## master

* Add your own contributions to the next release on the line below this with your name.
- Add a synchronous mode to ASCollectionNode, for colletion view data source debugging. [Hannah Troisi](https://github.com/hannahmbanana)
- Fixed an issue where GIFs with placeholders never had their placeholders uncover the GIF. [Garrett Moon](https://github.com/garrettmoon)
- [Yoga] Implement ASYogaLayoutSpec, a simplified integration strategy for Yoga-powered layout calculation. [Scott Goodson](https://github.com/appleguy)
- Fixed an issue where calls to setNeedsDisplay and setNeedsLayout would stop working on loaded nodes. [Garrett Moon](https://github.com/garrettmoon)
Expand Down
17 changes: 17 additions & 0 deletions Source/ASCollectionNode+Beta.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ NS_ASSUME_NONNULL_BEGIN

@property (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.
*
* 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.
*
* @default defaults to NO.
*/
@property (nonatomic, assign) BOOL usesSynchronousDataLoading;

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout layoutFacilitator:(nullable id<ASCollectionViewLayoutFacilitatorProtocol>)layoutFacilitator;

- (instancetype)initWithLayoutDelegate:(id<ASCollectionLayoutDelegate>)layoutDelegate layoutFacilitator:(nullable id<ASCollectionViewLayoutFacilitatorProtocol>)layoutFacilitator;
Expand Down
10 changes: 10 additions & 0 deletions Source/ASCollectionNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@ - (void)setBatchFetchingDelegate:(id<ASBatchFetchingDelegate>)batchFetchingDeleg
return _batchFetchingDelegate;
}

- (BOOL)usesSynchronousDataLoading
{
return self.view.usesSynchronousDataLoading;
}

- (void)setUsesSynchronousDataLoading:(BOOL)usesSynchronousDataLoading
{
self.view.usesSynchronousDataLoading = usesSynchronousDataLoading;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, this may actually trigger a premature view allocation. Let's handle it now by putting the flag in pending state if the node is not loaded yet.

}

#pragma mark - Range Tuning

- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType
Expand Down
10 changes: 10 additions & 0 deletions Source/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,16 @@ - (NSArray *)visibleNodes
return visibleNodes;
}

- (BOOL)usesSynchronousDataLoading
{
return self.dataController.usesSynchronousDataLoading;
}

- (void)setUsesSynchronousDataLoading:(BOOL)usesSynchronousDataLoading
{
self.dataController.usesSynchronousDataLoading = usesSynchronousDataLoading;
}

#pragma mark Internal

- (void)_configureCollectionViewLayout:(nonnull UICollectionViewLayout *)layout
Expand Down
5 changes: 5 additions & 0 deletions Source/Details/ASCollectionInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, readonly) ASDataController *dataController;
@property (nonatomic, strong, readonly) ASRangeController *rangeController;

/**
* @see ASCollectionNode+Beta.h for full documentation.
*/
@property (nonatomic, assign) BOOL usesSynchronousDataLoading;

/**
* Attempt to get the view-layer index path for the item with the given index path.
*
Expand Down
5 changes: 5 additions & 0 deletions Source/Details/ASDataController.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ extern NSString * const ASCollectionInvalidUpdateException;
@property (nonatomic, strong, readonly) ASEventLog *eventLog;
#endif

/**
* @see ASCollectionNode+Beta.h for full documentation.
*/
@property (nonatomic, assign) BOOL usesSynchronousDataLoading;

/** @name Data Updating */

- (void)updateWithChangeSet:(_ASHierarchyChangeSet *)changeSet;
Expand Down
4 changes: 4 additions & 0 deletions Source/Details/ASDataController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,10 @@ - (void)updateWithChangeSet:(_ASHierarchyChangeSet *)changeSet
}];
}];
});

if (_usesSynchronousDataLoading) {
dispatch_group_wait(_editingTransactionGroup, DISPATCH_TIME_FOREVER);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call -waitUntilAllUpdatesAreCommitted instead?

}
}

/**
Expand Down