Skip to content

Commit bb141e3

Browse files
author
Hedger Wang
committed
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.
1 parent 1b7699f commit bb141e3

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

Libraries/Components/WebView/WebView.android.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ var WebView = React.createClass({
4343
startInLoadingState: PropTypes.bool, // force WebView to show loadingView on first load
4444
style: View.propTypes.style,
4545
javaScriptEnabledAndroid: PropTypes.bool,
46+
47+
/**
48+
* Sets the JS to be injected when the webpage loads.
49+
*/
50+
injectedJavaScript: PropTypes.string,
51+
4652
/**
4753
* Sets the user-agent for this WebView. The user-agent can also be set in native through
4854
* WebViewConfig, but this can and will overwrite that config.
@@ -96,6 +102,7 @@ var WebView = React.createClass({
96102
key="webViewKey"
97103
style={webViewStyles}
98104
url={this.props.url}
105+
injectedJavaScript={this.props.injectedJavaScript}
99106
userAgent={this.props.userAgent}
100107
javaScriptEnabledAndroid={this.props.javaScriptEnabledAndroid}
101108
contentInset={this.props.contentInset}
@@ -176,8 +183,9 @@ var WebView = React.createClass({
176183

177184
var RCTWebView = createReactNativeComponentClass({
178185
validAttributes: merge(ReactNativeViewAttributes.UIView, {
179-
url: true,
186+
injectedJavaScript: true,
180187
javaScriptEnabledAndroid: true,
188+
url: true,
181189
userAgent: true,
182190
}),
183191
uiViewClassName: 'RCTWebView',

Libraries/Components/WebView/WebView.ios.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ var WebView = React.createClass({
9898
*/
9999
javaScriptEnabledAndroid: PropTypes.bool,
100100
/**
101-
* Used for iOS only, sets the JS to be injected when the webpage loads.
101+
* Sets the JS to be injected when the webpage loads.
102102
*/
103-
injectedJavascriptIOS: PropTypes.string,
103+
injectedJavaScript: PropTypes.string,
104104

105105
/**
106106
* Used for iOS only, sets whether the webpage scales to fit the view and the
@@ -159,7 +159,7 @@ var WebView = React.createClass({
159159
style={webViewStyles}
160160
url={this.props.url}
161161
html={this.props.html}
162-
injectedJavascriptIOS={this.props.injectedJavascriptIOS}
162+
injectedJavaScript={this.props.injectedJavaScript}
163163
bounces={this.props.bounces}
164164
scrollEnabled={this.props.scrollEnabled}
165165
contentInset={this.props.contentInset}
@@ -179,15 +179,15 @@ var WebView = React.createClass({
179179
},
180180

181181
goForward: function() {
182-
RCTWebViewManager.goForward(this.getWebWiewHandle());
182+
RCTWebViewManager.goForward(this.getWebViewHandle());
183183
},
184184

185185
goBack: function() {
186-
RCTWebViewManager.goBack(this.getWebWiewHandle());
186+
RCTWebViewManager.goBack(this.getWebViewHandle());
187187
},
188188

189189
reload: function() {
190-
RCTWebViewManager.reload(this.getWebWiewHandle());
190+
RCTWebViewManager.reload(this.getWebViewHandle());
191191
},
192192

193193
/**
@@ -200,7 +200,7 @@ var WebView = React.createClass({
200200
}
201201
},
202202

203-
getWebWiewHandle: function(): any {
203+
getWebViewHandle: function(): any {
204204
return React.findNodeHandle(this.refs[RCT_WEBVIEW_REF]);
205205
},
206206

React/Views/RCTWebView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern NSString *const RCTJSNavigationScheme;
1818
@property (nonatomic, strong) NSURL *URL;
1919
@property (nonatomic, assign) UIEdgeInsets contentInset;
2020
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
21-
@property (nonatomic, copy) NSString *injectedJavascriptIOS;
21+
@property (nonatomic, copy) NSString *injectedJavaScript;
2222

2323
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
2424

React/Views/RCTWebView.m

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ @implementation RCTWebView
3333
{
3434
RCTEventDispatcher *_eventDispatcher;
3535
UIWebView *_webView;
36-
NSString *_injectedJavascriptIOS;
36+
NSString *_injectedJavaScript;
3737
}
3838

3939
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
@@ -126,19 +126,6 @@ - (UIColor *)backgroundColor
126126
return _webView.backgroundColor;
127127
}
128128

129-
- (void)setinjectedJavascriptIOS:(NSString *)jsStr
130-
{
131-
if (_injectedJavascriptIOS == jsStr) {
132-
return;
133-
}
134-
135-
if ([_injectedJavascriptIOS isEqualToString:jsStr]) {
136-
return;
137-
}
138-
139-
_injectedJavascriptIOS = [jsStr copy];
140-
}
141-
142129
- (NSMutableDictionary *)baseEvent
143130
{
144131
NSURL *url = _webView.request.URL;
@@ -197,8 +184,8 @@ - (void)webView:(__unused UIWebView *)webView didFailLoadWithError:(NSError *)er
197184

198185
- (void)webViewDidFinishLoad:(UIWebView *)webView
199186
{
200-
if (_injectedJavascriptIOS != nil) {
201-
[webView stringByEvaluatingJavaScriptFromString:_injectedJavascriptIOS];
187+
if (_injectedJavaScript != nil) {
188+
[webView stringByEvaluatingJavaScriptFromString:_injectedJavaScript];
202189
}
203190

204191
// we only need the final 'finishLoad' call so only fire the event when we're actually done loading.

React/Views/RCTWebViewManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ - (UIView *)view
2828
RCT_REMAP_VIEW_PROPERTY(bounces, _webView.scrollView.bounces, BOOL);
2929
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, _webView.scrollView.scrollEnabled, BOOL);
3030
RCT_REMAP_VIEW_PROPERTY(scalesPageToFit, _webView.scalesPageToFit, BOOL);
31-
RCT_EXPORT_VIEW_PROPERTY(injectedJavascriptIOS, NSString);
31+
RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString);
3232
RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets);
3333
RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL);
3434

0 commit comments

Comments
 (0)