diff --git a/Libraries/Components/WKWebView/WKWebView.android.js b/Libraries/Components/WKWebView/WKWebView.android.js new file mode 100644 index 000000000..a4cab3123 --- /dev/null +++ b/Libraries/Components/WKWebView/WKWebView.android.js @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + * @providesModule WKWebView + */ + +const React = require('React'); +const View = require('View'); +const Text = require('Text'); + +module.exports = () => { + return ( + + Android version not implemented. + + ); +}; diff --git a/Libraries/Components/WKWebView/WKWebView.ios.js b/Libraries/Components/WKWebView/WKWebView.ios.js new file mode 100644 index 000000000..d1af14bfe --- /dev/null +++ b/Libraries/Components/WKWebView/WKWebView.ios.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + * @providesModule WKWebView + */ + +const requireNativeComponent = require('requireNativeComponent'); + +module.exports = requireNativeComponent('RCTWKWebView'); diff --git a/React/Views/RCTWKWebView.h b/React/Views/RCTWKWebView.h new file mode 100644 index 000000000..7e985f68e --- /dev/null +++ b/React/Views/RCTWKWebView.h @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import + +@class RCTWKWebView; + +@protocol RCTWKWebViewDelegate +@end + +@interface RCTWKWebView : RCTView + +@property (nonatomic, weak) id delegate; +@property (nonatomic, copy) NSDictionary *source; + +@end diff --git a/React/Views/RCTWKWebView.m b/React/Views/RCTWKWebView.m new file mode 100644 index 000000000..98cdf290b --- /dev/null +++ b/React/Views/RCTWKWebView.m @@ -0,0 +1,72 @@ +#import "RCTWKWebView.h" + +#import + +#import + +#import "RCTAutoInsetsProtocol.h" + +@interface RCTWKWebView () +@end + +@implementation RCTWKWebView +{ + WKWebView *_webView; +} + +- (void)dealloc +{ + +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + if ((self = [super initWithFrame:frame])) { + super.backgroundColor = [UIColor clearColor]; + _webView = [[WKWebView alloc] initWithFrame:self.bounds]; + _webView.UIDelegate = self; + [self addSubview:_webView]; + } + return self; +} + +- (void)setSource:(NSDictionary *)source +{ + if (![_source isEqualToDictionary:source]) { + _source = [source copy]; + + // Check for a static html source first + NSString *html = [RCTConvert NSString:source[@"html"]]; + if (html) { + NSURL *baseURL = [RCTConvert NSURL:source[@"baseUrl"]]; + if (!baseURL) { + baseURL = [NSURL URLWithString:@"about:blank"]; + } + [_webView loadHTMLString:html baseURL:baseURL]; + return; + } + + NSURLRequest *request = [RCTConvert NSURLRequest:source]; + // Because of the way React works, as pages redirect, we actually end up + // passing the redirect urls back here, so we ignore them if trying to load + // the same url. We'll expose a call to 'reload' to allow a user to load + // the existing page. + if ([request.URL isEqual:_webView.URL]) { + return; + } + if (!request.URL) { + // Clear the webview + [_webView loadHTMLString:@"" baseURL:nil]; + return; + } + [_webView loadRequest:request]; + } +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + _webView.frame = self.bounds; +} + +@end diff --git a/React/Views/RCTWKWebViewManager.m b/React/Views/RCTWKWebViewManager.m new file mode 100644 index 000000000..e16bbe723 --- /dev/null +++ b/React/Views/RCTWKWebViewManager.m @@ -0,0 +1,18 @@ +#import "RCTViewManager.h" +#import "RCTWKWebView.h" + +@interface RCTWKWebViewManager : RCTViewManager +@end + +@implementation RCTWKWebViewManager + +RCT_EXPORT_MODULE() + +- (UIView *)view +{ + return [RCTWKWebView new]; +} + +RCT_EXPORT_VIEW_PROPERTY(source, NSDictionary) + +@end