|
@@ -42,8 +42,6 @@ const RCTAutoHeightWebView = requireNativeComponent('RCTAutoHeightWebView', Auto
|
42
|
42
|
|
43
|
43
|
import momoize from './momoize';
|
44
|
44
|
|
45
|
|
-const baseUrl = 'file:///android_asset/web/';
|
46
|
|
-
|
47
|
45
|
const getUpdatedState = momoize(setState, isEqual);
|
48
|
46
|
|
49
|
47
|
export default class AutoHeightWebView extends PureComponent {
|
|
@@ -65,15 +63,15 @@ export default class AutoHeightWebView extends PureComponent {
|
65
|
63
|
animationEasing: PropTypes.func,
|
66
|
64
|
// offset of rn webView margin
|
67
|
65
|
heightOffset: PropTypes.number,
|
68
|
|
- // baseUrl not work in android 4.3 or below version
|
69
|
|
- enableBaseUrl: PropTypes.bool,
|
70
|
66
|
style: ViewPropTypes.style,
|
71
|
67
|
// rn WebView callback
|
72
|
68
|
onError: PropTypes.func,
|
73
|
69
|
onLoad: PropTypes.func,
|
74
|
70
|
onLoadStart: PropTypes.func,
|
75
|
71
|
onLoadEnd: PropTypes.func,
|
76
|
|
- // works if set enableBaseUrl to true; add web/files... to android/app/src/assets/
|
|
72
|
+ // 'file:///android_asset/web/' by default, and baseUrl not work in android 4.3 or below version
|
|
73
|
+ baseUrl: PropTypes.string,
|
|
74
|
+ // add baseUrl/files... to android/app/src/assets/
|
77
|
75
|
files: PropTypes.arrayOf(
|
78
|
76
|
PropTypes.shape({
|
79
|
77
|
href: PropTypes.string,
|
|
@@ -84,8 +82,8 @@ export default class AutoHeightWebView extends PureComponent {
|
84
|
82
|
};
|
85
|
83
|
|
86
|
84
|
static defaultProps = {
|
|
85
|
+ baseUrl: 'file:///android_asset/web/',
|
87
|
86
|
scalesPageToFit: true,
|
88
|
|
- enableBaseUrl: false,
|
89
|
87
|
enableAnimation: true,
|
90
|
88
|
animationDuration: 255,
|
91
|
89
|
heightOffset: 20,
|
|
@@ -94,7 +92,7 @@ export default class AutoHeightWebView extends PureComponent {
|
94
|
92
|
|
95
|
93
|
constructor(props) {
|
96
|
94
|
super(props);
|
97
|
|
- const { enableAnimation, style, source, enableBaseUrl, heightOffset } = props;
|
|
95
|
+ const { baseUrl, enableAnimation, style, source, heightOffset } = props;
|
98
|
96
|
isBelowKitKat && DeviceEventEmitter.addListener('webViewBridgeMessage', this.listenWebViewBridgeMessage);
|
99
|
97
|
this.finishInterval = true;
|
100
|
98
|
const initWidth = getWidth(style);
|
|
@@ -105,7 +103,7 @@ export default class AutoHeightWebView extends PureComponent {
|
105
|
103
|
height: initHeight,
|
106
|
104
|
width: initWidth,
|
107
|
105
|
script: getScript(props, getBaseScript),
|
108
|
|
- source: enableBaseUrl ? Object.assign({}, source, { baseUrl }) : source
|
|
106
|
+ source: Object.assign({}, source, { baseUrl })
|
109
|
107
|
};
|
110
|
108
|
if (enableAnimation) {
|
111
|
109
|
Object.assign(state, {
|
|
@@ -122,8 +120,8 @@ export default class AutoHeightWebView extends PureComponent {
|
122
|
120
|
|
123
|
121
|
static getDerivedStateFromProps(props, state) {
|
124
|
122
|
const { height: oldHeight, width: oldWidth, source: prevSource, script: prevScript } = state;
|
125
|
|
- const { style, enableBaseUrl } = props;
|
126
|
|
- const { source, script } = getUpdatedState(props, enableBaseUrl ? baseUrl : null, getBaseScript);
|
|
123
|
+ const { style } = props;
|
|
124
|
+ const { source, script } = getUpdatedState(props, getBaseScript);
|
127
|
125
|
const height = style ? style.height : null;
|
128
|
126
|
const width = style ? style.width : null;
|
129
|
127
|
if (source.html !== prevSource.html || source.uri !== prevSource.uri || script !== prevScript) {
|