Skip to content

Commit

Permalink
Fix Drawer may be opened in reverse (#4)
Browse files Browse the repository at this point in the history
* Fix Drawer may be opened in reverse
* Support quick dragging out with the original direction
* Bump to 1.0.2

| Before | After |
|---|---|
| ![r-be](https://user-images.githubusercontent.com/5214214/104086078-8af44f80-528f-11eb-9b3b-4b3e34ad91ea.gif) | ![r-af](https://user-images.githubusercontent.com/5214214/104086061-71530800-528f-11eb-96e3-15655ac5870e.gif) |
  • Loading branch information
drakeet authored Jan 9, 2021
1 parent 83e2979 commit 9358853
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ In your `build.gradle`:

```groovy
dependencies {
implementation 'com.drakeet.drawer:drawer:1.0.1'
implementation 'com.drakeet.drawer:drawer:1.0.2'
// Optional: No need if you just use the FullDraggableHelper
implementation 'androidx.drawerlayout:drawerlayout:1.1.1'
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
buildscript {

ext.kotlinVersion = '1.4.21'
ext.buildConfig = ['versionCode' : 4,
'versionName' : "1.0.1",
ext.buildConfig = ['versionCode' : 5,
'versionName' : "1.0.2",
'compileSdkVersion': 30,
'minSdkVersion' : 19,
'targetSdkVersion' : 30]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void onDrawerDragging() {
if (drawerListeners != null) {
int listenerCount = drawerListeners.size();
for (int i = listenerCount - 1; i >= 0; --i) {
((DrawerLayout.DrawerListener) drawerListeners.get(i)).onDrawerStateChanged(DrawerLayout.STATE_DRAGGING);
drawerListeners.get(i).onDrawerStateChanged(DrawerLayout.STATE_DRAGGING);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions library/src/main/java/com/drakeet/drawer/FullDraggableHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,17 @@ public boolean onTouchEvent(MotionEvent event) {
// Not allowed to change direction in a process
if (gravity == Gravity.NO_GRAVITY) {
gravity = diffX > 0 ? Gravity.LEFT : Gravity.RIGHT;
} else if ((gravity == Gravity.LEFT && diffX < 0) || (gravity == Gravity.RIGHT && diffX > 0)) {
// Means that the motion first moves in one direction,
// and then completely close the drawer in the reverse direction.
// At this time, absDiffX should not be distributed anymore.
// So for this case, we are returning false,
// and set the initialMotionX to the direction changed point
// to support quick dragging out with the original direction.
initialMotionX = x;
return false;
}

callback.offsetDrawer(gravity, absDiffX - swipeSlop);

if (!lastDraggingDrawer) {
Expand Down

0 comments on commit 9358853

Please sign in to comment.