|
@@ -12,7 +12,7 @@ import { reduceData, getWidth, isSizeChanged, shouldUpdate } from './utils';
|
12
|
12
|
|
13
|
13
|
const AutoHeightWebView = React.memo(
|
14
|
14
|
forwardRef((props, ref) => {
|
15
|
|
- const { style, onMessage, onSizeUpdated, source } = props;
|
|
15
|
+ const { style, onMessage, onSizeUpdated, scrollableWhenZoomin, scrollEnabled, source } = props;
|
16
|
16
|
|
17
|
17
|
if (!source) {
|
18
|
18
|
return null;
|
|
@@ -31,6 +31,7 @@ const AutoHeightWebView = React.memo(
|
31
|
31
|
height: style && style.height ? style.height : 0,
|
32
|
32
|
width: getWidth(style)
|
33
|
33
|
});
|
|
34
|
+ const [scrollable, setScrollable] = useState(false);
|
34
|
35
|
const handleMessage = event => {
|
35
|
36
|
onMessage && onMessage(event);
|
36
|
37
|
if (!event.nativeEvent) {
|
|
@@ -44,7 +45,8 @@ const AutoHeightWebView = React.memo(
|
44
|
45
|
console.error(error);
|
45
|
46
|
return;
|
46
|
47
|
}
|
47
|
|
- const { height, width } = data;
|
|
48
|
+ const { height, width, zoomin } = data;
|
|
49
|
+ !scrollEnabled && scrollableWhenZoomin && setScrollable(zoomin);
|
48
|
50
|
const { height: previousHeight, width: previousWidth } = size;
|
49
|
51
|
isSizeChanged({ height, previousHeight, width, previousWidth }) &&
|
50
|
52
|
setSize({
|
|
@@ -53,6 +55,8 @@ const AutoHeightWebView = React.memo(
|
53
|
55
|
});
|
54
|
56
|
};
|
55
|
57
|
|
|
58
|
+ const currentScrollEnabled = scrollEnabled === false && scrollableWhenZoomin ? scrollable : scrollEnabled;
|
|
59
|
+
|
56
|
60
|
const { currentSource, script } = reduceData(props);
|
57
|
61
|
|
58
|
62
|
const { width, height } = size;
|
|
@@ -81,6 +85,7 @@ const AutoHeightWebView = React.memo(
|
81
|
85
|
]}
|
82
|
86
|
injectedJavaScript={script}
|
83
|
87
|
source={currentSource}
|
|
88
|
+ scrollEnabled={currentScrollEnabled}
|
84
|
89
|
/>
|
85
|
90
|
);
|
86
|
91
|
}),
|
|
@@ -89,8 +94,6 @@ const AutoHeightWebView = React.memo(
|
89
|
94
|
|
90
|
95
|
AutoHeightWebView.propTypes = {
|
91
|
96
|
onSizeUpdated: PropTypes.func,
|
92
|
|
- // add files to android/app/src/main/assets/ (depends on baseUrl) on android
|
93
|
|
- // add files to web/ (depends on baseUrl) on iOS
|
94
|
97
|
files: PropTypes.arrayOf(
|
95
|
98
|
PropTypes.shape({
|
96
|
99
|
href: PropTypes.string,
|
|
@@ -102,12 +105,11 @@ AutoHeightWebView.propTypes = {
|
102
|
105
|
customScript: PropTypes.string,
|
103
|
106
|
customStyle: PropTypes.string,
|
104
|
107
|
zoomable: PropTypes.bool,
|
|
108
|
+ scrollableWhenZoomin: PropTypes.bool,
|
105
|
109
|
// webview props
|
106
|
110
|
originWhitelist: PropTypes.arrayOf(PropTypes.string),
|
107
|
111
|
onMessage: PropTypes.func,
|
108
|
|
- // baseUrl now contained by source
|
109
|
|
- // 'web/' by default on iOS
|
110
|
|
- // 'file:///android_asset/' by default on Android
|
|
112
|
+ scalesPageToFit: PropTypes.bool,
|
111
|
113
|
source: PropTypes.object
|
112
|
114
|
};
|
113
|
115
|
|