|
@@ -31,6 +31,9 @@ import android.webkit.WebView;
|
31
|
31
|
import android.webkit.WebViewClient;
|
32
|
32
|
import android.widget.FrameLayout;
|
33
|
33
|
|
|
34
|
+import com.facebook.react.views.scroll.ScrollEvent;
|
|
35
|
+import com.facebook.react.views.scroll.ScrollEventType;
|
|
36
|
+import com.facebook.react.views.scroll.OnScrollDispatchHelper;
|
34
|
37
|
import com.facebook.react.bridge.Arguments;
|
35
|
38
|
import com.facebook.react.bridge.LifecycleEventListener;
|
36
|
39
|
import com.facebook.react.bridge.ReactContext;
|
|
@@ -446,6 +449,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
446
|
449
|
}
|
447
|
450
|
export.put(TopLoadingProgressEvent.EVENT_NAME, MapBuilder.of("registrationName", "onLoadingProgress"));
|
448
|
451
|
export.put(TopShouldStartLoadWithRequestEvent.EVENT_NAME, MapBuilder.of("registrationName", "onShouldStartLoadWithRequest"));
|
|
452
|
+ export.put(ScrollEventType.SCROLL.getJSEventName(), MapBuilder.of("registrationName", "onScroll"));
|
449
|
453
|
return export;
|
450
|
454
|
}
|
451
|
455
|
|
|
@@ -780,6 +784,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
780
|
784
|
protected @Nullable
|
781
|
785
|
RNCWebViewClient mRNCWebViewClient;
|
782
|
786
|
protected boolean sendContentSizeChangeEvents = false;
|
|
787
|
+ private final OnScrollDispatchHelper mOnScrollDispatchHelper = new OnScrollDispatchHelper();
|
783
|
788
|
|
784
|
789
|
/**
|
785
|
790
|
* WebView must be created with an context of the current activity
|
|
@@ -886,6 +891,26 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
886
|
891
|
dispatchEvent(this, new TopMessageEvent(this.getId(), message));
|
887
|
892
|
}
|
888
|
893
|
|
|
894
|
+ protected void onScrollChanged(int x, int y, int oldX, int oldY) {
|
|
895
|
+ super.onScrollChanged(x, y, oldX, oldY);
|
|
896
|
+
|
|
897
|
+ if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
|
|
898
|
+ ScrollEvent event = ScrollEvent.obtain(
|
|
899
|
+ this.getId(),
|
|
900
|
+ ScrollEventType.SCROLL,
|
|
901
|
+ x,
|
|
902
|
+ y,
|
|
903
|
+ mOnScrollDispatchHelper.getXFlingVelocity(),
|
|
904
|
+ mOnScrollDispatchHelper.getYFlingVelocity(),
|
|
905
|
+ this.computeHorizontalScrollRange(),
|
|
906
|
+ this.computeVerticalScrollRange(),
|
|
907
|
+ this.getWidth(),
|
|
908
|
+ this.getHeight());
|
|
909
|
+
|
|
910
|
+ dispatchEvent(this, event);
|
|
911
|
+ }
|
|
912
|
+ }
|
|
913
|
+
|
889
|
914
|
protected void cleanupCallbacksAndDestroy() {
|
890
|
915
|
setWebViewClient(null);
|
891
|
916
|
destroy();
|