From 24e46673f599b4253ba18abb0d3845ef3c5f737c 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. [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 --- packages/react-native/React/CoreModules/RCTDeviceInfo.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm index 40e2b406053180..56ede49f71e6e9 100644 --- a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm +++ b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm @@ -98,6 +98,9 @@ - (void)initialize - (void)invalidate { + if (_invalidated) { + return; + } _invalidated = YES; [self _cleanupObservers]; } @@ -118,10 +121,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()