Skip to content

Commit

Permalink
[Hotfix] Pick up RCTDeviceInfo fix from upstream (#2130)
Browse files Browse the repository at this point in the history
## Summary:

Pick up
facebook@d46d80d
and
facebook@44159e3
from upstream to fix a potential hang we're seeing internally

## Test Plan:

CI should pass
  • Loading branch information
Saadnajmi authored May 25, 2024
2 parents 2954e4f + 2c7a514 commit 2e9c485
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ - (void)windowScene:(UIWindowScene *)windowScene
interfaceOrientation:(UIInterfaceOrientation)previousInterfaceOrientation
traitCollection:(UITraitCollection *)previousTraitCollection API_AVAILABLE(ios(13.0))
{
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRootViewFrameDidChangeNotification object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:RCTWindowFrameDidChangeNotification object:self];
}
#endif // [macOS]

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/Base/RCTConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollec
RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotificationAppearanceKey;
#endif // macOS]

RCT_EXTERN NSString *const RCTRootViewFrameDidChangeNotification;
RCT_EXTERN NSString *const RCTWindowFrameDidChangeNotification;

/**
* This notification fires when the bridge initializes.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/Base/RCTConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
NSString *const RCTUserInterfaceStyleDidChangeNotificationAppearanceKey = @"appearance";
#endif // macOS]

NSString *const RCTRootViewFrameDidChangeNotification = @"RCTRootViewFrameDidChangeNotification";
NSString *const RCTWindowFrameDidChangeNotification = @"RCTWindowFrameDidChangeNotification";

NSString *const RCTJavaScriptDidFailToLoadNotification = @"RCTJavaScriptDidFailToLoadNotification";
NSString *const RCTJavaScriptDidLoadNotification = @"RCTJavaScriptDidLoadNotification";
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/Base/RCTRootContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ - (void)viewDidMoveToWindow

- (void)sendFrameChangedEvent:(__unused NSNotification *)notification
{
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRootViewFrameDidChangeNotification object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:RCTWindowFrameDidChangeNotification object:self];
}

#endif // macOS]
Expand Down
37 changes: 36 additions & 1 deletion packages/react-native/React/CoreModules/RCTDeviceInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,48 @@ - (void)initialize

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(interfaceFrameDidChange)
name:RCTRootViewFrameDidChangeNotification
name:RCTWindowFrameDidChangeNotification
object:nil];

// TODO T175901725 - Registering the RCTDeviceInfo module to the notification is a short-term fix to unblock 0.73
// The actual behavior should be that the module is properly registered in the TurboModule/Bridge infrastructure
// and the infrastructure imperatively invoke the `invalidate` method, rather than listening to a notification.
// This is a temporary workaround until we can investigate the issue better as there might be other modules in a
// similar situation.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(invalidate)
name:RCTBridgeWillInvalidateModulesNotification
object:nil];
}

- (void)invalidate
{
if (_invalidated) {
return;
}
_invalidated = YES;
[self _cleanupObservers];
}

- (void)_cleanupObservers
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
object:[_moduleRegistry moduleForName:"AccessibilityManager"]];

#if TARGET_OS_IOS // [macOS] [visionOS]
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
#endif // [macOS] [visionOS]

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTUserInterfaceStyleDidChangeNotification object:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTWindowFrameDidChangeNotification object:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTBridgeWillInvalidateModulesNotification object:nil];
}

static BOOL RCTIsIPhoneNotched()
Expand Down

0 comments on commit 2e9c485

Please sign in to comment.