@Override public void onPageScrollStateChanged(int scrollState) { if (hardwaredDisabled) { hardwaredDisabled = false; enableHWAcceleration(nativeView); } mPager.requestDisallowInterceptTouchEvent(scrollState != ViewPager.SCROLL_STATE_IDLE); if (scrollState == ViewPager.SCROLL_STATE_DRAGGING) { updateCurrentPageDuringScroll = true; ((ScrollableViewProxy) proxy).fireScrollStart(mCurIndex, mViews.get(mCurIndex)); } else if ((scrollState == ViewPager.SCROLL_STATE_IDLE) && isValidScroll) { int oldIndex = mCurIndex; { updateCurrentPageDuringScroll = false; ((ScrollableViewProxy) proxy).fireScrollEnd(mCurIndex, mViews.get(mCurIndex)); } if (mCurIndex >= 0) { // if (oldIndex >=0 && oldIndex != mCurIndex && oldIndex < mViews.size()) { // // Don't know what these focused and unfocused // // events are good for, but they were in our previous // // scrollable implementation. // // cf. // https://github.com/appcelerator/titanium_mobile/blob/20335d8603e2708b59a18bafbb91b7292278de8e/android/modules/ui/src/ti/modules/titanium/ui/widget/TiScrollableView.java#L260 // TiEventHelper.fireFocused(mViews.get(oldIndex)); // } // // TiEventHelper.fireUnfocused(mViews.get(mCurIndex)); if (oldIndex >= 0) { // oldIndex will be -1 if the view has just // been created and is setting currentPage // to something other than 0. In that case we // don't want a `scrollend` to fire. ((ScrollableViewProxy) proxy).fireScrollEnd(mCurIndex, mViews.get(mCurIndex)); } if (shouldShowPager()) { showPager(); } } // If we don't use this state variable to check if it's a valid // scroll, this event will fire when the view is first created // because on creation, the scroll state is initialized to // `idle` and this handler is called. isValidScroll = false; } else if (scrollState == ViewPager.SCROLL_STATE_SETTLING) { updateCurrentPageDuringScroll = false; ((ScrollableViewProxy) proxy).fireDragEnd(mCurIndex, mViews.get(mCurIndex)); // Note that we just fired a `dragend` so the `onPageSelected` // handler below doesn't fire a `scrollend`. Read below comment. justFiredDragEnd = true; } }
@Override public void onPageSelected(int page) { setCurrentPageIndex(page, true); updateCurrentPageDuringScroll = false; // If we didn't just fire a `dragend` event then this is the case // where a user drags the view and settles it on a different view. // Since the OS settling logic is never run, the // `onPageScrollStateChanged` handler is never run, and therefore // we forgot to inform the Javascripters that the user just scrolled // their thing. if (!justFiredDragEnd && mCurIndex != -1 && mCurIndex < mViews.size()) { ((ScrollableViewProxy) proxy).fireScrollEnd(mCurIndex, mViews.get(mCurIndex)); if (shouldShowPager()) { showPager(); } } }