Fixed root view background color propagation

This commit is contained in:
Nick Lockwood
2015-05-26 04:14:31 -07:00
parent 81401064e5
commit b7c669aa73
7 changed files with 85 additions and 47 deletions

View File

@@ -48,10 +48,11 @@
RCTBridge *_bridge;
NSString *_moduleName;
NSDictionary *_launchOptions;
UIColor *_backgroundColor;
RCTRootContentView *_contentView;
}
- (instancetype)initWithBridge:(RCTBridge *)bridge
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
{
RCTAssertMainThread();
@@ -87,6 +88,17 @@
return [self initWithBridge:bridge moduleName:moduleName];
}
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
_backgroundColor = backgroundColor;
_contentView.backgroundColor = backgroundColor;
}
- (UIColor *)backgroundColor
{
return _backgroundColor;
}
- (UIViewController *)backingViewController
{
return _backingViewController ?: [super backingViewController];
@@ -100,7 +112,6 @@
RCT_IMPORT_METHOD(AppRegistry, runApplication)
RCT_IMPORT_METHOD(ReactNative, unmountComponentAtNodeAndRemoveContainer)
- (void)javaScriptDidLoad:(NSNotification *)notification
{
RCTBridge *bridge = notification.userInfo[@"bridge"];
@@ -124,6 +135,7 @@ RCT_IMPORT_METHOD(ReactNative, unmountComponentAtNodeAndRemoveContainer)
[_contentView removeFromSuperview];
_contentView = [[RCTRootContentView alloc] initWithFrame:self.bounds
bridge:bridge];
_contentView.backgroundColor = _backgroundColor;
[self addSubview:_contentView];
NSString *moduleName = _moduleName ?: @"";
@@ -187,9 +199,17 @@ RCT_IMPORT_METHOD(ReactNative, unmountComponentAtNodeAndRemoveContainer)
- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
super.frame = frame;
if (self.reactTag && _bridge.isValid) {
[_bridge.uiManager setFrame:self.bounds forRootView:self];
[_bridge.uiManager setFrame:frame forRootView:self];
}
}
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
super.backgroundColor = backgroundColor;
if (self.reactTag && _bridge.isValid) {
[_bridge.uiManager setBackgroundColor:backgroundColor forRootView:self];
}
}