mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Fixed root view background color propagation
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user