Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide swiped position to onCardSwiped event #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ CardStackLayoutManager.setSwipeableMethod(SwipeableMethod.AutomaticAndManual)
| Method | Description |
| :---- | :---- |
| CardStackListener.onCardDragging(Direction direction, float ratio) | This method is called while the card is dragging. |
| CardStackListener.onCardSwiped(Direction direction) | This method is called when the card is swiped. |
| CardStackListener.onCardSwiped(Direction direction, int swipedPosition) | This method is called when the card is swiped. |
| CardStackListener.onCardRewound() | This method is called when the card is rewinded. |
| CardStackListener.onCardCanceled() | This method is called when the card is dragged less than threshold. |
| CardStackListener.onCardAppeared(View view, int position) | This method is called when the card appeared. |
Expand All @@ -317,7 +317,7 @@ CardStackLayoutManager.setSwipeableMethod(SwipeableMethod.AutomaticAndManual)
| :---- | :---- |
| CardStackView.CardEventListener | CardStackListener |
| onCardDragging(float percentX, float percentY) | onCardDragging(Direction direction, float ratio) |
| onCardSwiped(SwipeDirection direction) | onCardSwiped(Direction direction) |
| onCardSwiped(SwipeDirection direction) | onCardSwiped(Direction direction, int swipedPosition) |
| onCardReversed() | onCardRewound() |
| onCardMovedToOrigin() | onCardCanceled() |
| onCardClicked(int index) | This method is no longer provided. Please implement in your item of RecyclerView. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ private void update(RecyclerView.Recycler recycler) {
final Direction direction = state.getDirection();

state.next(state.status.toAnimatedStatus());
final int swipedPosition = state.topPosition;
state.topPosition++;
state.dx = 0;
state.dy = 0;
Expand Down Expand Up @@ -311,7 +312,7 @@ private void update(RecyclerView.Recycler recycler) {
new Handler().post(new Runnable() {
@Override
public void run() {
listener.onCardSwiped(direction);
listener.onCardSwiped(direction, swipedPosition);
View topView = getTopView();
if (topView != null) {
listener.onCardAppeared(getTopView(), state.topPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public interface CardStackListener {
void onCardDragging(Direction direction, float ratio);
void onCardSwiped(Direction direction);
void onCardSwiped(Direction direction, int swipedPosition);
void onCardRewound();
void onCardCanceled();
void onCardAppeared(View view, int position);
Expand All @@ -14,7 +14,7 @@ public interface CardStackListener {
@Override
public void onCardDragging(Direction direction, float ratio) {}
@Override
public void onCardSwiped(Direction direction) {}
public void onCardSwiped(Direction direction, int swipedPosition) {}
@Override
public void onCardRewound() {}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class MainActivity : AppCompatActivity(), CardStackListener {
Log.d("CardStackView", "onCardDragging: d = ${direction.name}, r = $ratio")
}

override fun onCardSwiped(direction: Direction) {
Log.d("CardStackView", "onCardSwiped: p = ${manager.topPosition}, d = $direction")
if (manager.topPosition == adapter.itemCount - 5) {
override fun onCardSwiped(direction: Direction, swipedPosition: Int) {
Log.d("CardStackView", "onCardSwiped: p = $swipedPosition, d = $direction")
if (swipedPosition == adapter.itemCount - 5) {
paginate()
}
}
Expand Down