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.
This commit is contained in:
Hedger Wang 2015-07-07 17:07:52 -07:00
parent 1b7699f671
commit bb141e3a3c
5 changed files with 21 additions and 26 deletions

View File

@ -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',

View File

@ -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]);
},

View File

@ -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;

View File

@ -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.

View File

@ -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);