This repository has been archived by the owner on Nov 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
WebView.android.js
109 lines (93 loc) · 3.27 KB
/
WebView.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React, { cloneElement } from 'react';
import { WebView, UIManager, requireNativeComponent } from 'react-native';
import PropTypes from 'prop-types';
export default class extends WebView {
static displayName = 'AdvancedWebView';
static propTypes = {
...WebView.propTypes,
keyboardDisplayRequiresUserAction: PropTypes.bool,
allowFileAccessFromFileURLs: PropTypes.bool,
hideAccessory: PropTypes.bool,
webviewDebugEnabledWhenDev: PropTypes.number
};
goForward = () => {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RNAdvancedWebView.Commands.goForward,
null
);
};
goBack = () => {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RNAdvancedWebView.Commands.goBack,
null
);
};
reload = () => {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RNAdvancedWebView.Commands.reload,
null
);
};
stopLoading = () => {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RNAdvancedWebView.Commands.stopLoading,
null
);
};
postMessage = (data) => {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RNAdvancedWebView.Commands.postMessage,
[String(data)]
);
};
injectJavaScript = (data) => {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.RNAdvancedWebView.Commands.injectJavaScript,
[data]
);
};
_onLoadingError = (event) => {
event.persist(); // persist this event because we need to store it
var {onError, onLoadEnd} = this.props;
var result = onError && onError(event);
onLoadEnd && onLoadEnd(event);
console.warn('Encountered an error loading page', event.nativeEvent);
result !== false && this.setState({
lastErrorEvent: event.nativeEvent,
viewState: 'ERROR'
});
};
onLoadingError = (event) => {
this._onLoadingError(event)
};
render() {
const wrapper = super.render();
const [webview,...children] = wrapper.props.children;
const { hideAccessory, allowFileAccessFromFileURLs, keyboardDisplayRequiresUserAction,webviewDebugEnabledWhenDev} = this.props;
const advancedWebview = (
<RNAdvancedWebView
{...webview.props}
ref="webview"
allowFileAccessFromFileURLs={allowFileAccessFromFileURLs}
keyboardDisplayRequiresUserAction={keyboardDisplayRequiresUserAction}
hideAccessory={hideAccessory}
webviewDebugEnabledWhenDev={webviewDebugEnabledWhenDev}
/>
);
return cloneElement(wrapper, wrapper.props, advancedWebview, ...children);
}
}
const RNAdvancedWebView = requireNativeComponent('RNAdvancedWebView', null, {
nativeOnly: {
allowFileAccessFromFileURLs: true,
hideAccessory: true,
keyboardDisplayRequiresUserAction: true,
webviewDebugEnabledWhenDev: true
}
})