iou90 4 år sedan
förälder
incheckning
68fd3d44ed
2 ändrade filer med 15 tillägg och 4 borttagningar
  1. 1
    2
      autoHeightWebView/index.js
  2. 14
    2
      autoHeightWebView/utils.js

+ 1
- 2
autoHeightWebView/index.js Visa fil

48
       const { height, width, zoomedin } = data;
48
       const { height, width, zoomedin } = data;
49
       !scrollEnabled && scrollEnabledWithZoomedin && setScrollable(!!zoomedin);
49
       !scrollEnabled && scrollEnabledWithZoomedin && setScrollable(!!zoomedin);
50
       const { height: previousHeight, width: previousWidth } = size;
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
         setSize({
52
         setSize({
53
           height,
53
           height,
54
           width
54
           width
55
         });
55
         });
56
-      webView.current.zoomedin = zoomedin;
57
     };
56
     };
58
 
57
 
59
     const currentScrollEnabled = scrollEnabled === false && scrollEnabledWithZoomedin ? scrollable : scrollEnabled;
58
     const currentScrollEnabled = scrollEnabled === false && scrollEnabledWithZoomedin ? scrollable : scrollEnabled;

+ 14
- 2
autoHeightWebView/utils.js Visa fil

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