From cb8b656a82ad0105679f14b02cbec5fbeaea9cd3 Mon Sep 17 00:00:00 2001 From: James Ide Date: Thu, 8 Oct 2015 03:47:43 -0700 Subject: [PATCH] Only handle accessibility notifications from the correct RCTAccessibilityManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: When you reload and create a new bridge, one of the things that happens during setup is that the RCTAccessibilityManager fires a notification. The old bridge would receive this notification from the new bridge's RCTAccessibilityManager, which we don't want, especially because the two are running on different shadow queues. I believe this led to a gnarly crash in NSConcreteTextStorage because RCTMeasure in RCTShadowText.m was getting called for the old RCTText (getting destroyed) from a notification fired from the new shadow queue. The fix is for the UIManager to handle notifications only from its bridge's RCTAccessibilityManager. See #2001 for the kinds of crashes we were seeing. Closes https://github.com/facebook/react-native/pull/3279 Reviewed By: @​svcscm Differential Revision: D2521652 Pulled By: @nicklockwood fb-gh-sync-id: a4ffe3ef8304667727e573e2a2e8b716e1d2f3e1 --- React/Modules/RCTUIManager.m | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index f6e35dad4..574eebdc4 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -229,20 +229,10 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); _rootViewTags = [NSMutableSet new]; _bridgeTransactionListeners = [NSMutableSet new]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(didReceiveNewContentSizeMultiplier) - name:RCTAccessibilityManagerDidUpdateMultiplierNotification - object:nil]; } return self; } -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} - - (void)didReceiveNewContentSizeMultiplier { __weak RCTUIManager *weakSelf = self; @@ -276,6 +266,8 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); [_pendingUIBlocksLock lock]; _pendingUIBlocks = nil; [_pendingUIBlocksLock unlock]; + + [[NSNotificationCenter defaultCenter] removeObserver:self]; }); } @@ -296,6 +288,11 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); } _componentDataByName = [componentDataByName copy]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(didReceiveNewContentSizeMultiplier) + name:RCTAccessibilityManagerDidUpdateMultiplierNotification + object:_bridge.accessibilityManager]; } - (dispatch_queue_t)methodQueue