mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 20:01:01 +08:00
Add headers prop to Android WebViews
Summary: Related to [issue #5418](https://github.com/facebook/react-native/issues/5418) This is a follow-up to [this previous pull request.](https://github.com/facebook/react-native/pull/5419) ~~Adds a new ReactProp 'urlWithHeaders' to Android WebViews that takes an object with a 'url' string and a 'headers' map.~~ [Update] Adds a new prop 'source' to Android WebViews ``` { html: string, url: string, headers: map<string, string>, } ``` Update: resolves TODO 8495359 Closes https://github.com/facebook/react-native/pull/5494 Reviewed By: svcscm Differential Revision: D2881313 Pulled By: nicklockwood fb-gh-sync-id: 7cad8490d4932d0a7ef559165f3ec279d873c537
This commit is contained in:
committed by
facebook-github-bot-4
parent
f04882f8e4
commit
80a2f5d50f
@@ -17,6 +17,7 @@ var StyleSheet = require('StyleSheet');
|
||||
var UIManager = require('UIManager');
|
||||
var View = require('View');
|
||||
|
||||
var deprecatedPropType = require('deprecatedPropType');
|
||||
var keyMirror = require('keyMirror');
|
||||
var merge = require('merge');
|
||||
var requireNativeComponent = require('requireNativeComponent');
|
||||
@@ -44,14 +45,29 @@ var WebView = React.createClass({
|
||||
onLoadEnd: PropTypes.func,
|
||||
onLoadStart: PropTypes.func,
|
||||
onError: PropTypes.func,
|
||||
url: PropTypes.string,
|
||||
html: PropTypes.string,
|
||||
automaticallyAdjustContentInsets: PropTypes.bool,
|
||||
contentInset: EdgeInsetsPropType,
|
||||
onNavigationStateChange: PropTypes.func,
|
||||
startInLoadingState: PropTypes.bool, // force WebView to show loadingView on first load
|
||||
style: View.propTypes.style,
|
||||
|
||||
html: deprecatedPropType(
|
||||
PropTypes.string,
|
||||
'Use the `source` prop instead.'
|
||||
),
|
||||
|
||||
url: deprecatedPropType(
|
||||
PropTypes.string,
|
||||
'Use the `source` prop instead.'
|
||||
),
|
||||
|
||||
/**
|
||||
* Used on Android only, provides html or url with optional headers to the WebView.
|
||||
* `{ html: string, uri: string, headers: map<string, string> }`
|
||||
* @platform android
|
||||
*/
|
||||
source: PropTypes.object,
|
||||
|
||||
/**
|
||||
* Used on Android only, JS is enabled by default for WebView on iOS
|
||||
* @platform android
|
||||
@@ -127,13 +143,19 @@ var WebView = React.createClass({
|
||||
domStorageEnabled = this.props.domStorageEnabledAndroid;
|
||||
}
|
||||
|
||||
var source = this.props.source || {};
|
||||
if (this.props.html) {
|
||||
source.html = this.props.html;
|
||||
} else if (this.props.url) {
|
||||
source.uri = this.props.url;
|
||||
}
|
||||
|
||||
var webView =
|
||||
<RCTWebView
|
||||
ref={RCT_WEBVIEW_REF}
|
||||
key="webViewKey"
|
||||
style={webViewStyles}
|
||||
url={this.props.url}
|
||||
html={this.props.html}
|
||||
source={source}
|
||||
injectedJavaScript={this.props.injectedJavaScript}
|
||||
userAgent={this.props.userAgent}
|
||||
javaScriptEnabled={javaScriptEnabled}
|
||||
|
||||
Reference in New Issue
Block a user