This commit is contained in:
Thibault Malbranche 2019-01-22 19:17:20 +01:00
parent 8ec7c16e5c
commit 1148766747
8 changed files with 24 additions and 22 deletions

View File

@ -532,7 +532,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
view.getSettings().setJavaScriptEnabled(enabled); view.getSettings().setJavaScriptEnabled(enabled);
} }
@ReactProp(name = "enableCache") @ReactProp(name = "cacheEnabled")
public void setCacheEnabled(WebView view, boolean enabled) { public void setCacheEnabled(WebView view, boolean enabled) {
if (enabled) { if (enabled) {
Context ctx = view.getContext(); Context ctx = view.getContext();

View File

@ -48,7 +48,7 @@ This document lays out the current public properties and methods for the React N
- [`incognito`](Reference.md#incognito) - [`incognito`](Reference.md#incognito)
- [`allowFileAccess`](Reference.md#allowFileAccess) - [`allowFileAccess`](Reference.md#allowFileAccess)
- [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled) - [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled)
- [`enableCache`](Reference.md#enableCache) - [`cacheEnabled`](Reference.md#cacheEnabled)
- [`pagingEnabled`](Reference.md#pagingEnabled) - [`pagingEnabled`](Reference.md#pagingEnabled)
- [`allowsLinkPreview`](Reference.md#allowsLinkPreview) - [`allowsLinkPreview`](Reference.md#allowsLinkPreview)
@ -362,7 +362,7 @@ Boolean value to enable third party cookies in the `WebView`. Used on Android Lo
Sets the user-agent for the `WebView`. This will only work for iOS if you are using WKWebView, not UIWebView (see https://developer.apple.com/documentation/webkit/wkwebview/1414950-customuseragent). Sets the user-agent for the `WebView`. This will only work for iOS if you are using WKWebView, not UIWebView (see https://developer.apple.com/documentation/webkit/wkwebview/1414950-customuseragent).
| Type | Required | Platform | | Type | Required | Platform |
| ------ | -------- | -------- | | ------ | -------- | ---------------------- |
| string | No | Android, iOS WKWebView | | string | No | Android, iOS WKWebView |
--- ---
@ -554,7 +554,7 @@ Sets whether the WebView should disable saving form data. The default value is `
--- ---
### `enableCache` ### `cacheEnabled`
Sets whether WebView & WKWebView should use browser caching. Sets whether WebView & WKWebView should use browser caching.
@ -582,7 +582,6 @@ A Boolean value that determines whether pressing on a link displays a preview of
| ------- | -------- | -------- | | ------- | -------- | -------- |
| boolean | No | iOS | | boolean | No | iOS |
## Methods ## Methods
### `extraNativeComponentConfig()` ### `extraNativeComponentConfig()`

View File

@ -41,7 +41,7 @@
@property (nonatomic, assign) BOOL incognito; @property (nonatomic, assign) BOOL incognito;
@property (nonatomic, assign) BOOL useSharedProcessPool; @property (nonatomic, assign) BOOL useSharedProcessPool;
@property (nonatomic, copy) NSString *userAgent; @property (nonatomic, copy) NSString *userAgent;
@property (nonatomic, assign) BOOL enableCache; @property (nonatomic, assign) BOOL cacheEnabled;
@property (nonatomic, assign) BOOL allowsLinkPreview; @property (nonatomic, assign) BOOL allowsLinkPreview;
- (void)postMessage:(NSString *)message; - (void)postMessage:(NSString *)message;

View File

@ -83,7 +83,7 @@ static NSString *const MessageHanderName = @"ReactNative";
WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new]; WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
if (_incognito) { if (_incognito) {
wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
} else if (_enableCache) { } else if (_cacheEnabled) {
wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore defaultDataStore]; wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore defaultDataStore];
} }
if(self.useSharedProcessPool) { if(self.useSharedProcessPool) {

View File

@ -48,7 +48,7 @@ RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
RCT_EXPORT_VIEW_PROPERTY(incognito, BOOL) RCT_EXPORT_VIEW_PROPERTY(incognito, BOOL)
RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString) RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
RCT_EXPORT_VIEW_PROPERTY(enableCache, BOOL) RCT_EXPORT_VIEW_PROPERTY(cacheEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL) RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)
/** /**

View File

@ -17,7 +17,7 @@ import ReactNative, {
StyleSheet, StyleSheet,
UIManager, UIManager,
View, View,
NativeModules NativeModules,
} from 'react-native'; } from 'react-native';
import invariant from 'fbjs/lib/invariant'; import invariant from 'fbjs/lib/invariant';
@ -67,7 +67,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
scalesPageToFit: true, scalesPageToFit: true,
allowFileAccess: false, allowFileAccess: false,
saveFormDataDisabled: false, saveFormDataDisabled: false,
enableCache: true, cacheEnabled: true,
androidHardwareAccelerationDisabled: false, androidHardwareAccelerationDisabled: false,
originWhitelist: defaultOriginWhitelist, originWhitelist: defaultOriginWhitelist,
}; };
@ -75,7 +75,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
static isFileUploadSupported = async () => { static isFileUploadSupported = async () => {
// native implementation should return "true" only for Android 5+ // native implementation should return "true" only for Android 5+
return NativeModules.RNCWebView.isFileUploadSupported(); return NativeModules.RNCWebView.isFileUploadSupported();
} };
state = { state = {
viewState: this.props.startInLoadingState viewState: this.props.startInLoadingState
@ -152,10 +152,13 @@ class WebView extends React.Component<WebViewSharedProps, State> {
injectedJavaScript={this.props.injectedJavaScript} injectedJavaScript={this.props.injectedJavaScript}
userAgent={this.props.userAgent} userAgent={this.props.userAgent}
javaScriptEnabled={this.props.javaScriptEnabled} javaScriptEnabled={this.props.javaScriptEnabled}
androidHardwareAccelerationDisabled={this.props.androidHardwareAccelerationDisabled} androidHardwareAccelerationDisabled={
this.props.androidHardwareAccelerationDisabled
}
thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled} thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled}
domStorageEnabled={this.props.domStorageEnabled} domStorageEnabled={this.props.domStorageEnabled}
messagingEnabled={typeof this.props.onMessage === 'function'} messagingEnabled={typeof this.props.onMessage === 'function'}
cacheEnabled={this.props.cacheEnabled}
onMessage={this.onMessage} onMessage={this.onMessage}
overScrollMode={this.props.overScrollMode} overScrollMode={this.props.overScrollMode}
contentInset={this.props.contentInset} contentInset={this.props.contentInset}

View File

@ -133,7 +133,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
static defaultProps = { static defaultProps = {
useWebKit: true, useWebKit: true,
enableCache: true, cacheEnabled: true,
originWhitelist: defaultOriginWhitelist, originWhitelist: defaultOriginWhitelist,
useSharedProcessPool: true, useSharedProcessPool: true,
}; };
@ -141,7 +141,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
static isFileUploadSupported = async () => { static isFileUploadSupported = async () => {
// no native implementation for iOS, depends only on permissions // no native implementation for iOS, depends only on permissions
return true; return true;
} };
state = { state = {
viewState: this.props.startInLoadingState viewState: this.props.startInLoadingState
@ -170,10 +170,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
); );
} }
if ( if (!this.props.useWebKit && this.props.incognito) {
!this.props.useWebKit &&
this.props.incognito
) {
console.warn( console.warn(
'The incognito property is not supported when useWebKit = false', 'The incognito property is not supported when useWebKit = false',
); );
@ -255,13 +252,16 @@ class WebView extends React.Component<WebViewSharedProps, State> {
bounces={this.props.bounces} bounces={this.props.bounces}
scrollEnabled={this.props.scrollEnabled} scrollEnabled={this.props.scrollEnabled}
pagingEnabled={this.props.pagingEnabled} pagingEnabled={this.props.pagingEnabled}
cacheEnabled={this.props.cacheEnabled}
decelerationRate={decelerationRate} decelerationRate={decelerationRate}
contentInset={this.props.contentInset} contentInset={this.props.contentInset}
automaticallyAdjustContentInsets={ automaticallyAdjustContentInsets={
this.props.automaticallyAdjustContentInsets this.props.automaticallyAdjustContentInsets
} }
hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView} hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView}
allowsBackForwardNavigationGestures={this.props.allowsBackForwardNavigationGestures} allowsBackForwardNavigationGestures={
this.props.allowsBackForwardNavigationGestures
}
incognito={this.props.incognito} incognito={this.props.incognito}
userAgent={this.props.userAgent} userAgent={this.props.userAgent}
onLoadingStart={this._onLoadingStart} onLoadingStart={this._onLoadingStart}

View File

@ -491,7 +491,7 @@ export type WebViewSharedProps = $ReadOnly<{|
/** /**
* Should caching be enabled. Default is true. * Should caching be enabled. Default is true.
*/ */
enableCache?: ?boolean, cacheEnabled?: ?boolean,
style?: ViewStyleProp, style?: ViewStyleProp,
children: Node, children: Node,