From b7f50621286d00dc04f485061195413b6d484725 Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Mon, 16 Nov 2015 09:16:25 -0800 Subject: [PATCH] Fixed nil insert crash in shadowViewRegistry Summary: public In iOS < 9, inserting a nil object into NSMutableDictionary crashes. It is valid for come components to return a nil shadowView (e.g. ART nodes), and this was crashing on iOS 8. Reviewed By: jspahrsummers Differential Revision: D2658309 fb-gh-sync-id: 7abf9273708cc03c3b6307b69ba11c016b471fbe --- React/Modules/RCTUIManager.m | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 78767a95b..576f70db9 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -795,8 +795,10 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag // Register shadow view RCTShadowView *shadowView = [componentData createShadowViewWithTag:reactTag]; - [componentData setProps:props forShadowView:shadowView]; - _shadowViewRegistry[reactTag] = shadowView; + if (shadowView) { + [componentData setProps:props forShadowView:shadowView]; + _shadowViewRegistry[reactTag] = shadowView; + } // Shadow view is the source of truth for background color this is a little // bit counter-intuitive if people try to set background color when setting up @@ -805,14 +807,16 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag [self addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = [componentData createViewWithTag:reactTag props:props]; - if ([view respondsToSelector:@selector(setBackgroundColor:)]) { - ((UIView *)view).backgroundColor = backgroundColor; + if (view) { + if ([view respondsToSelector:@selector(setBackgroundColor:)]) { + ((UIView *)view).backgroundColor = backgroundColor; + } + [componentData setProps:props forView:view]; + if ([view respondsToSelector:@selector(reactBridgeDidFinishTransaction)]) { + [uiManager->_bridgeTransactionListeners addObject:view]; + } + ((NSMutableDictionary *)viewRegistry)[reactTag] = view; } - [componentData setProps:props forView:view]; - if ([view respondsToSelector:@selector(reactBridgeDidFinishTransaction)]) { - [uiManager->_bridgeTransactionListeners addObject:view]; - } - ((NSMutableDictionary *)viewRegistry)[reactTag] = view; }]; }