[WebView]: Kill shouldInjectAJAXHandler, and add injectedJavascriptIOS

Summary:
@public

The API and implementation of `shouldInjectAJAXHandler` is very opinionated, and it does not solve many of the use cases that we'd like to address.

Since  `shouldInjectAJAXHandler` is basically juts injecting JS to the web page, we should let developer inject whatever JS that address different issues that they want to fix.

Test Plan:
Test this snippet at <Playground />

```
<WebView
  url="http://www.facebook.com"
  injectedJavascriptIOS="document.body.style.border='solid 10px red'"
/>
```
This commit is contained in:
Hedger Wang
2015-07-01 18:06:39 -07:00
parent b45e2ed7ed
commit 54825b304a
4 changed files with 40 additions and 35 deletions

View File

@@ -43,6 +43,8 @@ var NavigationType = {
other: RCTWebViewManager.NavigationType.Other,
};
var JSNavigationScheme = RCTWebViewManager.JSNavigationScheme;
type ErrorEvent = {
domain: any;
code: any;
@@ -75,6 +77,7 @@ var defaultRenderError = (errorDomain, errorCode, errorDesc) => (
var WebView = React.createClass({
statics: {
JSNavigationScheme: JSNavigationScheme,
NavigationType: NavigationType,
},
@@ -86,7 +89,6 @@ var WebView = React.createClass({
bounces: PropTypes.bool,
scrollEnabled: PropTypes.bool,
automaticallyAdjustContentInsets: PropTypes.bool,
shouldInjectAJAXHandler: PropTypes.bool,
contentInset: EdgeInsetsPropType,
onNavigationStateChange: PropTypes.func,
startInLoadingState: PropTypes.bool, // force WebView to show loadingView on first load
@@ -95,6 +97,11 @@ var WebView = React.createClass({
* Used for android only, JS is enabled by default for WebView on iOS
*/
javaScriptEnabledAndroid: PropTypes.bool,
/**
* Used for iOS only, sets the JS to be injected when the webpage loads.
*/
injectedJavascriptIOS: PropTypes.string,
/**
* Used for iOS only, sets whether the webpage scales to fit the view and the
* user can change the scale
@@ -152,9 +159,9 @@ var WebView = React.createClass({
style={webViewStyles}
url={this.props.url}
html={this.props.html}
injectedJavascriptIOS={this.props.injectedJavascriptIOS}
bounces={this.props.bounces}
scrollEnabled={this.props.scrollEnabled}
shouldInjectAJAXHandler={this.props.shouldInjectAJAXHandler}
contentInset={this.props.contentInset}
automaticallyAdjustContentInsets={this.props.automaticallyAdjustContentInsets}
onLoadingStart={this.onLoadingStart}