浏览代码

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

masako-yamada 5 年前
父节点
当前提交
a5cb7ba65c
共有 1 个文件被更改,包括 19 次插入1 次删除
  1. 19
    1
      android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java

+ 19
- 1
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java 查看文件

@@ -16,6 +16,7 @@ import android.os.Environment;
16 16
 import androidx.annotation.RequiresApi;
17 17
 import androidx.core.content.ContextCompat;
18 18
 import android.text.TextUtils;
19
+import android.view.MotionEvent;
19 20
 import android.view.Gravity;
20 21
 import android.view.View;
21 22
 import android.view.ViewGroup;
@@ -363,7 +364,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
363 364
   public void setMessagingEnabled(WebView view, boolean enabled) {
364 365
     ((RNCWebView) view).setMessagingEnabled(enabled);
365 366
   }
366
-   
367
+
367 368
   @ReactProp(name = "incognito")
368 369
   public void setIncognito(WebView view, boolean enabled) {
369 370
     // Remove all previous cookies
@@ -910,6 +911,23 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
910 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 931
     @Override
914 932
     public void onHostResume() {
915 933
       // do nothing