diff --git a/React/Base/RCTRootView.h b/React/Base/RCTRootView.h index 480663a5d..fdb7d6b9b 100644 --- a/React/Base/RCTRootView.h +++ b/React/Base/RCTRootView.h @@ -75,10 +75,21 @@ extern NSString *const RCTContentDidAppearNotification; @property (nonatomic, strong, readonly) RCTBridge *bridge; /** + * DEPRECATED: access app properties via appProperties property instead + * * The default properties to apply to the view when the script bundle * is first loaded. Defaults to nil/empty. */ -@property (nonatomic, copy, readonly) NSDictionary *initialProperties; +@property (nonatomic, copy, readonly) NSDictionary *initialProperties DEPRECATED_MSG_ATTRIBUTE ("use appProperties instead"); + +/** + * The properties to apply to the view. Use this property to update + * application properties and rerender the view. Initialized with + * initialProperties argument of the initializer. + * + * Set this property only on the main thread. + */ +@property (nonatomic, copy, readwrite) NSDictionary *appProperties; /** * The class of the RCTJavaScriptExecutor to use with this view. diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 6d8059158..90a3fed9c 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -54,6 +54,7 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat RCTBridge *_bridge; NSString *_moduleName; NSDictionary *_launchOptions; + NSDictionary *_initialProperties; RCTRootContentView *_contentView; } @@ -72,6 +73,7 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat _bridge = bridge; _moduleName = moduleName; _initialProperties = [initialProperties copy]; + _appProperties = [initialProperties copy]; _loadingViewFadeDelay = 0.25; _loadingViewFadeDuration = 0.25; _sizeFlexibility = RCTRootViewSizeFlexibilityNone; @@ -182,10 +184,15 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) _contentView.backgroundColor = self.backgroundColor; [self insertSubview:_contentView atIndex:0]; + [self runApplication:bridge]; +} + +- (void)runApplication:(RCTBridge *)bridge +{ NSString *moduleName = _moduleName ?: @""; NSDictionary *appParameters = @{ @"rootTag": _contentView.reactTag, - @"initialProps": _initialProperties ?: @{}, + @"initialProps": _appProperties ?: @{}, }; [bridge enqueueJSCall:@"AppRegistry.runApplication" @@ -208,6 +215,27 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) }; } +- (NSDictionary *)initialProperties +{ + RCTLogWarn(@"Using deprecated 'initialProperties' property. Use 'appProperties' instead."); + return _initialProperties; +} + +- (void)setAppProperties:(NSDictionary *)appProperties +{ + RCTAssertMainThread(); + + if ([_appProperties isEqualToDictionary:appProperties]) { + return; + } + + _appProperties = [appProperties copy]; + + if (_bridge.valid && !_bridge.loading) { + [self runApplication:_bridge.batchedBridge]; + } +} + - (void)setIntrinsicSize:(CGSize)intrinsicSize { if (!CGSizeEqualToSize(_intrinsicSize, intrinsicSize)) {