Example usage for com.facebook.react.views.scroll ReactScrollViewHelper emitScrollMomentumEndEvent

List of usage examples for com.facebook.react.views.scroll ReactScrollViewHelper emitScrollMomentumEndEvent

Introduction

In this page you can find the example usage for com.facebook.react.views.scroll ReactScrollViewHelper emitScrollMomentumEndEvent.

Prototype

public static void emitScrollMomentumEndEvent(ViewGroup scrollView) 

Source Link

Usage

From source file:com.rnnestedscrollview.ReactNestedScrollView.java

License:MIT License

/**
 * This handles any sort of scrolling that may occur after a touch is finished.  This may be
 * momentum scrolling (fling) or because you have pagingEnabled on the scroll view.  Because we
 * don't get any events from Android about this lifecycle, we do all our detection by creating a
 * runnable that checks if we scrolled in the last frame and if so assumes we are still scrolling.
 *///from ww  w  .ja  v a  2  s. co  m
private void handlePostTouchScrolling(int velocityX, int velocityY) {
    // If we aren't going to do anything (send events or snap to page), we can early exit out.
    if (!mSendMomentumEvents && !mPagingEnabled && !isScrollPerfLoggingEnabled()) {
        return;
    }

    // Check if we are already handling this which may occur if this is called by both the touch up
    // and a fling call
    if (mPostTouchRunnable != null) {
        return;
    }

    if (mSendMomentumEvents) {
        enableFpsListener();
        ReactScrollViewHelper.emitScrollMomentumBeginEvent(this, velocityX, velocityY);
    }

    mActivelyScrolling = false;
    mPostTouchRunnable = new Runnable() {

        private boolean mSnappingToPage = false;

        @Override
        public void run() {
            if (mActivelyScrolling) {
                // We are still scrolling so we just post to check again a frame later
                mActivelyScrolling = false;
                ViewCompat.postOnAnimationDelayed(ReactNestedScrollView.this, this,
                        ReactScrollViewHelper.MOMENTUM_DELAY);
            } else {
                if (mPagingEnabled && !mSnappingToPage) {
                    // Only if we have pagingEnabled and we have not snapped to the page do we
                    // need to continue checking for the scroll.  And we cause that scroll by asking for it
                    mSnappingToPage = true;
                    flingAndSnap(0);
                    ViewCompat.postOnAnimationDelayed(ReactNestedScrollView.this, this,
                            ReactScrollViewHelper.MOMENTUM_DELAY);
                } else {
                    if (mSendMomentumEvents) {
                        ReactScrollViewHelper.emitScrollMomentumEndEvent(ReactNestedScrollView.this);
                    }
                    ReactNestedScrollView.this.mPostTouchRunnable = null;
                    disableFpsListener();
                }
            }
        }
    };
    ViewCompat.postOnAnimationDelayed(ReactNestedScrollView.this, mPostTouchRunnable,
            ReactScrollViewHelper.MOMENTUM_DELAY);
}

From source file:com.zulipmobile.AnchorScrollView.java

License:Open Source License

@Override
public void fling(int velocityY) {
    if (mScroller != null) {
        // FB SCROLLVIEW CHANGE

        // We provide our own version of fling that uses a different call to the standard OverScroller
        // which takes into account the possibility of adding new content while the ScrollView is
        // animating. Because we give essentially no max Y for the fling, the fling will continue as long
        // as there is content. See #onOverScrolled() to see the second part of this change which properly
        // aborts the scroller animation when we get to the bottom of the ScrollView content.

        int scrollWindowHeight = getHeight() - getPaddingBottom() - getPaddingTop();

        mScroller.fling(getScrollX(), getScrollY(), 0, velocityY, 0, 0, 0, Integer.MAX_VALUE, 0,
                scrollWindowHeight / 2);

        postInvalidateOnAnimation();//  w  w  w  .j  ava 2  s.co m

        // END FB SCROLLVIEW CHANGE
    } else {
        super.fling(velocityY);
    }

    if (mSendMomentumEvents || isScrollPerfLoggingEnabled()) {
        mFlinging = true;
        enableFpsListener();
        ReactScrollViewHelper.emitScrollMomentumBeginEvent(this);
        Runnable r = new Runnable() {
            @Override
            public void run() {
                if (mDoneFlinging) {
                    mFlinging = false;
                    disableFpsListener();
                    ReactScrollViewHelper.emitScrollMomentumEndEvent(AnchorScrollView.this);
                } else {
                    mDoneFlinging = true;
                    AnchorScrollView.this.postOnAnimationDelayed(this, ReactScrollViewHelper.MOMENTUM_DELAY);
                }
            }
        };
        postOnAnimationDelayed(r, ReactScrollViewHelper.MOMENTUM_DELAY);
    }
}