Skip to content

Commit 29e26bb

Browse files
committed
先提交
1 parent 9a9ccdb commit 29e26bb

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

library/src/main/java/com/beyondsw/lib/widget/StackCardsView.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,20 @@ void tryAppendChild() {
310310
}
311311
}
312312

313-
void updateChildrenPosition(float progress, int startIndex) {
313+
void onChildScrolling(float progress, View view) {
314+
int index = indexOfChild(view);
315+
if (index == getChildCount() - 1) {
316+
return;
317+
}
318+
updateChildrenPosition(progress, getChildAt(index + 1));
319+
}
320+
321+
void updateChildrenPosition(float progress, View startView) {
314322
final int cnt = getChildCount();
323+
int startIndex = indexOfChild(startView);
324+
if (startIndex == -1) {
325+
return;
326+
}
315327
float oriScale;
316328
float oriAlpha;
317329
float oriTranslationY;
@@ -321,10 +333,6 @@ void updateChildrenPosition(float progress, int startIndex) {
321333
float progressScale;
322334
for (int i = startIndex; i < cnt; i++) {
323335
View child = getChildAt(i);
324-
if (child == null) {
325-
log(TAG, "updateChildrenPosition: err,child=null");
326-
return;
327-
}
328336
int oriIndex = Math.min(mScaleArray.length - 1, i - startIndex + 1);
329337
if (child.getVisibility() != View.GONE) {
330338
if (mScaleArray != null) {

library/src/main/java/com/beyondsw/lib/widget/SwipeTouchHelper.java

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)