Skip to content

Commit

Permalink
Merge pull request #183 from yuyakaido/issue/181
Browse files Browse the repository at this point in the history
Make swipeable after automatic swipe and then manual cancel
  • Loading branch information
yuyakaido authored Jan 17, 2019
2 parents 392441a + d81708f commit 0eb0f95
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,48 @@ public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerVi
@Override
public void onScrollStateChanged(int s) {
switch (s) {
// スクロールが止まったタイミング
case RecyclerView.SCROLL_STATE_IDLE:
if (state.status != CardStackState.Status.PrepareSwipeAnimation) {
// ManualSwipeが完了した場合の処理
if (state.targetPosition == RecyclerView.NO_POSITION) {
state.next(CardStackState.Status.Idle);
state.targetPosition = RecyclerView.NO_POSITION;
} else {
// 2枚以上のカードを同時にスワイプする場合の処理
if (state.topPosition < state.targetPosition) {
// 1枚目のカードをスワイプすると一旦SCROLL_STATE_IDLEが流れる
// そのタイミングで次のアニメーションを走らせることで連続でスワイプしているように見せる
smoothScrollToNext(state.targetPosition);
} else if (state.targetPosition < state.topPosition) {
// Nextの場合と同様に、1枚目の処理が完了したタイミングで次のアニメーションは走らせる
smoothScrollToPrevious(state.targetPosition);
} else {
// AutomaticSwipeが完了した場合の処理
state.next(CardStackState.Status.Idle);
state.targetPosition = RecyclerView.NO_POSITION;
}
}
} else {
// スワイプが何らかの理由で途中でキャンセルされた場合を考慮して、ここで状態をリセットする
// (例)AutomaticSwipeの最中にカードをタップしてManualCancelを実行した場合
// https://github.com/yuyakaido/CardStackView/issues/175
// https://github.com/yuyakaido/CardStackView/issues/181
state.next(CardStackState.Status.Idle);
state.targetPosition = RecyclerView.NO_POSITION;
}
break;
// カードをドラッグしている最中
case RecyclerView.SCROLL_STATE_DRAGGING:
state.next(CardStackState.Status.Dragging);
break;
// カードが指から離れて、慣性アニメーションが開始したタイミング
case RecyclerView.SCROLL_STATE_SETTLING:
if (state.status != CardStackState.Status.PrepareSwipeAnimation) {
// TODO この分岐は本当に必要か?
if (state.targetPosition == RecyclerView.NO_POSITION) {
state.next(CardStackState.Status.Idle);
state.targetPosition = RecyclerView.NO_POSITION;
} else {
if (state.topPosition < state.targetPosition) {
state.next(CardStackState.Status.PrepareSwipeAnimation);
Expand Down

0 comments on commit 0eb0f95

Please sign in to comment.