diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index fcc6464..f5862d4 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -435,6 +435,11 @@ public class RNCWebViewManager extends SimpleViewManager { view.getSettings().setGeolocationEnabled(isGeolocationEnabled != null && isGeolocationEnabled); } + @ReactProp(name = "onScroll") + public void setOnScroll(WebView view, boolean hasScrollEvent) { + ((RNCWebView) view).setHasScrollEvent(hasScrollEvent); + } + @Override protected void addEventEmitters(ThemedReactContext reactContext, WebView view) { // Do not register default touch emitter and let WebView implementation handle touches @@ -784,7 +789,8 @@ public class RNCWebViewManager extends SimpleViewManager { protected @Nullable RNCWebViewClient mRNCWebViewClient; protected boolean sendContentSizeChangeEvents = false; - private final OnScrollDispatchHelper mOnScrollDispatchHelper = new OnScrollDispatchHelper(); + private OnScrollDispatchHelper mOnScrollDispatchHelper; + protected boolean hasScrollEvent = false; /** * WebView must be created with an context of the current activity @@ -800,6 +806,10 @@ public class RNCWebViewManager extends SimpleViewManager { this.sendContentSizeChangeEvents = sendContentSizeChangeEvents; } + public void setHasScrollEvent(boolean hasScrollEvent) { + this.hasScrollEvent = hasScrollEvent; + } + @Override public void onHostResume() { // do nothing @@ -894,6 +904,14 @@ public class RNCWebViewManager extends SimpleViewManager { protected void onScrollChanged(int x, int y, int oldX, int oldY) { super.onScrollChanged(x, y, oldX, oldY); + if (!hasScrollEvent) { + return; + } + + if (mOnScrollDispatchHelper == null) { + mOnScrollDispatchHelper = new OnScrollDispatchHelper(); + } + if (mOnScrollDispatchHelper.onScrollChanged(x, y)) { ScrollEvent event = ScrollEvent.obtain( this.getId(),