|
@@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
|
8
|
8
|
|
9
|
9
|
import { WebView } from 'react-native-webview';
|
10
|
10
|
|
11
|
|
-import { getMemoInputProps, getMemoResult, getWidth, isSizeChanged } from './utils';
|
|
11
|
+import { getMemoResult, getWidth, isSizeChanged } from './utils';
|
12
|
12
|
|
13
|
13
|
const AutoHeightWebView = forwardRef((props, ref) => {
|
14
|
14
|
let webView = useRef();
|
|
@@ -20,7 +20,7 @@ const AutoHeightWebView = forwardRef((props, ref) => {
|
20
|
20
|
injectJavaScript: script => webView.current.injectJavaScript(script)
|
21
|
21
|
}));
|
22
|
22
|
|
23
|
|
- const { style, onMessage, onSizeUpdated } = props;
|
|
23
|
+ const { style, onMessage, onSizeUpdated, source, baseUrl, files, customStyle, customScript, zoomable } = props;
|
24
|
24
|
|
25
|
25
|
const [size, setSize] = useState(() => ({
|
26
|
26
|
height: style && style.height ? style.height : 0,
|
|
@@ -48,7 +48,10 @@ const AutoHeightWebView = forwardRef((props, ref) => {
|
48
|
48
|
onMessage && onMessage(event);
|
49
|
49
|
};
|
50
|
50
|
|
51
|
|
- const { source, script } = useMemo(() => getMemoResult(props), [getMemoInputProps(props)]);
|
|
51
|
+ const { currentSource, script } = useMemo(
|
|
52
|
+ () => getMemoResult({ source, baseUrl, files, customStyle, customScript, zoomable }),
|
|
53
|
+ [source, baseUrl, files, customStyle, customScript, zoomable]
|
|
54
|
+ );
|
52
|
55
|
|
53
|
56
|
const { width, height } = size;
|
54
|
57
|
useEffect(
|
|
@@ -58,8 +61,9 @@ const AutoHeightWebView = forwardRef((props, ref) => {
|
58
|
61
|
height,
|
59
|
62
|
width
|
60
|
63
|
}),
|
61
|
|
- [width, height]
|
|
64
|
+ [width, height, onSizeUpdated]
|
62
|
65
|
);
|
|
66
|
+
|
63
|
67
|
return (
|
64
|
68
|
<WebView
|
65
|
69
|
{...props}
|
|
@@ -74,7 +78,7 @@ const AutoHeightWebView = forwardRef((props, ref) => {
|
74
|
78
|
style
|
75
|
79
|
]}
|
76
|
80
|
injectedJavaScript={script}
|
77
|
|
- source={source}
|
|
81
|
+ source={currentSource}
|
78
|
82
|
/>
|
79
|
83
|
);
|
80
|
84
|
});
|
|
@@ -96,10 +100,11 @@ AutoHeightWebView.propTypes = {
|
96
|
100
|
style: ViewPropTypes.style,
|
97
|
101
|
customScript: PropTypes.string,
|
98
|
102
|
customStyle: PropTypes.string,
|
|
103
|
+ zoomable: PropTypes.bool,
|
99
|
104
|
// webview props
|
100
|
105
|
originWhitelist: PropTypes.arrayOf(PropTypes.string),
|
101
|
106
|
onMessage: PropTypes.func,
|
102
|
|
- zoomable: PropTypes.bool,
|
|
107
|
+ source: PropTypes.object
|
103
|
108
|
};
|
104
|
109
|
|
105
|
110
|
let defaultProps = {
|
|
@@ -107,7 +112,7 @@ let defaultProps = {
|
107
|
112
|
showsHorizontalScrollIndicator: false,
|
108
|
113
|
originWhitelist: ['*'],
|
109
|
114
|
baseUrl: 'web/',
|
110
|
|
- zoomable: true,
|
|
115
|
+ zoomable: true
|
111
|
116
|
};
|
112
|
117
|
|
113
|
118
|
Platform.OS === 'android' &&
|