From 1148766747f0c80ec8a8a1d0a60fe868ee49cbf8 Mon Sep 17 00:00:00 2001 From: Thibault Malbranche Date: Tue, 22 Jan 2019 19:17:20 +0100 Subject: [PATCH] wip --- .../webview/RNCWebViewManager.java | 2 +- docs/Reference.md | 11 +++++------ ios/RNCWKWebView.h | 2 +- ios/RNCWKWebView.m | 2 +- ios/RNCWKWebViewManager.m | 2 +- js/WebView.android.js | 11 +++++++---- js/WebView.ios.js | 14 +++++++------- js/WebViewTypes.js | 2 +- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index 4783aa6..e6d7d7a 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -532,7 +532,7 @@ public class RNCWebViewManager extends SimpleViewManager { view.getSettings().setJavaScriptEnabled(enabled); } - @ReactProp(name = "enableCache") + @ReactProp(name = "cacheEnabled") public void setCacheEnabled(WebView view, boolean enabled) { if (enabled) { Context ctx = view.getContext(); diff --git a/docs/Reference.md b/docs/Reference.md index 8bca613..d64114b 100644 --- a/docs/Reference.md +++ b/docs/Reference.md @@ -48,7 +48,7 @@ This document lays out the current public properties and methods for the React N - [`incognito`](Reference.md#incognito) - [`allowFileAccess`](Reference.md#allowFileAccess) - [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled) -- [`enableCache`](Reference.md#enableCache) +- [`cacheEnabled`](Reference.md#cacheEnabled) - [`pagingEnabled`](Reference.md#pagingEnabled) - [`allowsLinkPreview`](Reference.md#allowsLinkPreview) @@ -361,9 +361,9 @@ 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). -| Type | Required | Platform | -| ------ | -------- | -------- | -| string | No | Android, iOS WKWebView | +| Type | Required | Platform | +| ------ | -------- | ---------------------- | +| 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. @@ -582,7 +582,6 @@ A Boolean value that determines whether pressing on a link displays a preview of | ------- | -------- | -------- | | boolean | No | iOS | - ## Methods ### `extraNativeComponentConfig()` diff --git a/ios/RNCWKWebView.h b/ios/RNCWKWebView.h index 1e43053..d3ad66d 100644 --- a/ios/RNCWKWebView.h +++ b/ios/RNCWKWebView.h @@ -41,7 +41,7 @@ @property (nonatomic, assign) BOOL incognito; @property (nonatomic, assign) BOOL useSharedProcessPool; @property (nonatomic, copy) NSString *userAgent; -@property (nonatomic, assign) BOOL enableCache; +@property (nonatomic, assign) BOOL cacheEnabled; @property (nonatomic, assign) BOOL allowsLinkPreview; - (void)postMessage:(NSString *)message; diff --git a/ios/RNCWKWebView.m b/ios/RNCWKWebView.m index 0058636..fee82a8 100644 --- a/ios/RNCWKWebView.m +++ b/ios/RNCWKWebView.m @@ -83,7 +83,7 @@ static NSString *const MessageHanderName = @"ReactNative"; WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new]; if (_incognito) { wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; - } else if (_enableCache) { + } else if (_cacheEnabled) { wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore defaultDataStore]; } if(self.useSharedProcessPool) { diff --git a/ios/RNCWKWebViewManager.m b/ios/RNCWKWebViewManager.m index 97e4713..73a664b 100644 --- a/ios/RNCWKWebViewManager.m +++ b/ios/RNCWKWebViewManager.m @@ -48,7 +48,7 @@ RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL) RCT_EXPORT_VIEW_PROPERTY(incognito, BOOL) RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString) -RCT_EXPORT_VIEW_PROPERTY(enableCache, BOOL) +RCT_EXPORT_VIEW_PROPERTY(cacheEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL) /** diff --git a/js/WebView.android.js b/js/WebView.android.js index 59b2b4d..408ca62 100644 --- a/js/WebView.android.js +++ b/js/WebView.android.js @@ -17,7 +17,7 @@ import ReactNative, { StyleSheet, UIManager, View, - NativeModules + NativeModules, } from 'react-native'; import invariant from 'fbjs/lib/invariant'; @@ -67,7 +67,7 @@ class WebView extends React.Component { scalesPageToFit: true, allowFileAccess: false, saveFormDataDisabled: false, - enableCache: true, + cacheEnabled: true, androidHardwareAccelerationDisabled: false, originWhitelist: defaultOriginWhitelist, }; @@ -75,7 +75,7 @@ class WebView extends React.Component { static isFileUploadSupported = async () => { // native implementation should return "true" only for Android 5+ return NativeModules.RNCWebView.isFileUploadSupported(); - } + }; state = { viewState: this.props.startInLoadingState @@ -152,10 +152,13 @@ class WebView extends React.Component { injectedJavaScript={this.props.injectedJavaScript} userAgent={this.props.userAgent} javaScriptEnabled={this.props.javaScriptEnabled} - androidHardwareAccelerationDisabled={this.props.androidHardwareAccelerationDisabled} + androidHardwareAccelerationDisabled={ + this.props.androidHardwareAccelerationDisabled + } thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled} domStorageEnabled={this.props.domStorageEnabled} messagingEnabled={typeof this.props.onMessage === 'function'} + cacheEnabled={this.props.cacheEnabled} onMessage={this.onMessage} overScrollMode={this.props.overScrollMode} contentInset={this.props.contentInset} diff --git a/js/WebView.ios.js b/js/WebView.ios.js index 06de5a1..27b6e3b 100644 --- a/js/WebView.ios.js +++ b/js/WebView.ios.js @@ -133,7 +133,7 @@ class WebView extends React.Component { static defaultProps = { useWebKit: true, - enableCache: true, + cacheEnabled: true, originWhitelist: defaultOriginWhitelist, useSharedProcessPool: true, }; @@ -141,7 +141,7 @@ class WebView extends React.Component { static isFileUploadSupported = async () => { // no native implementation for iOS, depends only on permissions return true; - } + }; state = { viewState: this.props.startInLoadingState @@ -170,10 +170,7 @@ class WebView extends React.Component { ); } - if ( - !this.props.useWebKit && - this.props.incognito - ) { + if (!this.props.useWebKit && this.props.incognito) { console.warn( 'The incognito property is not supported when useWebKit = false', ); @@ -255,13 +252,16 @@ class WebView extends React.Component { bounces={this.props.bounces} scrollEnabled={this.props.scrollEnabled} pagingEnabled={this.props.pagingEnabled} + cacheEnabled={this.props.cacheEnabled} decelerationRate={decelerationRate} contentInset={this.props.contentInset} automaticallyAdjustContentInsets={ this.props.automaticallyAdjustContentInsets } hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView} - allowsBackForwardNavigationGestures={this.props.allowsBackForwardNavigationGestures} + allowsBackForwardNavigationGestures={ + this.props.allowsBackForwardNavigationGestures + } incognito={this.props.incognito} userAgent={this.props.userAgent} onLoadingStart={this._onLoadingStart} diff --git a/js/WebViewTypes.js b/js/WebViewTypes.js index 167ca3b..1e6f076 100644 --- a/js/WebViewTypes.js +++ b/js/WebViewTypes.js @@ -491,7 +491,7 @@ export type WebViewSharedProps = $ReadOnly<{| /** * Should caching be enabled. Default is true. */ - enableCache?: ?boolean, + cacheEnabled?: ?boolean, style?: ViewStyleProp, children: Node,