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.ios.js
116 lines (100 loc) · 3.19 KB
/
WebView.ios.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
110
111
112
113
114
115
116
import React, { cloneElement } from 'react';
import PropTypes from 'prop-types';
import { WebView, UIManager, requireNativeComponent } from 'react-native';
export default class extends WebView {
static displayName = 'AdvancedWebView';
static propTypes = {
...WebView.propTypes,
keyboardDisplayRequiresUserAction: PropTypes.bool,
allowFileAccessFromFileURLs: PropTypes.bool,
hideAccessory: PropTypes.bool,
validSchemes: PropTypes.array,
disableKeyboardAdjust: PropTypes.bool,
contentInsetAdjustmentBehavior: PropTypes.number,
userAgent: PropTypes.string
};
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,
disableKeyboardAdjust, contentInsetAdjustmentBehavior, userAgent } = this.props;
const advancedWebview = (
<RNAdvancedWebView
{...webview.props}
ref="webview"
userAgent={userAgent}
allowFileAccessFromFileURLs={allowFileAccessFromFileURLs}
keyboardDisplayRequiresUserAction={keyboardDisplayRequiresUserAction}
hideAccessory={hideAccessory}
disableKeyboardAdjust={disableKeyboardAdjust}
contentInsetAdjustmentBehavior={contentInsetAdjustmentBehavior}
/>
);
return cloneElement(wrapper, wrapper.props, advancedWebview, ...children);
}
}
const RNAdvancedWebView = requireNativeComponent('RNAdvancedWebView', null, {
nativeOnly: {
allowFileAccessFromFileURLs: true,
hideAccessory: true,
keyboardDisplayRequiresUserAction: true,
contentInsetAdjustmentBehavior: true,
userAgent: true
}
})