下面列出了android.support.v4.view.ViewCompat#postOnAnimationDelayed ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Starts the scroll animation.
*/
private void startAnimating() {
if (mRunnable == null) {
mRunnable = new ScrollAnimationRunnable();
}
mAnimating = true;
mNeedsReset = true;
if (!mAlreadyDelayed && mActivationDelay > 0) {
ViewCompat.postOnAnimationDelayed(mTarget, mRunnable, mActivationDelay);
} else {
mRunnable.run();
}
// If we start animating again before the user lifts their finger, we
// already know it's not a tap and don't need an activation delay.
mAlreadyDelayed = true;
}
/**
* Starts the scroll animation.
*/
private void startAnimating() {
if (mRunnable == null) {
mRunnable = new ScrollAnimationRunnable();
}
mAnimating = true;
mNeedsReset = true;
if (!mAlreadyDelayed && mActivationDelay > 0) {
ViewCompat.postOnAnimationDelayed(mTarget, mRunnable, mActivationDelay);
} else {
mRunnable.run();
}
// If we start animating again before the user lifts their finger, we
// already know it's not a tap and don't need an activation delay.
mAlreadyDelayed = true;
}
/**
* Starts the scroll animation.
*/
private void startAnimating() {
if (mRunnable == null) {
mRunnable = new ScrollAnimationRunnable();
}
mAnimating = true;
mNeedsReset = true;
if (!mAlreadyDelayed && mActivationDelay > 0) {
ViewCompat.postOnAnimationDelayed(mTarget, mRunnable, mActivationDelay);
} else {
mRunnable.run();
}
// If we start animating again before the user lifts their finger, we
// already know it's not a tap and don't need an activation delay.
mAlreadyDelayed = true;
}
/**
* Starts the scroll animation.
*/
private void startAnimating() {
if (mRunnable == null) {
mRunnable = new ScrollAnimationRunnable();
}
mAnimating = true;
mNeedsReset = true;
if (!mAlreadyDelayed && mActivationDelay > 0) {
ViewCompat.postOnAnimationDelayed(mTarget, mRunnable, mActivationDelay);
} else {
mRunnable.run();
}
// If we start animating again before the user lifts their finger, we
// already know it's not a tap and don't need an activation delay.
mAlreadyDelayed = true;
}
private void startAnimating() {
if (this.mRunnable == null) {
this.mRunnable = new ScrollAnimationRunnable();
}
this.mAnimating = true;
this.mNeedsReset = true;
if (this.mAlreadyDelayed || this.mActivationDelay <= 0) {
this.mRunnable.run();
} else {
ViewCompat.postOnAnimationDelayed(this.mTarget, this.mRunnable, (long) this.mActivationDelay);
}
this.mAlreadyDelayed = true;
}
/**
* 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.
*/
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(ReactScrollView.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(ReactScrollView.this,
this,
ReactScrollViewHelper.MOMENTUM_DELAY);
} else {
if (mSendMomentumEvents) {
ReactScrollViewHelper.emitScrollMomentumEndEvent(ReactScrollView.this);
}
ReactScrollView.this.mPostTouchRunnable = null;
disableFpsListener();
}
}
}
};
ViewCompat.postOnAnimationDelayed(ReactScrollView.this,
mPostTouchRunnable,
ReactScrollViewHelper.MOMENTUM_DELAY);
}
/**
* 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.
*/
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) {
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(ReactHorizontalScrollView.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(ReactHorizontalScrollView.this,
this,
ReactScrollViewHelper.MOMENTUM_DELAY);
} else {
if (mSendMomentumEvents) {
ReactScrollViewHelper.emitScrollMomentumEndEvent(ReactHorizontalScrollView.this);
}
ReactHorizontalScrollView.this.mPostTouchRunnable = null;
disableFpsListener();
}
}
}
};
ViewCompat.postOnAnimationDelayed(ReactHorizontalScrollView.this,
mPostTouchRunnable,
ReactScrollViewHelper.MOMENTUM_DELAY);
}