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:
parent
c1152ca850
commit
6bac272a5f
|
@ -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);
|
||||
|
|
|
@ -51,6 +51,7 @@ This document lays out the current public properties and methods for the React N
|
|||
- [`contentMode`](Reference.md#contentMode)
|
||||
- [`dataDetectorTypes`](Reference.md#datadetectortypes)
|
||||
- [`scrollEnabled`](Reference.md#scrollenabled)
|
||||
- [`nestedScrollEnabled`](Reference.md#nestedscrollenabled)
|
||||
- [`directionalLockEnabled`](Reference.md#directionalLockEnabled)
|
||||
- [`geolocationEnabled`](Reference.md#geolocationenabled)
|
||||
- [`allowFileAccessFromFileURLs`](Reference.md#allowFileAccessFromFileURLs)
|
||||
|
@ -1040,6 +1041,18 @@ Boolean value that determines whether scrolling is enabled in the `WebView`. The
|
|||
|
||||
---
|
||||
|
||||
### `nestedScrollEnabled`[⬆](#props-index)
|
||||
|
||||
Boolean value that determines whether scrolling is possible in the `WebView` when used inside a `ScrollView` on Android. The default value is `false`.
|
||||
|
||||
Setting this to `true` will prevent the `ScrollView` to scroll when scrolling from inside the `WebView`.
|
||||
|
||||
| Type | Required | Platform |
|
||||
| ---- | -------- | ------------- |
|
||||
| bool | No | Android |
|
||||
|
||||
---
|
||||
|
||||
### `directionalLockEnabled`[⬆](#props-index)<!-- Link generated with jump2header -->
|
||||
|
||||
A Boolean value that determines whether scrolling is disabled in a particular direction.
|
||||
|
|
|
@ -64,6 +64,7 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
|||
androidLayerType: 'none',
|
||||
originWhitelist: defaultOriginWhitelist,
|
||||
setSupportMultipleWindows: true,
|
||||
nestedScrollEnabled: false,
|
||||
};
|
||||
|
||||
static isFileUploadSupported = async () => {
|
||||
|
|
|
@ -301,6 +301,7 @@ export interface AndroidNativeWebViewProps extends CommonNativeWebViewProps {
|
|||
textZoom?: number;
|
||||
thirdPartyCookiesEnabled?: boolean;
|
||||
messagingModuleName?: string;
|
||||
nestedScrollEnabled?: boolean;
|
||||
readonly urlPrefixesForDefaultIntent?: string[];
|
||||
}
|
||||
|
||||
|
@ -951,6 +952,15 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
|
|||
* Sets ability to open fullscreen videos on Android devices.
|
||||
*/
|
||||
allowsFullscreenVideo?: boolean;
|
||||
|
||||
/**
|
||||
* Allows to scroll inside the webview when used inside a scrollview.
|
||||
* Behaviour already existing on iOS.
|
||||
* Default to false
|
||||
*
|
||||
* @platform android
|
||||
*/
|
||||
nestedScrollEnabled?: boolean;
|
||||
}
|
||||
|
||||
export interface WebViewSharedProps extends ViewProps {
|
||||
|
|
Loading…
Reference in New Issue