Skip to content

Updated for react-native 0.47.2 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.facebook.react.common.ReactConstants;
import com.facebook.react.views.scroll.FpsListener;
import com.facebook.react.views.scroll.OnScrollDispatchHelper;
import com.facebook.react.views.scroll.VelocityHelper;
import com.facebook.react.uimanager.MeasureSpecAssertions;
import com.facebook.react.uimanager.events.NativeGestureUtil;
import com.facebook.react.uimanager.ReactClippingViewGroup;
Expand All @@ -53,6 +54,7 @@ public class ReactNestedScrollView extends NestedScrollView implements ReactClip

private final OnScrollDispatchHelper mOnScrollDispatchHelper = new OnScrollDispatchHelper();
private final OverScroller mScroller;
private final VelocityHelper mVelocityHelper = new VelocityHelper();

private @Nullable Rect mClippingRect;
private boolean mDoneFlinging;
Expand Down Expand Up @@ -153,20 +155,23 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// }

@Override
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);

if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
if (mRemoveClippedSubviews) {
updateClippingRect();
}
if (mRemoveClippedSubviews) {
updateClippingRect();
}

if (mFlinging) {
mDoneFlinging = false;
}
if (mFlinging) {
mDoneFlinging = false;
}

ReactNestedScrollViewHelper.emitScrollEvent(this);
}
ReactNestedScrollViewHelper.emitScrollEvent(
this,
mOnScrollDispatchHelper.getXFlingVelocity(),
mOnScrollDispatchHelper.getYFlingVelocity());
}
}

@Override
Expand All @@ -187,17 +192,22 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
public boolean onTouchEvent(MotionEvent ev) {
if (!mScrollEnabled) {
return false;
return false;
}

mVelocityHelper.calculateVelocity(ev);
int action = ev.getAction() & MotionEvent.ACTION_MASK;
if (action == MotionEvent.ACTION_UP && mDragging) {
ReactNestedScrollViewHelper.emitScrollEndDragEvent(this);
mDragging = false;
disableFpsListener();
ReactNestedScrollViewHelper.emitScrollEndDragEvent(
this,
mVelocityHelper.getXVelocity(),
mVelocityHelper.getYVelocity());
mDragging = false;
disableFpsListener();
}

return super.onTouchEvent(ev);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,46 @@ public class ReactNestedScrollViewHelper {
public static final String AUTO = "auto";
public static final String OVER_SCROLL_NEVER = "never";


/**
* Shared by {@link ReactScrollView} and {@link ReactHorizontalScrollView}.
*/
public static void emitScrollEvent(ViewGroup scrollView) {
emitScrollEvent(scrollView, ScrollEventType.SCROLL);
public static void emitScrollEvent(ViewGroup scrollView, float xVelocity, float yVelocity) {
emitScrollEvent(scrollView, ScrollEventType.SCROLL, xVelocity, yVelocity);
}

public static void emitScrollBeginDragEvent(ViewGroup scrollView) {
emitScrollEvent(scrollView, ScrollEventType.BEGIN_DRAG);
emitScrollEvent(scrollView, ScrollEventType.BEGIN_DRAG);
}

public static void emitScrollEndDragEvent(ViewGroup scrollView) {
emitScrollEvent(scrollView, ScrollEventType.END_DRAG);
public static void emitScrollEndDragEvent(
ViewGroup scrollView,
float xVelocity,
float yVelocity) {
emitScrollEvent(scrollView, ScrollEventType.END_DRAG, xVelocity, yVelocity);
}

public static void emitScrollMomentumBeginEvent(ViewGroup scrollView) {
emitScrollEvent(scrollView, ScrollEventType.MOMENTUM_BEGIN);
emitScrollEvent(scrollView, ScrollEventType.MOMENTUM_BEGIN);
}

public static void emitScrollMomentumEndEvent(ViewGroup scrollView) {
emitScrollEvent(scrollView, ScrollEventType.MOMENTUM_END);
emitScrollEvent(scrollView, ScrollEventType.MOMENTUM_END);
}

private static void emitScrollEvent(ViewGroup scrollView, ScrollEventType scrollEventType) {
emitScrollEvent(scrollView, scrollEventType, 0, 0);
}

private static void emitScrollEvent(
ViewGroup scrollView,
ScrollEventType scrollEventType,
float xVelocity,
float yVelocity) {
View contentView = scrollView.getChildAt(0);

if (contentView == null) {
return;
return;
}

ReactContext reactContext = (ReactContext) scrollView.getContext();
Expand All @@ -68,6 +80,8 @@ private static void emitScrollEvent(ViewGroup scrollView, ScrollEventType scroll
scrollEventType,
scrollView.getScrollX(),
scrollView.getScrollY(),
xVelocity,
yVelocity,
contentView.getWidth(),
contentView.getHeight(),
scrollView.getWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactAppli
return Collections.emptyList();
}

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactApplicationContext) {
Expand Down