From bb141e3a3c14d45e56fd897499b8aad1a1e7d814 Mon Sep 17 00:00:00 2001 From: Hedger Wang Date: Tue, 7 Jul 2015 17:07:52 -0700 Subject: [PATCH] Rename prop "injectedJavascriptIOS" to "injectedJavaScript Summary: Android WebView now supports the prop "injectedJavaScript", too. It's time to rename "injectedJavascriptIOS" to "injectedJavaScript" for API consistency between IOS and Android. --- .../Components/WebView/WebView.android.js | 10 +++++++++- Libraries/Components/WebView/WebView.ios.js | 14 +++++++------- React/Views/RCTWebView.h | 2 +- React/Views/RCTWebView.m | 19 +++---------------- React/Views/RCTWebViewManager.m | 2 +- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/Libraries/Components/WebView/WebView.android.js b/Libraries/Components/WebView/WebView.android.js index 872e2b3bd..b525c44f3 100644 --- a/Libraries/Components/WebView/WebView.android.js +++ b/Libraries/Components/WebView/WebView.android.js @@ -43,6 +43,12 @@ var WebView = React.createClass({ startInLoadingState: PropTypes.bool, // force WebView to show loadingView on first load style: View.propTypes.style, javaScriptEnabledAndroid: PropTypes.bool, + + /** + * Sets the JS to be injected when the webpage loads. + */ + injectedJavaScript: PropTypes.string, + /** * Sets the user-agent for this WebView. The user-agent can also be set in native through * WebViewConfig, but this can and will overwrite that config. @@ -96,6 +102,7 @@ var WebView = React.createClass({ key="webViewKey" style={webViewStyles} url={this.props.url} + injectedJavaScript={this.props.injectedJavaScript} userAgent={this.props.userAgent} javaScriptEnabledAndroid={this.props.javaScriptEnabledAndroid} contentInset={this.props.contentInset} @@ -176,8 +183,9 @@ var WebView = React.createClass({ var RCTWebView = createReactNativeComponentClass({ validAttributes: merge(ReactNativeViewAttributes.UIView, { - url: true, + injectedJavaScript: true, javaScriptEnabledAndroid: true, + url: true, userAgent: true, }), uiViewClassName: 'RCTWebView', diff --git a/Libraries/Components/WebView/WebView.ios.js b/Libraries/Components/WebView/WebView.ios.js index 83b1c26f6..3308842a2 100644 --- a/Libraries/Components/WebView/WebView.ios.js +++ b/Libraries/Components/WebView/WebView.ios.js @@ -98,9 +98,9 @@ var WebView = React.createClass({ */ javaScriptEnabledAndroid: PropTypes.bool, /** - * Used for iOS only, sets the JS to be injected when the webpage loads. + * Sets the JS to be injected when the webpage loads. */ - injectedJavascriptIOS: PropTypes.string, + injectedJavaScript: PropTypes.string, /** * Used for iOS only, sets whether the webpage scales to fit the view and the @@ -159,7 +159,7 @@ var WebView = React.createClass({ style={webViewStyles} url={this.props.url} html={this.props.html} - injectedJavascriptIOS={this.props.injectedJavascriptIOS} + injectedJavaScript={this.props.injectedJavaScript} bounces={this.props.bounces} scrollEnabled={this.props.scrollEnabled} contentInset={this.props.contentInset} @@ -179,15 +179,15 @@ var WebView = React.createClass({ }, goForward: function() { - RCTWebViewManager.goForward(this.getWebWiewHandle()); + RCTWebViewManager.goForward(this.getWebViewHandle()); }, goBack: function() { - RCTWebViewManager.goBack(this.getWebWiewHandle()); + RCTWebViewManager.goBack(this.getWebViewHandle()); }, reload: function() { - RCTWebViewManager.reload(this.getWebWiewHandle()); + RCTWebViewManager.reload(this.getWebViewHandle()); }, /** @@ -200,7 +200,7 @@ var WebView = React.createClass({ } }, - getWebWiewHandle: function(): any { + getWebViewHandle: function(): any { return React.findNodeHandle(this.refs[RCT_WEBVIEW_REF]); }, diff --git a/React/Views/RCTWebView.h b/React/Views/RCTWebView.h index 90846e349..270b04ec5 100644 --- a/React/Views/RCTWebView.h +++ b/React/Views/RCTWebView.h @@ -18,7 +18,7 @@ extern NSString *const RCTJSNavigationScheme; @property (nonatomic, strong) NSURL *URL; @property (nonatomic, assign) UIEdgeInsets contentInset; @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets; -@property (nonatomic, copy) NSString *injectedJavascriptIOS; +@property (nonatomic, copy) NSString *injectedJavaScript; - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER; diff --git a/React/Views/RCTWebView.m b/React/Views/RCTWebView.m index 693f00eaa..d22ca43fc 100644 --- a/React/Views/RCTWebView.m +++ b/React/Views/RCTWebView.m @@ -33,7 +33,7 @@ NSString *const RCTJSNavigationScheme = @"react-js-navigation"; { RCTEventDispatcher *_eventDispatcher; UIWebView *_webView; - NSString *_injectedJavascriptIOS; + NSString *_injectedJavaScript; } - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher @@ -126,19 +126,6 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder) return _webView.backgroundColor; } -- (void)setinjectedJavascriptIOS:(NSString *)jsStr -{ - if (_injectedJavascriptIOS == jsStr) { - return; - } - - if ([_injectedJavascriptIOS isEqualToString:jsStr]) { - return; - } - - _injectedJavascriptIOS = [jsStr copy]; -} - - (NSMutableDictionary *)baseEvent { NSURL *url = _webView.request.URL; @@ -197,8 +184,8 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder) - (void)webViewDidFinishLoad:(UIWebView *)webView { - if (_injectedJavascriptIOS != nil) { - [webView stringByEvaluatingJavaScriptFromString:_injectedJavascriptIOS]; + if (_injectedJavaScript != nil) { + [webView stringByEvaluatingJavaScriptFromString:_injectedJavaScript]; } // we only need the final 'finishLoad' call so only fire the event when we're actually done loading. diff --git a/React/Views/RCTWebViewManager.m b/React/Views/RCTWebViewManager.m index ff5fcf26a..fd69f667e 100644 --- a/React/Views/RCTWebViewManager.m +++ b/React/Views/RCTWebViewManager.m @@ -28,7 +28,7 @@ RCT_REMAP_VIEW_PROPERTY(html, HTML, NSString); RCT_REMAP_VIEW_PROPERTY(bounces, _webView.scrollView.bounces, BOOL); RCT_REMAP_VIEW_PROPERTY(scrollEnabled, _webView.scrollView.scrollEnabled, BOOL); RCT_REMAP_VIEW_PROPERTY(scalesPageToFit, _webView.scalesPageToFit, BOOL); -RCT_EXPORT_VIEW_PROPERTY(injectedJavascriptIOS, NSString); +RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString); RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets); RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL);