Skip to content

Commit d37c3ff

Browse files
authored
Remove methodQueue with RCTGetUIManagerQueue (software-mansion#7156)
## Summary ⚠️ This is potentially a very breaking change in some setups! This PR removes `methodQueue` method in `REAModule` that was responsible for marking that native methods of Reanimated module should be initialized on the UIManager queue. As stated in the comment, `REAModule` methods needed to be executed on the same queue as the `UIManager` to avoid having to lock `_operations` and `_preOperations` since `uiManagerWillPerformMounting` will be called from that queue. Since `_operations` and `_preOperations` have been removed, we can finally get rid of `methodQueue` as well. After this change, invalidation methods will be called on the TurboModuleManager queue instead of the UIManager queue. Looks like this is a perfect moment to get rid of this chunk of the code and hopefully it should work just fine. Please let us know immediately if you have any troubles with running Reanimated without `methodQueue`. ## Test plan
1 parent 2b669b0 commit d37c3ff

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#import <react/debug/react_native_assert.h>
2+
3+
constexpr auto turboModuleManagerQueueLabel =
4+
"com.meta.react.turbomodulemanager.queue";
5+
6+
static bool REAIsTurboModuleManagerQueue() {
7+
const auto currentQueueLabel =
8+
dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
9+
return strcmp(currentQueueLabel, turboModuleManagerQueueLabel) == 0;
10+
}
11+
12+
static void REAAssertTurboModuleManagerQueue() {
13+
react_native_assert(
14+
REAIsTurboModuleManagerQueue() &&
15+
"This function must be called on the TurboModuleManager queue");
16+
}

packages/react-native-reanimated/apple/reanimated/apple/REAModule.mm

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#import <React/RCTCallInvoker.h>
22
#import <React/RCTScheduler.h>
33
#import <React/RCTSurfacePresenter.h>
4-
#import <React/RCTUIManagerUtils.h>
54

65
#import <reanimated/RuntimeDecorators/RNRuntimeDecorator.h>
76
#import <reanimated/apple/REAAssertJavaScriptQueue.h>
7+
#import <reanimated/apple/REAAssertTurboModuleManagerQueue.h>
88
#import <reanimated/apple/REAModule.h>
99
#import <reanimated/apple/REANodesManager.h>
1010
#import <reanimated/apple/native/NativeProxy.h>
@@ -35,23 +35,13 @@ @implementation REAModule {
3535

3636
- (void)invalidate
3737
{
38-
RCTAssertUIManagerQueue();
38+
REAAssertTurboModuleManagerQueue();
3939

4040
[[NSNotificationCenter defaultCenter] removeObserver:self];
4141
[_nodesManager invalidate];
4242
[super invalidate];
4343
}
4444

45-
- (dispatch_queue_t)methodQueue
46-
{
47-
REAAssertJavaScriptQueue();
48-
49-
// This module needs to be on the same queue as the UIManager to avoid
50-
// having to lock `_operations` and `_preOperations` since `uiManagerWillPerformMounting`
51-
// will be called from that queue.
52-
return RCTGetUIManagerQueue();
53-
}
54-
5545
- (std::shared_ptr<UIManager>)getUIManager
5646
{
5747
REAAssertJavaScriptQueue();

packages/react-native-reanimated/apple/reanimated/apple/REANodesManager.mm

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#import <reanimated/apple/REAAssertJavaScriptQueue.h>
2+
#import <reanimated/apple/REAAssertTurboModuleManagerQueue.h>
23
#import <reanimated/apple/REANodesManager.h>
34

4-
#import <React/RCTUIManagerUtils.h>
55
#import <React/RCTUtils.h>
66

77
@implementation REANodesManager {
@@ -28,7 +28,7 @@ - (READisplayLink *)getDisplayLink
2828
- (void)useDisplayLinkOnMainQueue:(CADisplayLinkOperation)displayLinkOperation
2929
{
3030
// This method is called on the JavaScript queue during initialization or on the ShadowQueue during invalidation.
31-
react_native_assert(REAIsJavaScriptQueue() || RCTIsUIManagerQueue());
31+
react_native_assert(REAIsJavaScriptQueue() || REAIsTurboModuleManagerQueue());
3232

3333
__weak __typeof__(self) weakSelf = self;
3434
RCTExecuteOnMainQueue(^{
@@ -62,7 +62,8 @@ - (nonnull instancetype)initWithModule:(REAModule *)reanimatedModule
6262

6363
- (void)invalidate
6464
{
65-
RCTAssertUIManagerQueue();
65+
REAAssertTurboModuleManagerQueue();
66+
6667
_eventHandler = nil;
6768
[self useDisplayLinkOnMainQueue:^(READisplayLink *displayLink) {
6869
[displayLink invalidate];

0 commit comments

Comments
 (0)