Skip to content

Commit 329d5dc

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Register RCTDeviceInfo to invalidating and cleanup observer (facebook#42396)
Summary: Cmmunity reported [facebook#42120](facebook#42120) where React Native was crashing if RCTDeviceInfo native module was receiving a notification while the bridge is invalidating. Upon investigation, I realized that: 1. The RCTDeviceInfo module is never invalidated 2. Observers are still observing even when the Bridge is in an invalidated state and it is not back up. This change makes sure that we invalidate the `RCTDeviceInfo.mm` module and that we unregister the observers. ## Changelog: [iOS][Fixed] - Make `RCTDeviceInfo` listen to invalidate events and unregister observers while invalidating the bridge Differential Revision: D52912604
1 parent 2722f95 commit 329d5dc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/react-native/React/CoreModules/RCTDeviceInfo.mm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,39 @@ - (void)initialize
7575
selector:@selector(interfaceFrameDidChange)
7676
name:RCTWindowFrameDidChangeNotification
7777
object:nil];
78+
79+
[[NSNotificationCenter defaultCenter] addObserver:self
80+
selector:@selector(invalidate)
81+
name:RCTBridgeWillInvalidateModulesNotification
82+
object:nil];
7883
}
7984

8085
- (void)invalidate
8186
{
8287
_invalidated = YES;
88+
[self _cleanupObservers];
89+
}
90+
91+
- (void)_cleanupObservers
92+
{
93+
[[NSNotificationCenter defaultCenter] removeObserver:self
94+
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
95+
object:[_moduleRegistry moduleForName:"AccessibilityManager"]];
96+
97+
[[NSNotificationCenter defaultCenter] removeObserver:self
98+
name:UIApplicationDidChangeStatusBarOrientationNotification
99+
object:nil];
100+
101+
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
102+
103+
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTUserInterfaceStyleDidChangeNotification object:nil];
104+
105+
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTWindowFrameDidChangeNotification object:nil];
106+
107+
[[NSNotificationCenter defaultCenter] addObserver:self
108+
selector:@selector(invalidate)
109+
name:RCTBridgeWillInvalidateModulesNotification
110+
object:nil];
83111
}
84112

85113
static BOOL RCTIsIPhoneNotched()

0 commit comments

Comments
 (0)