Skip to content

Commit

Permalink
Props setter for RCTRootView
Browse files Browse the repository at this point in the history
Reviewed By: javache

Differential Revision: D2587673

fb-gh-sync-id: 79fff15b625ed9f4856ec75246ecafd1f7ef95f1
  • Loading branch information
Pawel Sienkowski authored and facebook-github-bot-4 committed Oct 30, 2015
1 parent f96c92d commit db71dde
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
13 changes: 12 additions & 1 deletion React/Base/RCTRootView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 29 additions & 1 deletion React/Base/RCTRootView.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ @implementation RCTRootView
RCTBridge *_bridge;
NSString *_moduleName;
NSDictionary *_launchOptions;
NSDictionary *_initialProperties;
RCTRootContentView *_contentView;
}

Expand All @@ -72,6 +73,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
_bridge = bridge;
_moduleName = moduleName;
_initialProperties = [initialProperties copy];
_appProperties = [initialProperties copy];
_loadingViewFadeDelay = 0.25;
_loadingViewFadeDuration = 0.25;
_sizeFlexibility = RCTRootViewSizeFlexibilityNone;
Expand Down Expand Up @@ -182,10 +184,15 @@ - (void)bundleFinishedLoading:(RCTBridge *)bridge
_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"
Expand All @@ -208,6 +215,27 @@ - (void)layoutSubviews
};
}

- (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)) {
Expand Down

0 comments on commit db71dde

Please sign in to comment.