iou90 4 years ago
parent
commit
68fd3d44ed
2 changed files with 15 additions and 4 deletions
  1. 1
    2
      autoHeightWebView/index.js
  2. 14
    2
      autoHeightWebView/utils.js

+ 1
- 2
autoHeightWebView/index.js View File

@@ -48,12 +48,11 @@ const AutoHeightWebView = React.memo(
48 48
       const { height, width, zoomedin } = data;
49 49
       !scrollEnabled && scrollEnabledWithZoomedin && setScrollable(!!zoomedin);
50 50
       const { height: previousHeight, width: previousWidth } = size;
51
-      !zoomedin && webView.current.zoomedin === zoomedin && isSizeChanged({ height, previousHeight, width, previousWidth }) &&
51
+      isSizeChanged({ height, previousHeight, width, previousWidth }) &&
52 52
         setSize({
53 53
           height,
54 54
           width
55 55
         });
56
-      webView.current.zoomedin = zoomedin;
57 56
     };
58 57
 
59 58
     const currentScrollEnabled = scrollEnabled === false && scrollEnabledWithZoomedin ? scrollable : scrollEnabled;

+ 14
- 2
autoHeightWebView/utils.js View File

@@ -1,6 +1,6 @@
1 1
 'use strict';
2 2
 
3
-import { Dimensions, Platform } from 'react-native';
3
+import { Dimensions } from 'react-native';
4 4
 
5 5
 const domMutationObserveScript = `
6 6
   var MutationObserver =
@@ -22,6 +22,9 @@ const updateSizeWithMessage = (element, scalesPageToFit) =>
22 22
   var checkPostMessageTimeout;
23 23
 
24 24
   function updateSize(event) {
25
+    if (zoomedin || scaling) {
26
+      return;
27
+    }
25 28
     if (
26 29
       !window.hasOwnProperty('ReactNativeWebView') || 
27 30
       !window.ReactNativeWebView.hasOwnProperty('postMessage')
@@ -69,14 +72,23 @@ const setViewportContent = content => {
69 72
 const detectZoomChanged = `
70 73
   var zoomedin = false;
71 74
   var latestTapStamp = 0;
72
-  var lastScale = false;
75
+  var lastScale = 1.0;
76
+  var scaling = false;
73 77
   var doubleTapDelay = 400;
74 78
   function detectZoomChanged() {
75 79
     var tempZoomedin = (screen.width / window.innerWidth) > 1;
76 80
     tempZoomedin !== zoomedin && window.ReactNativeWebView.postMessage(JSON.stringify({ zoomedin: tempZoomedin }));
77 81
     zoomedin = tempZoomedin;
78 82
   }
83
+  window.addEventListener('ontouchstart', event => {
84
+    if (event.touches.length === 2) {
85
+      scaling = true;
86
+    }
87
+  })
79 88
   window.addEventListener('touchend', event => {
89
+    if(scaling) {
90
+      scaleing = false;
91
+    }
80 92
     var tempScale = event.scale; 
81 93
     tempScale !== lastScale && detectZoomChanged();
82 94
     lastScale = tempScale;