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

bug fix for issue #139 #210

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class CardStackLayoutManager
implements RecyclerView.SmoothScroller.ScrollVectorProvider {

private final Context context;
private boolean isSwipeEnabled = true;

private CardStackListener listener = CardStackListener.DEFAULT;
private CardStackSetting setting = new CardStackSetting();
Expand Down Expand Up @@ -206,6 +207,7 @@ private void update(RecyclerView.Recycler recycler) {
@Override
public void run() {
listener.onCardSwiped(direction);
setCanInteract(false);
View topView = getTopView();
if (topView != null) {
listener.onCardAppeared(getTopView(), state.topPosition);
Expand Down Expand Up @@ -493,4 +495,24 @@ public void setRewindAnimationSetting(@NonNull RewindAnimationSetting rewindAnim
setting.rewindAnimationSetting = rewindAnimationSetting;
}

/**
* If your using setSwipeEnabled(false) don't use this method is can make setSwipeEnabled unpredictable
*/
public void setCanInteract(boolean isIntractable){
if(!isSwipeEnabled) {
setCanScrollHorizontal(isIntractable);
setCanScrollVertical(isIntractable);
}
}

public void setSwipeEnabled(boolean isSwipeEnabled){
this.isSwipeEnabled = isSwipeEnabled;
if(!isSwipeEnabled){
setCanInteract(false);
}
}

public boolean isSwipeEnabled() {
return isSwipeEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
public void swipe() {
if (getLayoutManager() instanceof CardStackLayoutManager) {
CardStackLayoutManager manager = (CardStackLayoutManager) getLayoutManager();
manager.setCanInteract(true);
smoothScrollToPosition(manager.getTopPosition() + 1);
}
}

public void rewind() {
if (getLayoutManager() instanceof CardStackLayoutManager) {
CardStackLayoutManager manager = (CardStackLayoutManager) getLayoutManager();
manager.setCanInteract(true);
smoothScrollToPosition(manager.getTopPosition() - 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ protected void onStop() {
break;
case ManualCancel:
listener.onCardCanceled();
if(!manager.isSwipeEnabled()){
manager.getCardStackState().next(CardStackState.Status.RewindAnimating);
manager.setCanInteract(false);
}
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public View findSnapView(RecyclerView.LayoutManager layoutManager) {
if (view != null) {
int x = (int) view.getTranslationX();
int y = (int) view.getTranslationY();
int width = manager.getWidth();
int height = manager.getHeight();
if (x > width || y > height || (x == 0 && y == 0)) {
if ((x == 0 && y == 0)) {
return null;
}
return view;
Expand Down