Skip to content

Commit

Permalink
Honor requiresMainQueueSetup in bridgeless mode for ViewManagers
Browse files Browse the repository at this point in the history
Summary:
We [received an issue](react-native-maps/react-native-maps#5042) in OSS where a ViewManager was configured to be initialized on the main queue, but it wasn't.
This was creating a soft crash and showing a RedBox to the user.
The library was going through the Interop Layer.

This change makes sure that, if the ViewManager is configured to be setup in the main queue, we retrieve the constants from the Main Queue

## Changelog
[iOS][Fixed] - Extract the constants from ViewManagers in the UI Thread if needed.

Reviewed By: sammy-SC

Differential Revision: D56762253

fbshipit-source-id: ca807b34d6e61418da9fd6a639a05f3394879f7c
  • Loading branch information
cipolleschi committed May 1, 2024
1 parent 1373951 commit 8813061
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/react-native/React/Views/RCTComponentData.m
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,20 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forView:(id<RCTComponent>
+ (NSDictionary<NSString *, id> *)constantsForViewMangerClass:(Class)managerClass
{
if ([managerClass instancesRespondToSelector:@selector(constantsToExport)]) {
return [[managerClass new] constantsToExport];
BOOL shouldRunOnMainThread = NO;

if ([managerClass respondsToSelector:@selector(requiresMainQueueSetup)]) {
shouldRunOnMainThread = [managerClass requiresMainQueueSetup];
}
if (shouldRunOnMainThread) {
__block NSDictionary<NSString *, id> *constants;
RCTUnsafeExecuteOnMainQueueSync(^{
constants = [[managerClass new] constantsToExport];
});
return constants;
} else {
return [[managerClass new] constantsToExport];
}
}
return @{};
}
Expand Down

0 comments on commit 8813061

Please sign in to comment.