@@ -34,6 +34,7 @@ public class SwipeTouchHelper implements ISwipeTouchHelper {
3434 private StackCardsView mSwipeView ;
3535 private float mCurProgress ;
3636 private ValueAnimator mSmoothUpdater ;
37+ private ManualDisappearUpdateListener mManualUpdateListener ;
3738 private float mLastX ;
3839 private float mLastY ;
3940 private float mInitDownX ;
@@ -247,6 +248,10 @@ private void performDrag(float dx, float dy) {
247248 if (mSmoothUpdater != null && mSmoothUpdater .isRunning ()) {
248249 mSmoothUpdater .end ();
249250 }
251+ if (mManualUpdateListener != null ) {
252+ mManualUpdateListener .end ();
253+ mManualUpdateListener = null ;
254+ }
250255 mTouchChild .setX (mTouchChild .getX () + dx );
251256 mTouchChild .setY (mTouchChild .getY () + dy );
252257 final StackCardsView .LayoutParams lp = (StackCardsView .LayoutParams ) mTouchChild .getLayoutParams ();
@@ -286,6 +291,13 @@ private void doManualDisappear(final int direction) {
286291 if (mTouchChild == null ) {
287292 return ;
288293 }
294+ if (mSmoothUpdater != null && mSmoothUpdater .isRunning ()) {
295+ mSmoothUpdater .end ();
296+ }
297+ if (mManualUpdateListener != null ) {
298+ mManualUpdateListener .end ();
299+ mManualUpdateListener = null ;
300+ }
289301 mDisappearingCnt ++;
290302 final View disappearView = mTouchChild ;
291303 mSwipeView .tryAppendChild ();
@@ -337,16 +349,34 @@ public void onAnimationStart(Animator animation) {
337349 mSwipeView .onCoverStatusChanged (false );
338350 }
339351 });
340- animator .addUpdateListener (new ValueAnimator .AnimatorUpdateListener () {
341- @ Override
342- public void onAnimationUpdate (ValueAnimator animation ) {
343- onCoverScrolled (disappearView );
344- }
345- });
352+ mManualUpdateListener = new ManualDisappearUpdateListener (disappearView );
353+ animator .addUpdateListener (mManualUpdateListener );
346354 animator .start ();
347355 }
348356 }
349357
358+ private class ManualDisappearUpdateListener implements ValueAnimator .AnimatorUpdateListener {
359+
360+ View disappearView ;
361+ boolean isCanceled ;
362+
363+ ManualDisappearUpdateListener (View disappearView ) {
364+ this .disappearView = disappearView ;
365+ }
366+
367+ @ Override
368+ public void onAnimationUpdate (ValueAnimator animation ) {
369+ if (!isCanceled ) {
370+ onCoverScrolled (disappearView );
371+ }
372+ }
373+
374+ void end (){
375+ isCanceled = true ;
376+ mSwipeView .onChildScrolling (1 , disappearView );
377+ }
378+ }
379+
350380 private void doSlowDisappear () {
351381 if (mTouchChild == null ) {
352382 return ;
@@ -453,7 +483,7 @@ private void smoothUpdatePosition(final View startView) {
453483 mSmoothUpdater .addUpdateListener (new ValueAnimator .AnimatorUpdateListener () {
454484 @ Override
455485 public void onAnimationUpdate (ValueAnimator animation ) {
456- mSwipeView .updateChildrenPosition ((float ) animation .getAnimatedValue (), mSwipeView . indexOfChild ( startView ) );
486+ mSwipeView .updateChildrenPosition ((float ) animation .getAnimatedValue (), startView );
457487 }
458488 });
459489 mSmoothUpdater .start ();
@@ -478,6 +508,10 @@ private boolean doFastDisappear(float vx, float vy) {
478508
479509 mSwipeView .tryAppendChild ();
480510 updateTouchChild ();
511+ if (mManualUpdateListener != null ) {
512+ mManualUpdateListener .end ();
513+ mManualUpdateListener = null ;
514+ }
481515 smoothUpdatePosition (mTouchChild );
482516
483517 float dx = disappearView .getX () - initX ;
@@ -571,13 +605,12 @@ private void onCoverScrolled(View movingView) {
571605 float dy = movingView .getY () - mChildInitY ;
572606 double distance = Math .sqrt (dx * dx + dy * dy );
573607 float dismiss_distance = mSwipeView .getDismissDistance ();
574- int index = mSwipeView .indexOfChild (movingView ) + 1 ;
575608 if (distance >= dismiss_distance ) {
576- mSwipeView .updateChildrenPosition (1 , index );
609+ mSwipeView .onChildScrolling (1 , movingView );
577610 mCurProgress = 1 ;
578611 } else {
579612 final float progress = (float ) distance / dismiss_distance ;
580- mSwipeView .updateChildrenPosition (progress , index );
613+ mSwipeView .onChildScrolling (progress , movingView );
581614 mCurProgress = progress ;
582615 }
583616 }
0 commit comments