Props setter for RCTRootView

Reviewed By: javache

Differential Revision: D2587673

fb-gh-sync-id: 79fff15b625ed9f4856ec75246ecafd1f7ef95f1
This commit is contained in:
Pawel Sienkowski 2015-10-30 09:26:22 -07:00 committed by facebook-github-bot-4
parent f96c92d75c
commit db71dde10a
2 changed files with 41 additions and 2 deletions

View File

@ -75,10 +75,21 @@ extern NSString *const RCTContentDidAppearNotification;
@property (nonatomic, strong, readonly) RCTBridge *bridge; @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 * The default properties to apply to the view when the script bundle
* is first loaded. Defaults to nil/empty. * 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. * The class of the RCTJavaScriptExecutor to use with this view.

View File

@ -54,6 +54,7 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat
RCTBridge *_bridge; RCTBridge *_bridge;
NSString *_moduleName; NSString *_moduleName;
NSDictionary *_launchOptions; NSDictionary *_launchOptions;
NSDictionary *_initialProperties;
RCTRootContentView *_contentView; RCTRootContentView *_contentView;
} }
@ -72,6 +73,7 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat
_bridge = bridge; _bridge = bridge;
_moduleName = moduleName; _moduleName = moduleName;
_initialProperties = [initialProperties copy]; _initialProperties = [initialProperties copy];
_appProperties = [initialProperties copy];
_loadingViewFadeDelay = 0.25; _loadingViewFadeDelay = 0.25;
_loadingViewFadeDuration = 0.25; _loadingViewFadeDuration = 0.25;
_sizeFlexibility = RCTRootViewSizeFlexibilityNone; _sizeFlexibility = RCTRootViewSizeFlexibilityNone;
@ -182,10 +184,15 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
_contentView.backgroundColor = self.backgroundColor; _contentView.backgroundColor = self.backgroundColor;
[self insertSubview:_contentView atIndex:0]; [self insertSubview:_contentView atIndex:0];
[self runApplication:bridge];
}
- (void)runApplication:(RCTBridge *)bridge
{
NSString *moduleName = _moduleName ?: @""; NSString *moduleName = _moduleName ?: @"";
NSDictionary *appParameters = @{ NSDictionary *appParameters = @{
@"rootTag": _contentView.reactTag, @"rootTag": _contentView.reactTag,
@"initialProps": _initialProperties ?: @{}, @"initialProps": _appProperties ?: @{},
}; };
[bridge enqueueJSCall:@"AppRegistry.runApplication" [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 - (void)setIntrinsicSize:(CGSize)intrinsicSize
{ {
if (!CGSizeEqualToSize(_intrinsicSize, intrinsicSize)) { if (!CGSizeEqualToSize(_intrinsicSize, intrinsicSize)) {