Skip to content

Commit

Permalink
Fixes Appearance getColorScheme sync method UI thread issue (#46344)
Browse files Browse the repository at this point in the history
Summary:
If the module sets the method queue to the main queue, we should call it on the main queue if it contains some UI operations, otherwise it may lead to some undefined behavior.

## Changelog:

[IOS] [FIXED] - Fixes the exported synchronous method not being called on the method queue when it's the main queue

Pull Request resolved: #46344

Test Plan: The sync method should be called on the main queue if the module's method queue is main queue.

Reviewed By: cipolleschi

Differential Revision: D63532525

Pulled By: javache

fbshipit-source-id: 55baaa60af96bb1355d3641174f23bccd8eb9344
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Sep 27, 2024
1 parent 8237e23 commit 8bfd7e1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/react-native/React/CoreModules/RCTAppearance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ - (dispatch_queue_t)methodQueue
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, getColorScheme)
{
if (!sIsAppearancePreferenceSet) {
UITraitCollection *traitCollection = RCTKeyWindow().traitCollection;
__block UITraitCollection *traitCollection = nil;
RCTUnsafeExecuteOnMainQueueSync(^{
traitCollection = RCTKeyWindow().traitCollection;
});
_currentColorScheme = RCTColorSchemePreference(traitCollection);
}
return _currentColorScheme;
Expand Down

0 comments on commit 8bfd7e1

Please sign in to comment.