feat(android): Expose cacheMode property (#895)

This commit is contained in:
Andres Castano 2019-09-29 23:45:20 +10:00 committed by Thibault Malbranche
parent 902d3d1e7f
commit 5da59251ce
3 changed files with 54 additions and 0 deletions

View File

@ -257,6 +257,27 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
}
}
@ReactProp(name = "cacheMode")
public void setCacheMode(WebView view, String cacheModeString) {
Integer cacheMode;
switch (cacheModeString) {
case "LOAD_CACHE_ONLY":
cacheMode = WebSettings.LOAD_CACHE_ONLY;
break;
case "LOAD_CACHE_ELSE_NETWORK":
cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK;
break;
case "LOAD_NO_CACHE":
cacheMode = WebSettings.LOAD_NO_CACHE;
break;
case "LOAD_DEFAULT":
default:
cacheMode = WebSettings.LOAD_DEFAULT;
break;
}
view.getSettings().setCacheMode(cacheMode);
}
@ReactProp(name = "androidHardwareAccelerationDisabled")
public void setHardwareAccelerationDisabled(WebView view, boolean disabled) {
ReactContext reactContext = (ReactContext) view.getContext();

View File

@ -55,6 +55,7 @@ This document lays out the current public properties and methods for the React N
- [`allowFileAccess`](Reference.md#allowFileAccess)
- [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled)
- [`cacheEnabled`](Reference.md#cacheEnabled)
- [`cacheMode`](Reference.md#cacheMode)
- [`pagingEnabled`](Reference.md#pagingEnabled)
- [`allowsLinkPreview`](Reference.md#allowsLinkPreview)
- [`sharedCookiesEnabled`](Reference.md#sharedCookiesEnabled)
@ -985,6 +986,22 @@ Sets whether WebView should use browser caching.
---
### `cacheMode`
Overrides the way the cache is used. The way the cache is used is based on the navigation type. For a normal page load, the cache is checked and content is re-validated as needed. When navigating back, content is not revalidated, instead the content is just retrieved from the cache. This property allows the client to override this behavior.
Possible values are:
- `LOAD_DEFAULT` - Default cache usage mode. If the navigation type doesn't impose any specific behavior, use cached resources when they are available and not expired, otherwise load resources from the network.
- `LOAD_CACHE_ELSE_NETWORK` - Use cached resources when they are available, even if they have expired. Otherwise load resources from the network.
- `LOAD_NO_CACHE` - Don't use the cache, load from the network.
- `LOAD_CACHE_ONLY` - Don't use the network, load from the cache.
| Type | Required | Default | Platform |
| ------- | -------- | -------------| -------- |
| string | No | LOAD_DEFAULT | Android |
---
### `pagingEnabled`
If the value of this property is true, the scroll view stops on multiples of the scroll views bounds when the user scrolls. The default value is false.

View File

@ -145,6 +145,8 @@ export type DataDetectorTypes =
export type OverScrollModeType = 'always' | 'content' | 'never';
export type CacheMode = 'LOAD_DEFAULT' | 'LOAD_CACHE_ONLY' | 'LOAD_CACHE_ELSE_NETWORK' | 'LOAD_NO_CACHE';
export interface WebViewSourceUri {
/**
* The URI to load in the `WebView`. Can be a local or remote file.
@ -237,6 +239,7 @@ export interface CommonNativeWebViewProps extends ViewProps {
}
export interface AndroidNativeWebViewProps extends CommonNativeWebViewProps {
cacheMode?: CacheMode;
allowFileAccess?: boolean;
scalesPageToFit?: boolean;
allowUniversalAccessFromFileURLs?: boolean;
@ -459,6 +462,19 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
onNavigationStateChange?: (event: WebViewNavigation) => void;
onContentSizeChange?: (event: WebViewEvent) => void;
/**
* https://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode(int)
* Set the cacheMode. Possible values are:
*
* - `'LOAD_DEFAULT'` (default)
* - `'LOAD_CACHE_ELSE_NETWORK'`
* - `'LOAD_NO_CACHE'`
* - `'LOAD_CACHE_ONLY'`
*
* @platform android
*/
cacheMode?: CacheMode;
/**
* https://developer.android.com/reference/android/view/View#OVER_SCROLL_NEVER
* Sets the overScrollMode. Possible values are: