From 65713992c4bfe783197147947e201b3f51db5fa6 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 17 Aug 2015 06:11:29 -0700 Subject: [PATCH] Let native modules know when root views get added and removed --- React/Modules/RCTUIManager.h | 17 +++++++++++++++++ React/Modules/RCTUIManager.m | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/React/Modules/RCTUIManager.h b/React/Modules/RCTUIManager.h index beb9e5d5a..d7d91c997 100644 --- a/React/Modules/RCTUIManager.h +++ b/React/Modules/RCTUIManager.h @@ -20,6 +20,23 @@ */ RCT_EXTERN NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification; +/** + * Posted whenever a new root view is registered with RCTUIManager. The userInfo property + * will contain a RCTUIManagerRootViewKey with the registered root view. + */ +RCT_EXTERN NSString *const RCTUIManagerDidRegisterRootViewNotification; + +/** + * Posted whenever a root view is removed from the RCTUIManager. The userInfo property + * will contain a RCTUIManagerRootViewKey with the removed root view. + */ +RCT_EXTERN NSString *const RCTUIManagerDidRemoveRootViewNotification; + +/** + * Key for the root view property in the above notifications + */ +RCT_EXTERN NSString *const RCTUIManagerRootViewKey; + @protocol RCTScrollableProtocol; /** diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 19d478284..d1a29d3a8 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -41,6 +41,9 @@ static void RCTTraverseViewNodes(id view, void (^block)(id_shadowViewRegistry[shadowView.reactTag] = shadowView; [strongSelf->_rootViewTags addObject:reactTag]; }); + + [[NSNotificationCenter defaultCenter] postNotificationName:RCTUIManagerDidRegisterRootViewNotification + object:self + userInfo:@{ RCTUIManagerRootViewKey: rootView }]; } - (UIView *)viewForReactTag:(NSNumber *)reactTag @@ -637,6 +644,10 @@ RCT_EXPORT_METHOD(removeRootView:(nonnull NSNumber *)rootReactTag) UIView *rootView = viewRegistry[rootReactTag]; [uiManager _purgeChildren:rootView.reactSubviews fromRegistry:viewRegistry]; viewRegistry[rootReactTag] = nil; + + [[NSNotificationCenter defaultCenter] postNotificationName:RCTUIManagerDidRemoveRootViewNotification + object:uiManager + userInfo:@{ RCTUIManagerRootViewKey: rootView }]; }]; }