Merge pull request #15399 from geemedia/pageview-turning-time-configurable

Make PageView page turning event time tweak configurable.
This commit is contained in:
zilongshanren 2016-04-11 04:50:46 -05:00
commit abfce2617e
3 changed files with 16 additions and 2 deletions

View File

@ -38,7 +38,8 @@ _currentPageIndex(-1),
_childFocusCancelOffset(5.0f), _childFocusCancelOffset(5.0f),
_pageViewEventListener(nullptr), _pageViewEventListener(nullptr),
_pageViewEventSelector(nullptr), _pageViewEventSelector(nullptr),
_eventCallback(nullptr) _eventCallback(nullptr),
_autoScrollStopEpsilon(0.001f)
{ {
} }
@ -177,6 +178,11 @@ bool PageView::isUsingCustomScrollThreshold()const
return false; return false;
} }
void PageView::setAutoScrollStopEpsilon(float epsilon)
{
_autoScrollStopEpsilon = epsilon;
}
void PageView::moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack) void PageView::moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack)
{ {
ListView::moveInnerContainer(deltaMove, canStartBounceBack); ListView::moveInnerContainer(deltaMove, canStartBounceBack);
@ -263,7 +269,7 @@ void PageView::handleReleaseLogic(Touch *touch)
float PageView::getAutoScrollStopEpsilon() const float PageView::getAutoScrollStopEpsilon() const
{ {
return 0.001; return _autoScrollStopEpsilon;
} }
void PageView::pageTurningEvent() void PageView::pageTurningEvent()

View File

@ -341,6 +341,8 @@ public:
*/ */
CC_DEPRECATED_ATTRIBUTE bool isUsingCustomScrollThreshold()const; CC_DEPRECATED_ATTRIBUTE bool isUsingCustomScrollThreshold()const;
void setAutoScrollStopEpsilon(float epsilon);
CC_CONSTRUCTOR_ACCESS: CC_CONSTRUCTOR_ACCESS:
virtual bool init() override; virtual bool init() override;
@ -384,6 +386,7 @@ protected:
#pragma warning (pop) #pragma warning (pop)
#endif #endif
ccPageViewCallback _eventCallback; ccPageViewCallback _eventCallback;
float _autoScrollStopEpsilon;
}; };
} }

View File

@ -545,6 +545,11 @@ void ScrollView::processAutoScrolling(float deltaTime)
Vec2 newPosition = _autoScrollStartPosition + (_autoScrollTargetDelta * percentage); Vec2 newPosition = _autoScrollStartPosition + (_autoScrollTargetDelta * percentage);
bool reachedEnd = fabs(percentage - 1) <= this->getAutoScrollStopEpsilon(); bool reachedEnd = fabs(percentage - 1) <= this->getAutoScrollStopEpsilon();
if (reachedEnd)
{
newPosition = _autoScrollStartPosition + _autoScrollTargetDelta;
}
if(_bounceEnabled) if(_bounceEnabled)
{ {
// The new position is adjusted if out of boundary // The new position is adjusted if out of boundary