Skip to content

Commit

Permalink
Remove invalidate observer instead of re-adding observer in DeviceInf…
Browse files Browse the repository at this point in the history
…o module (#43737)

Summary:
Previous fix brings in #42396. Seems it's a mistake to re-add observer?
So let's remove it and also not `invalidate` method not be called twice.

## Changelog:

[IOS] [FIXED] - Remove invalidate observer instead of re-adding observer in DeviceInfo module

Pull Request resolved: #43737

Test Plan: Fix for #42120 also works.

Reviewed By: javache

Differential Revision: D55692219

Pulled By: cipolleschi

fbshipit-source-id: dba1ddc39a9f2611fc2b84fadf8c23827891379a
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Apr 4, 2024
1 parent 629159a commit 91279a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Expand Up @@ -151,7 +151,7 @@ typedef BOOL (^RCTBridgeDidNotFindModuleBlock)(RCTBridge *bridge, NSString *modu
*
* @parameter: moduleName - the name of the app, used by Metro to resolve the module.
* @parameter: initialProperties - a set of initial properties.
* @parameter: moduleName - a dictionary with a set of options.
* @parameter: launchOptions - a dictionary with a set of options.
*/
- (UIView *_Nonnull)viewWithModuleName:(NSString *)moduleName
initialProperties:(NSDictionary *__nullable)initialProperties
Expand Down
8 changes: 4 additions & 4 deletions packages/react-native/React/CoreModules/RCTDeviceInfo.mm
Expand Up @@ -89,6 +89,9 @@ - (void)initialize

- (void)invalidate
{
if (_invalidated) {
return;
}
_invalidated = YES;
[self _cleanupObservers];
}
Expand All @@ -109,10 +112,7 @@ - (void)_cleanupObservers

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

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(invalidate)
name:RCTBridgeWillInvalidateModulesNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTBridgeWillInvalidateModulesNotification object:nil];
}

static BOOL RCTIsIPhoneNotched()
Expand Down

0 comments on commit 91279a8

Please sign in to comment.