mirror of
https://github.com/status-im/react-native-webview.git
synced 2026-08-31 11:41:08 +00:00
feat: add prop to allow nested scroll on android (#2056)
* feat: add prop to allow nested scroll on android When set to true, this prop allow to scroll inside the webview when the webview is inside a scrollview on android * docs: nestedScrollEnabled prop usage
This commit is contained in:
@@ -19,6 +19,7 @@ import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
@@ -343,6 +344,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
view.setOverScrollMode(overScrollMode);
|
||||
}
|
||||
|
||||
@ReactProp(name = "nestedScrollEnabled")
|
||||
public void setNestedScrollEnabled(WebView view, boolean enabled) {
|
||||
((RNCWebView) view).setNestedScrollEnabled(enabled);
|
||||
}
|
||||
|
||||
@ReactProp(name = "thirdPartyCookiesEnabled")
|
||||
public void setThirdPartyCookiesEnabled(WebView view, boolean enabled) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
@@ -1405,6 +1411,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
protected boolean sendContentSizeChangeEvents = false;
|
||||
private OnScrollDispatchHelper mOnScrollDispatchHelper;
|
||||
protected boolean hasScrollEvent = false;
|
||||
protected boolean nestedScrollEnabled = false;
|
||||
protected ProgressChangedFilter progressChangedFilter;
|
||||
|
||||
/**
|
||||
@@ -1431,6 +1438,10 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
this.hasScrollEvent = hasScrollEvent;
|
||||
}
|
||||
|
||||
public void setNestedScrollEnabled(boolean nestedScrollEnabled) {
|
||||
this.nestedScrollEnabled = nestedScrollEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHostResume() {
|
||||
// do nothing
|
||||
@@ -1446,6 +1457,14 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
cleanupCallbacksAndDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (this.nestedScrollEnabled) {
|
||||
requestDisallowInterceptTouchEvent(true);
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int ow, int oh) {
|
||||
super.onSizeChanged(w, h, ow, oh);
|
||||
|
||||
Reference in New Issue
Block a user