fix(performance): Improved `onScroll` to work efficiently on Android (#609)
This commit is contained in:
parent
fab6008dd1
commit
d8743eeed2
|
@ -435,6 +435,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
view.getSettings().setGeolocationEnabled(isGeolocationEnabled != null && isGeolocationEnabled);
|
view.getSettings().setGeolocationEnabled(isGeolocationEnabled != null && isGeolocationEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = "onScroll")
|
||||||
|
public void setOnScroll(WebView view, boolean hasScrollEvent) {
|
||||||
|
((RNCWebView) view).setHasScrollEvent(hasScrollEvent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
|
protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
|
||||||
// Do not register default touch emitter and let WebView implementation handle touches
|
// Do not register default touch emitter and let WebView implementation handle touches
|
||||||
|
@ -784,7 +789,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
protected @Nullable
|
protected @Nullable
|
||||||
RNCWebViewClient mRNCWebViewClient;
|
RNCWebViewClient mRNCWebViewClient;
|
||||||
protected boolean sendContentSizeChangeEvents = false;
|
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
|
* WebView must be created with an context of the current activity
|
||||||
|
@ -800,6 +806,10 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
this.sendContentSizeChangeEvents = sendContentSizeChangeEvents;
|
this.sendContentSizeChangeEvents = sendContentSizeChangeEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHasScrollEvent(boolean hasScrollEvent) {
|
||||||
|
this.hasScrollEvent = hasScrollEvent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHostResume() {
|
public void onHostResume() {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
@ -894,6 +904,14 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
|
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
|
||||||
super.onScrollChanged(x, y, oldX, oldY);
|
super.onScrollChanged(x, y, oldX, oldY);
|
||||||
|
|
||||||
|
if (!hasScrollEvent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mOnScrollDispatchHelper == null) {
|
||||||
|
mOnScrollDispatchHelper = new OnScrollDispatchHelper();
|
||||||
|
}
|
||||||
|
|
||||||
if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
|
if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
|
||||||
ScrollEvent event = ScrollEvent.obtain(
|
ScrollEvent event = ScrollEvent.obtain(
|
||||||
this.getId(),
|
this.getId(),
|
||||||
|
|
Loading…
Reference in New Issue