From 91279a822be949051866a694148e509c1308035b Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 4 Apr 2024 07:33:10 -0700 Subject: [PATCH] Remove invalidate observer instead of re-adding observer in DeviceInfo module (#43737) Summary: Previous fix brings in https://github.com/facebook/react-native/pull/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: https://github.com/facebook/react-native/pull/43737 Test Plan: Fix for https://github.com/facebook/react-native/issues/42120 also works. Reviewed By: javache Differential Revision: D55692219 Pulled By: cipolleschi fbshipit-source-id: dba1ddc39a9f2611fc2b84fadf8c23827891379a --- .../Libraries/AppDelegate/RCTRootViewFactory.h | 2 +- packages/react-native/React/CoreModules/RCTDeviceInfo.mm | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h index 85c99421287184..21533feaad9dfc 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h @@ -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 diff --git a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm index bfb49700825841..f4c664014609c4 100644 --- a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm +++ b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm @@ -89,6 +89,9 @@ - (void)initialize - (void)invalidate { + if (_invalidated) { + return; + } _invalidated = YES; [self _cleanupObservers]; } @@ -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()