Skip to content

Commit

Permalink
Card gets stuck if you touch it while it's been closed #20
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed Nov 26, 2018
1 parent 8c63fbc commit 9aa02b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog drag-to-close

## `0.3.1` (26/11/18)

- Card gets stuck if you touch it while it's been closed programmatically #20

## `0.3.0` (26/11/18)

- Migrate to AndroidX #12 (only compatible with projects that have been migrated to androidx)
Expand Down
4 changes: 2 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 3
versionName "0.3.0"
versionCode 31
versionName "0.3.1"
}
buildTypes {
release {
Expand Down
10 changes: 10 additions & 0 deletions lib/src/main/java/com/davidmiguel/dragtoclose/DragToClose.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class DragToClose extends FrameLayout {
private DragListener listener;

private int verticalDraggableRange;
private boolean uiBlocked;

public DragToClose(@NonNull Context context) {
super(context);
Expand Down Expand Up @@ -101,6 +102,9 @@ protected void onSizeChanged(int w, int h, int oldW, int oldH) {
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if(uiBlocked) {
return true; // Don't propagate event when ui blocked
}
boolean handled = false;
if (isEnabled()) {
handled = dragHelper.shouldInterceptTouchEvent(event)
Expand All @@ -117,6 +121,9 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
if(uiBlocked) {
return true; // Ignore event when ui blocked
}
dragHelper.processTouchEvent(event);
return isViewTouched(draggableView, (int) event.getX(), (int) event.getY());
}
Expand Down Expand Up @@ -209,6 +216,7 @@ public void setDragListener(DragListener listener) {
* Slides down draggable container out of the DragToClose view.
*/
public void closeDraggableContainer() {
uiBlocked = true;
slideViewTo(draggableContainer, getPaddingLeft() + draggableContainerLeft, getDraggableRange());
}

Expand All @@ -218,6 +226,7 @@ public void closeDraggableContainer() {
public void openDraggableContainer() {
slideViewTo(draggableContainer, getPaddingLeft() + draggableContainerLeft,
getPaddingTop() + draggableContainerTop);
uiBlocked = false;
}

/**
Expand Down Expand Up @@ -282,6 +291,7 @@ private void initializeAttributes(AttributeSet attrs) {
if (draggableViewId == -1 || draggableContainerId == -1) {
throw new IllegalArgumentException("draggableView and draggableContainer attributes are required.");
}
uiBlocked = false;
} finally {
array.recycle();
}
Expand Down

0 comments on commit 9aa02b8

Please sign in to comment.