Explorar el Código

fix(android): Allow scrolling inside ScrollView (#281)

masako-yamada hace 4 años
padre
commit
a5cb7ba65c

+ 19
- 1
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java Ver fichero

16
 import androidx.annotation.RequiresApi;
16
 import androidx.annotation.RequiresApi;
17
 import androidx.core.content.ContextCompat;
17
 import androidx.core.content.ContextCompat;
18
 import android.text.TextUtils;
18
 import android.text.TextUtils;
19
+import android.view.MotionEvent;
19
 import android.view.Gravity;
20
 import android.view.Gravity;
20
 import android.view.View;
21
 import android.view.View;
21
 import android.view.ViewGroup;
22
 import android.view.ViewGroup;
363
   public void setMessagingEnabled(WebView view, boolean enabled) {
364
   public void setMessagingEnabled(WebView view, boolean enabled) {
364
     ((RNCWebView) view).setMessagingEnabled(enabled);
365
     ((RNCWebView) view).setMessagingEnabled(enabled);
365
   }
366
   }
366
-   
367
+
367
   @ReactProp(name = "incognito")
368
   @ReactProp(name = "incognito")
368
   public void setIncognito(WebView view, boolean enabled) {
369
   public void setIncognito(WebView view, boolean enabled) {
369
     // Remove all previous cookies
370
     // Remove all previous cookies
910
       this.hasScrollEvent = hasScrollEvent;
911
       this.hasScrollEvent = hasScrollEvent;
911
     }
912
     }
912
 
913
 
914
+    @Override
915
+    public boolean onTouchEvent(MotionEvent event){
916
+
917
+      // Allow scrolling inside ScrollView
918
+      if (event.findPointerIndex(0) == -1) {
919
+        return super.onTouchEvent(event);
920
+      }
921
+
922
+      if (event.getPointerCount() >= 1) {
923
+        requestDisallowInterceptTouchEvent(true);
924
+      } else {
925
+        requestDisallowInterceptTouchEvent(false);
926
+      }
927
+
928
+      return super.onTouchEvent(event);
929
+    }
930
+
913
     @Override
931
     @Override
914
     public void onHostResume() {
932
     public void onHostResume() {
915
       // do nothing
933
       // do nothing