diff --git a/React/Views/RCTWKWebView.m b/React/Views/RCTWKWebView.m index 8cb16175f13..0a55fdccd6c 100644 --- a/React/Views/RCTWKWebView.m +++ b/React/Views/RCTWKWebView.m @@ -15,6 +15,7 @@ static NSString *const MessageHanderName = @"ReactNative"; @implementation RCTWKWebView { + UIColor * _savedBackgroundColor; } - (void)dealloc @@ -56,6 +57,19 @@ static NSString *const MessageHanderName = @"ReactNative"; } } +- (void)setBackgroundColor:(UIColor *)backgroundColor +{ + _savedBackgroundColor = backgroundColor; + if (_webView == nil) { + return; + } + + CGFloat alpha = CGColorGetAlpha(backgroundColor.CGColor); + self.opaque = _webView.opaque = (alpha == 1.0); + _webView.scrollView.backgroundColor = backgroundColor; + _webView.backgroundColor = backgroundColor; +} + /** * This method is called whenever JavaScript running within the web view calls: * - window.webkit.messageHandlers.[MessageHanderName].postMessage @@ -236,6 +250,8 @@ static NSString *const MessageHanderName = @"ReactNative"; }]; _onLoadingError(event); } + + [self setBackgroundColor: _savedBackgroundColor]; } - (void)evaluateJS:(NSString *)js @@ -292,6 +308,8 @@ static NSString *const MessageHanderName = @"ReactNative"; } else if (_onLoadingFinish) { _onLoadingFinish([self baseEvent]); } + + [self setBackgroundColor: _savedBackgroundColor]; } - (void)injectJavaScript:(NSString *)script