Skip to content

Commit 79750ee

Browse files
committed
improve the smoothness of the drag dismsiss
1 parent 8d57b44 commit 79750ee

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### v1.5.1
4+
5+
* Smooth out the drag dismiss animation
6+
37
### v1.5.0
48

59
* Don't assume 24dp for the status bar size (Essential Ph-1)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To include it in your project, add this to your module's `build.gradle` file:
1919
```groovy
2020
dependencies {
2121
...
22-
compile 'com.klinkerapps:drag-dismiss-activity:1.5.0'
22+
compile 'com.klinkerapps:drag-dismiss-activity:1.5.1'
2323
}
2424
```
2525

gradle.properties

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
# limitations under the License.
1515
#
1616

17-
GRADLE_PLUGIN_VERSION=3.0.0-beta6
18-
BUILD_TOOLS_VERSION=26.0.1
17+
GRADLE_PLUGIN_VERSION=3.0.1
18+
BUILD_TOOLS_VERSION=27.0.1
1919

20-
ANDROID_SUPPORT_VERSION=26.0.1
20+
ANDROID_SUPPORT_VERSION=27.1.0
2121

2222
MIN_SDK=15
23-
TARGET_SDK=26
24-
COMPILE_SDK=26
23+
TARGET_SDK=27
24+
COMPILE_SDK=27
2525

26-
VERSION_NAME=1.5.0
26+
VERSION_NAME=1.5.1
2727
VERSION_CODE=1
2828
GROUP=com.klinkerapps
2929

library/src/main/java/xyz/klinker/android/drag_dismiss/view/ElasticDragDismissFrameLayout.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.graphics.RectF;
2424
import android.support.v4.view.ViewCompat;
2525
import android.util.AttributeSet;
26+
import android.view.MotionEvent;
2627
import android.view.View;
2728
import android.view.animation.AnimationUtils;
2829
import android.view.animation.Interpolator;
@@ -63,6 +64,7 @@ public class ElasticDragDismissFrameLayout extends FrameLayout {
6364
private float totalDrag;
6465
private boolean draggingDown = false;
6566
private boolean draggingUp = false;
67+
private int lastEventAction = Integer.MIN_VALUE;
6668

6769
private boolean enabled = true;
6870

@@ -152,6 +154,12 @@ public void onNestedScroll(View target, int dxConsumed, int dyConsumed,
152154
}
153155
}
154156

157+
@Override
158+
public boolean onInterceptTouchEvent(MotionEvent ev) {
159+
lastEventAction = ev.getAction();
160+
return super.onInterceptTouchEvent(ev);
161+
}
162+
155163
@Override
156164
public void onStopNestedScroll(View child) {
157165
if (enabled) {
@@ -162,14 +170,24 @@ public void onStopNestedScroll(View child) {
162170
fastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(),
163171
android.R.interpolator.fast_out_slow_in);
164172
}
165-
getChildAt(0).animate()
166-
.translationY(0f)
167-
.scaleX(1f)
168-
.scaleY(1f)
169-
.setDuration(200L)
170-
.setInterpolator(fastOutSlowInInterpolator)
171-
.setListener(null)
172-
.start();
173+
174+
if (lastEventAction == MotionEvent.ACTION_DOWN) {
175+
// this is a 'defensive cleanup for new gestures',
176+
// don't animate here
177+
// see also https://github.com/nickbutcher/plaid/issues/185
178+
setTranslationY(0f);
179+
setScaleX(1f);
180+
setScaleY(1f);
181+
} else {
182+
getChildAt(0).animate()
183+
.translationY(0f)
184+
.scaleX(1f)
185+
.scaleY(1f)
186+
.setDuration(200L)
187+
.setInterpolator(fastOutSlowInInterpolator)
188+
.setListener(null)
189+
.start();
190+
}
173191

174192
ValueAnimator animator = null;
175193
if (draggingUp) {

0 commit comments

Comments
 (0)