Skip to content

Commit

Permalink
Add option to enable main-thread mode #3
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii authored Feb 19, 2023
1 parent 835f48d commit 68df47f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Source/ASCollectionNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nullable, weak) id <ASCollectionDataSource> dataSource;

/**
* A Boolean valut that indicates whether performs collection node as main thread only.
*/
@property (nonatomic) BOOL isMainThreadModeEnabled;

/**
* The number of screens left to scroll before the delegate -collectionNode:beginBatchFetchingWithContext: is called.
*
Expand Down
10 changes: 10 additions & 0 deletions Source/ASCollectionNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,16 @@ - (_ASCollectionPendingState *)pendingState
return _pendingState;
}

- (void)setIsMainThreadModeEnabled:(BOOL)isMainThreadModeEnabled
{
self.dataController.isMainThreadModeEnabled = isMainThreadModeEnabled;
}

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

- (void)setInverted:(BOOL)inverted
{
self.transform = inverted ? CATransform3DMakeScale(1, -1, 1) : CATransform3DIdentity;
Expand Down
2 changes: 2 additions & 0 deletions Source/Details/ASDataController.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ ASDK_EXTERN NSString * const ASCollectionInvalidUpdateException;

- (instancetype)init NS_UNAVAILABLE;

@property (nonatomic) BOOL isMainThreadModeEnabled;

/**
* The node that owns this data controller, if any.
*
Expand Down
2 changes: 1 addition & 1 deletion Source/Details/ASDataController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ - (void)updateWithChangeSet:(_ASHierarchyChangeSet *)changeSet

// Step 3 can be done on the main thread or on _editingTransactionQueue
// depending on an experiment.
BOOL mainThreadOnly = ASActivateExperimentalFeature(ASExperimentalMainThreadOnlyDataController);
BOOL mainThreadOnly = self.isMainThreadModeEnabled || ASActivateExperimentalFeature(ASExperimentalMainThreadOnlyDataController);
if (mainThreadOnly) {
// In main-thread-only mode allocate and layout all nodes serially on the main thread.
//
Expand Down

0 comments on commit 68df47f

Please sign in to comment.