|
@@ -25,7 +25,8 @@ import {
|
25
|
25
|
getWidth,
|
26
|
26
|
getScript,
|
27
|
27
|
domMutationObserveScript,
|
28
|
|
- getCurrentSize
|
|
28
|
+ getCurrentSize,
|
|
29
|
+ getRenderSize
|
29
|
30
|
} from './common.js';
|
30
|
31
|
|
31
|
32
|
const RCTAutoHeightWebView = requireNativeComponent('RCTAutoHeightWebView', AutoHeightWebView, {
|
|
@@ -47,6 +48,7 @@ const getUpdatedState = momoize(setState, isEqual);
|
47
|
48
|
|
48
|
49
|
export default class AutoHeightWebView extends PureComponent {
|
49
|
50
|
static propTypes = {
|
|
51
|
+ onNavigationStateChange: PropTypes.func,
|
50
|
52
|
onMessage: PropTypes.func,
|
51
|
53
|
scrollEnabled: PropTypes.bool,
|
52
|
54
|
source: WebView.propTypes.source,
|
|
@@ -59,6 +61,7 @@ export default class AutoHeightWebView extends PureComponent {
|
59
|
61
|
scalesPageToFit: PropTypes.bool,
|
60
|
62
|
// only works on enable animation
|
61
|
63
|
animationDuration: PropTypes.number,
|
|
64
|
+ // only on android
|
62
|
65
|
animationEasing: PropTypes.func,
|
63
|
66
|
// offset of rn webView margin
|
64
|
67
|
heightOffset: PropTypes.number,
|
|
@@ -95,18 +98,18 @@ export default class AutoHeightWebView extends PureComponent {
|
95
|
98
|
isBelowKitKat && DeviceEventEmitter.addListener('webViewBridgeMessage', this.listenWebViewBridgeMessage);
|
96
|
99
|
this.finishInterval = true;
|
97
|
100
|
const initWidth = getWidth(style);
|
98
|
|
- const height = style ? (style.height ? style.height : 0) : 0;
|
|
101
|
+ const initHeight = style ? (style.height ? style.height : 0) : 0;
|
99
|
102
|
let state = {
|
100
|
103
|
isSizeChanged: false,
|
101
|
104
|
isSizeMayChange: false,
|
102
|
|
- height: height,
|
|
105
|
+ height: initHeight,
|
103
|
106
|
width: initWidth,
|
104
|
107
|
script: getScript(props, getBaseScript),
|
105
|
108
|
source: enableBaseUrl ? Object.assign({}, source, { baseUrl }) : source
|
106
|
109
|
};
|
107
|
110
|
if (enableAnimation) {
|
108
|
111
|
Object.assign(state, {
|
109
|
|
- heightValue: new Animated.Value(height + heightOffset),
|
|
112
|
+ heightValue: new Animated.Value(initHeight + heightOffset),
|
110
|
113
|
widthValue: new Animated.Value(initWidth)
|
111
|
114
|
});
|
112
|
115
|
}
|
|
@@ -231,8 +234,9 @@ export default class AutoHeightWebView extends PureComponent {
|
231
|
234
|
};
|
232
|
235
|
|
233
|
236
|
onLoadingStart = event => {
|
234
|
|
- const { onLoadStart } = this.props;
|
|
237
|
+ const { onLoadStart, onNavigationStateChange } = this.props;
|
235
|
238
|
onLoadStart && onLoadStart(event);
|
|
239
|
+ onNavigationStateChange && onNavigationStateChange(event.nativeEvent);
|
236
|
240
|
};
|
237
|
241
|
|
238
|
242
|
onLoadingError = event => {
|
|
@@ -243,9 +247,10 @@ export default class AutoHeightWebView extends PureComponent {
|
243
|
247
|
};
|
244
|
248
|
|
245
|
249
|
onLoadingFinish = event => {
|
246
|
|
- const { onLoad, onLoadEnd } = this.props;
|
|
250
|
+ const { onLoad, onLoadEnd, onNavigationStateChange } = this.props;
|
247
|
251
|
onLoad && onLoad(event);
|
248
|
252
|
onLoadEnd && onLoadEnd(event);
|
|
253
|
+ onNavigationStateChange && onNavigationStateChange(event.nativeEvent);
|
249
|
254
|
};
|
250
|
255
|
|
251
|
256
|
stopLoading() {
|
|
@@ -265,10 +270,7 @@ export default class AutoHeightWebView extends PureComponent {
|
265
|
270
|
<Animated.View
|
266
|
271
|
style={[
|
267
|
272
|
styles.container,
|
268
|
|
- {
|
269
|
|
- height: enableAnimation ? heightValue : height ? height + heightOffset : 0,
|
270
|
|
- width: enableAnimation ? widthValue : width
|
271
|
|
- },
|
|
273
|
+ getRenderSize(enableAnimation, height, width, heightOffset, heightValue, widthValue),
|
272
|
274
|
style
|
273
|
275
|
]}
|
274
|
276
|
>
|