Skip to content

Commit 23d0449

Browse files
rcancroJohnEstropia
authored andcommitted
Add NS_SWIFT_UI_ACTOR to methods always called on main (TextureGroup#2121)
* Add NS_SWIFT_UI_ACTOR to methods always called on main * found a couple more main actor blocks/methods (cherry picked from commit 83c6ff8)
1 parent dbf101a commit 23d0449

15 files changed

+94
-92
lines changed

Source/ASCellNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
133133
* The backing view controller, or @c nil if the node wasn't initialized with backing view controller
134134
* @note This property must be accessed on the main thread.
135135
*/
136-
@property (nullable, nonatomic, readonly) UIViewController *viewController;
136+
@property (nullable, nonatomic, readonly) UIViewController *viewController NS_SWIFT_UI_ACTOR;
137137

138138

139139
/**

Source/ASCollectionNode+Beta.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
2626
/**
2727
* The elements that are currently displayed. The "UIKit index space". Must be accessed on main thread.
2828
*/
29-
@property (nonatomic, readonly) ASElementMap *visibleElements;
29+
@property (nonatomic, readonly) ASElementMap *visibleElements NS_SWIFT_UI_ACTOR;
3030

3131
@property (nullable, readonly) id<ASCollectionLayoutDelegate> layoutDelegate;
3232

@@ -62,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN
6262
*
6363
* When isSynchronized == YES, the block is run block immediately (before the method returns).
6464
*/
65-
- (void)onDidFinishSynchronizing:(void (^)(void))didFinishSynchronizing;
65+
- (void)onDidFinishSynchronizing:(NS_SWIFT_UI_ACTOR void (^)(void))didFinishSynchronizing;
6666

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

Source/ASCollectionNode.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ NS_ASSUME_NONNULL_BEGIN
231231
*
232232
* This method must be called on the main thread.
233233
*/
234-
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated;
234+
- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated NS_SWIFT_UI_ACTOR;
235235

236236
/**
237237
* Determines collection node's current scroll direction. Supports 2-axis collection nodes.
@@ -271,7 +271,7 @@ NS_ASSUME_NONNULL_BEGIN
271271
* Boolean parameter that contains the value YES if all of the related animations completed successfully or
272272
* NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread.
273273
*/
274-
- (void)performBatchAnimated:(BOOL)animated updates:(nullable AS_NOESCAPE void (^)(void))updates completion:(nullable void (^)(BOOL finished))completion;
274+
- (void)performBatchAnimated:(BOOL)animated updates:(nullable AS_NOESCAPE void (^)(void))updates completion:(nullable NS_SWIFT_UI_ACTOR void (^)(BOOL finished))completion NS_SWIFT_UI_ACTOR;
275275

276276
/**
277277
* Perform a batch of updates asynchronously, optionally disabling all animations in the batch. This method must be called from the main thread.
@@ -282,7 +282,7 @@ NS_ASSUME_NONNULL_BEGIN
282282
* Boolean parameter that contains the value YES if all of the related animations completed successfully or
283283
* NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread.
284284
*/
285-
- (void)performBatchUpdates:(nullable AS_NOESCAPE void (^)(void))updates completion:(nullable void (^)(BOOL finished))completion;
285+
- (void)performBatchUpdates:(nullable AS_NOESCAPE void (^)(void))updates completion:(nullable void (^)(BOOL finished))completion NS_SWIFT_UI_ACTOR;
286286

287287
/**
288288
* Returns YES if the ASCollectionNode is still processing changes from performBatchUpdates:.
@@ -311,7 +311,7 @@ NS_ASSUME_NONNULL_BEGIN
311311
*
312312
* Calling -waitUntilAllUpdatesAreProcessed is one way to flush any pending update completion blocks.
313313
*/
314-
- (void)onDidFinishProcessingUpdates:(void (^)(void))didFinishProcessingUpdates;
314+
- (void)onDidFinishProcessingUpdates:(NS_SWIFT_UI_ACTOR void (^)(void))didFinishProcessingUpdates;
315315

316316
/**
317317
* Blocks execution of the main thread until all section and item updates are committed to the view. This method must be called from the main thread.
@@ -326,7 +326,7 @@ NS_ASSUME_NONNULL_BEGIN
326326
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
327327
* before this method is called.
328328
*/
329-
- (void)insertSections:(NSIndexSet *)sections;
329+
- (void)insertSections:(NSIndexSet *)sections NS_SWIFT_UI_ACTOR;
330330

331331
/**
332332
* Deletes one or more sections.
@@ -336,7 +336,7 @@ NS_ASSUME_NONNULL_BEGIN
336336
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
337337
* before this method is called.
338338
*/
339-
- (void)deleteSections:(NSIndexSet *)sections;
339+
- (void)deleteSections:(NSIndexSet *)sections NS_SWIFT_UI_ACTOR;
340340

341341
/**
342342
* Reloads the specified sections.
@@ -346,7 +346,7 @@ NS_ASSUME_NONNULL_BEGIN
346346
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
347347
* before this method is called.
348348
*/
349-
- (void)reloadSections:(NSIndexSet *)sections;
349+
- (void)reloadSections:(NSIndexSet *)sections NS_SWIFT_UI_ACTOR;
350350

351351
/**
352352
* Moves a section to a new location.
@@ -358,7 +358,7 @@ NS_ASSUME_NONNULL_BEGIN
358358
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
359359
* before this method is called.
360360
*/
361-
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection;
361+
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection NS_SWIFT_UI_ACTOR;
362362

363363
/**
364364
* Inserts items at the locations identified by an array of index paths.
@@ -368,7 +368,7 @@ NS_ASSUME_NONNULL_BEGIN
368368
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
369369
* before this method is called.
370370
*/
371-
- (void)insertItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;
371+
- (void)insertItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths NS_SWIFT_UI_ACTOR;
372372

373373
/**
374374
* Deletes the items specified by an array of index paths.
@@ -378,7 +378,7 @@ NS_ASSUME_NONNULL_BEGIN
378378
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
379379
* before this method is called.
380380
*/
381-
- (void)deleteItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;
381+
- (void)deleteItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths NS_SWIFT_UI_ACTOR;
382382

383383
/**
384384
* Reloads the specified items.
@@ -388,7 +388,7 @@ NS_ASSUME_NONNULL_BEGIN
388388
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
389389
* before this method is called.
390390
*/
391-
- (void)reloadItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths;
391+
- (void)reloadItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths NS_SWIFT_UI_ACTOR;
392392

393393
/**
394394
* Moves the item at a specified location to a destination location.
@@ -400,7 +400,7 @@ NS_ASSUME_NONNULL_BEGIN
400400
* @discussion This method must be called from the main thread. The data source must be updated to reflect the changes
401401
* before this method is called.
402402
*/
403-
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;
403+
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath NS_SWIFT_UI_ACTOR;
404404

405405
/**
406406
* Reload everything from scratch, destroying the working range and all cached nodes.
@@ -409,7 +409,7 @@ NS_ASSUME_NONNULL_BEGIN
409409
* the main thread.
410410
* @warning This method is substantially more expensive than UICollectionView's version.
411411
*/
412-
- (void)reloadDataWithCompletion:(nullable void (^)(void))completion;
412+
- (void)reloadDataWithCompletion:(nullable NS_SWIFT_UI_ACTOR void (^)(void))completion;
413413

414414

415415
/**
@@ -446,7 +446,7 @@ NS_ASSUME_NONNULL_BEGIN
446446
*
447447
* @discussion This method must be called from the main thread.
448448
*/
449-
- (void)selectItemAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition;
449+
- (void)selectItemAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition NS_SWIFT_UI_ACTOR;
450450

451451
/**
452452
* Deselects the item at the specified index.
@@ -459,7 +459,7 @@ NS_ASSUME_NONNULL_BEGIN
459459
*
460460
* @discussion This method must be called from the main thread.
461461
*/
462-
- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;
462+
- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated NS_SWIFT_UI_ACTOR;
463463

464464
#pragma mark - Querying Data
465465

@@ -482,7 +482,7 @@ NS_ASSUME_NONNULL_BEGIN
482482
*
483483
* @return an array containing the nodes being displayed on screen. This must be called on the main thread.
484484
*/
485-
@property (nonatomic, readonly) NSArray<__kindof ASCellNode *> *visibleNodes;
485+
@property (nonatomic, readonly) NSArray<__kindof ASCellNode *> *visibleNodes NS_SWIFT_UI_ACTOR;
486486

487487
/**
488488
* Retrieves the node for the item at the given index path.
@@ -518,7 +518,7 @@ NS_ASSUME_NONNULL_BEGIN
518518
*
519519
* @return an array containing the index paths of all visible items. This must be called on the main thread.
520520
*/
521-
@property (nonatomic, readonly) NSArray<NSIndexPath *> *indexPathsForVisibleItems;
521+
@property (nonatomic, readonly) NSArray<NSIndexPath *> *indexPathsForVisibleItems NS_SWIFT_UI_ACTOR;
522522

523523
/**
524524
* Retrieve the index path of the item at the given point.
@@ -527,7 +527,7 @@ NS_ASSUME_NONNULL_BEGIN
527527
*
528528
* @return The indexPath for the item at the given point. This must be called on the main thread.
529529
*/
530-
- (nullable NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point AS_WARN_UNUSED_RESULT;
530+
- (nullable NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point AS_WARN_UNUSED_RESULT NS_SWIFT_UI_ACTOR;
531531

532532
/**
533533
* Retrieve the cell at the given index path.
@@ -536,7 +536,7 @@ NS_ASSUME_NONNULL_BEGIN
536536
*
537537
* @return The cell for the given index path. This must be called on the main thread.
538538
*/
539-
- (nullable UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath;
539+
- (nullable UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath NS_SWIFT_UI_ACTOR;
540540

541541
/**
542542
* Retrieves the context object for the given section, as provided by the data source in
@@ -615,7 +615,7 @@ NS_ASSUME_NONNULL_BEGIN
615615
* not implement reuse (it will be called once per item). Unlike UICollectionView's version,
616616
* this method is not called when the item is about to display.
617617
*/
618-
- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForItemAtIndexPath:(NSIndexPath *)indexPath;
618+
- (ASCellNode *)collectionNode:(ASCollectionNode *)collectionNode nodeForItemAtIndexPath:(NSIndexPath *)indexPath NS_SWIFT_UI_ACTOR;
619619

620620
/**
621621
* Asks the data source to provide a node-block to display for the given supplementary element in the collection view.

Source/ASCollectionView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
7979
*
8080
* @return The context object, or @c nil if no context was provided.
8181
*/
82-
- (nullable id<ASSectionContext>)contextForSection:(NSInteger)section AS_WARN_UNUSED_RESULT;
82+
- (nullable id<ASSectionContext>)contextForSection:(NSInteger)section AS_WARN_UNUSED_RESULT NS_SWIFT_UI_ACTOR;
8383

8484
@end
8585

Source/ASDisplayNode+Convenience.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
2121
* @warning This property may only be accessed on the main thread. This property may
2222
* be @c nil until the node's view is actually hosted in the view hierarchy.
2323
*/
24-
@property (nonatomic, nullable, readonly) __kindof UIViewController *closestViewController;
24+
@property (nonatomic, nullable, readonly) __kindof UIViewController *closestViewController NS_SWIFT_UI_ACTOR;
2525

2626
@end
2727

Source/ASDisplayNode+InterfaceState.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,63 +46,63 @@ typedef NS_OPTIONS(unsigned char, ASInterfaceState)
4646
* @discussion Subclasses may use this to monitor when they become visible, should free cached data, and much more.
4747
* @see ASInterfaceState
4848
*/
49-
- (void)interfaceStateDidChange:(ASInterfaceState)newState fromState:(ASInterfaceState)oldState;
49+
- (void)interfaceStateDidChange:(ASInterfaceState)newState fromState:(ASInterfaceState)oldState NS_SWIFT_UI_ACTOR;
5050

5151
/**
5252
* @abstract Called whenever the node becomes visible.
5353
* @discussion Subclasses may use this to monitor when they become visible.
5454
* @note This method is guaranteed to be called on main.
5555
*/
56-
- (void)didEnterVisibleState;
56+
- (void)didEnterVisibleState NS_SWIFT_UI_ACTOR;
5757

5858
/**
5959
* @abstract Called whenever the node is no longer visible.
6060
* @discussion Subclasses may use this to monitor when they are no longer visible.
6161
* @note This method is guaranteed to be called on main.
6262
*/
63-
- (void)didExitVisibleState;
63+
- (void)didExitVisibleState NS_SWIFT_UI_ACTOR;
6464

6565
/**
6666
* @abstract Called whenever the the node has entered the display state.
6767
* @discussion Subclasses may use this to monitor when a node should be rendering its content.
6868
* @note This method is guaranteed to be called on main.
6969
*/
70-
- (void)didEnterDisplayState;
70+
- (void)didEnterDisplayState NS_SWIFT_UI_ACTOR;
7171

7272
/**
7373
* @abstract Called whenever the the node has exited the display state.
7474
* @discussion Subclasses may use this to monitor when a node should no longer be rendering its content.
7575
* @note This method is guaranteed to be called on main.
7676
*/
77-
- (void)didExitDisplayState;
77+
- (void)didExitDisplayState NS_SWIFT_UI_ACTOR;
7878

7979
/**
8080
* @abstract Called whenever the the node has entered the preload state.
8181
* @discussion Subclasses may use this to monitor data for a node should be preloaded, either from a local or remote source.
8282
* @note This method is guaranteed to be called on main.
8383
*/
84-
- (void)didEnterPreloadState;
84+
- (void)didEnterPreloadState NS_SWIFT_UI_ACTOR;
8585

8686
/**
8787
* @abstract Called whenever the the node has exited the preload state.
8888
* @discussion Subclasses may use this to monitor whether preloading data for a node should be canceled.
8989
* @note This method is guaranteed to be called on main.
9090
*/
91-
- (void)didExitPreloadState;
91+
- (void)didExitPreloadState NS_SWIFT_UI_ACTOR;
9292

9393
/**
9494
* @abstract Called when the node has completed applying the layout.
9595
* @discussion Can be used for operations that are performed after layout has completed.
9696
* @note This method is guaranteed to be called on main.
9797
*/
98-
- (void)nodeDidLayout;
98+
- (void)nodeDidLayout NS_SWIFT_UI_ACTOR;
9999

100100
/**
101101
* @abstract Called when the node loads.
102102
* @discussion Can be used for operations that are performed after the node's view is available.
103103
* @note This method is guaranteed to be called on main.
104104
*/
105-
- (void)nodeDidLoad;
105+
- (void)nodeDidLoad NS_SWIFT_UI_ACTOR;
106106

107107
/**
108108
* @abstract Indicates that the receiver and all subnodes have finished displaying.
@@ -114,7 +114,7 @@ typedef NS_OPTIONS(unsigned char, ASInterfaceState)
114114
* the progressImage block.
115115
* @note This method is guaranteed to be called on main.
116116
*/
117-
- (void)hierarchyDisplayDidFinish;
117+
- (void)hierarchyDisplayDidFinish NS_SWIFT_UI_ACTOR;
118118

119119
@optional
120120
/**
@@ -125,7 +125,7 @@ typedef NS_OPTIONS(unsigned char, ASInterfaceState)
125125
* to attempt to ascend the node tree when handling this, as the root node is locked when this is
126126
* called.
127127
*/
128-
- (void)nodeWillCalculateLayout:(ASSizeRange)constrainedSize;
128+
- (void)nodeWillCalculateLayout:(ASSizeRange)constrainedSize NS_SWIFT_UI_ACTOR;
129129

130130
/**
131131
* @abstract Called when the node's layer is about to enter the hierarchy.
@@ -134,7 +134,7 @@ typedef NS_OPTIONS(unsigned char, ASInterfaceState)
134134
* re-parented multiple times, and each time will trigger this call.
135135
* @note This method is guaranteed to be called on main.
136136
*/
137-
- (void)didEnterHierarchy;
137+
- (void)didEnterHierarchy NS_SWIFT_UI_ACTOR;
138138

139139
/**
140140
* @abstract Called when the node's layer has exited the hierarchy.
@@ -143,6 +143,6 @@ typedef NS_OPTIONS(unsigned char, ASInterfaceState)
143143
* re-parented multiple times, and each time will trigger this call.
144144
* @note This method is guaranteed to be called on main.
145145
*/
146-
- (void)didExitHierarchy;
146+
- (void)didExitHierarchy NS_SWIFT_UI_ACTOR;
147147

148148
@end

Source/ASDisplayNode+Subclasses.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ NS_ASSUME_NONNULL_BEGIN
7171
* @discussion This is the best time to add gesture recognizers to the view.
7272
*/
7373
AS_CATEGORY_IMPLEMENTABLE
74-
- (void)didLoad ASDISPLAYNODE_REQUIRES_SUPER;
74+
- (void)didLoad ASDISPLAYNODE_REQUIRES_SUPER NS_SWIFT_UI_ACTOR;
7575

7676
/**
7777
* An empty method that you can implement in a category to add global
@@ -95,7 +95,7 @@ AS_CATEGORY_IMPLEMENTABLE
9595
*
9696
* @discussion Subclasses override this method to layout all subnodes or subviews.
9797
*/
98-
- (void)layout ASDISPLAYNODE_REQUIRES_SUPER;
98+
- (void)layout ASDISPLAYNODE_REQUIRES_SUPER NS_SWIFT_UI_ACTOR;
9999

100100
/**
101101
* @abstract Called on the main thread by the view's -layoutSubviews, after -layout.
@@ -104,7 +104,7 @@ AS_CATEGORY_IMPLEMENTABLE
104104
* out.
105105
*/
106106
AS_CATEGORY_IMPLEMENTABLE
107-
- (void)layoutDidFinish ASDISPLAYNODE_REQUIRES_SUPER;
107+
- (void)layoutDidFinish ASDISPLAYNODE_REQUIRES_SUPER NS_SWIFT_UI_ACTOR;
108108

109109
/**
110110
* @abstract Called on a background thread if !isNodeLoaded - called on the main thread if isNodeLoaded.
@@ -255,7 +255,7 @@ AS_CATEGORY_IMPLEMENTABLE
255255
*
256256
* @note Called on the main thread only
257257
*/
258-
- (nullable id<NSObject>)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer;
258+
- (nullable id<NSObject>)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer NS_SWIFT_UI_ACTOR;
259259

260260
/**
261261
* @abstract Indicates that the receiver is about to display.
@@ -317,7 +317,7 @@ AS_CATEGORY_IMPLEMENTABLE
317317
* @discussion Called by -recursivelyClearContents. Always called on main thread. Base class implements self.contents = nil, clearing any backing
318318
* store, for asynchronous regeneration when needed.
319319
*/
320-
- (void)clearContents ASDISPLAYNODE_REQUIRES_SUPER;
320+
- (void)clearContents ASDISPLAYNODE_REQUIRES_SUPER NS_SWIFT_UI_ACTOR;
321321

322322
/**
323323
* @abstract Indicates that the receiver is about to display its subnodes. This method is not called if there are no

0 commit comments

Comments
 (0)