Skip to content

Commit

Permalink
improve the smoothness of the drag dismsiss
Browse files Browse the repository at this point in the history
  • Loading branch information
klinker24 committed Mar 24, 2018
1 parent 8d57b44 commit 79750ee
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### v1.5.1

* Smooth out the drag dismiss animation

### v1.5.0

* Don't assume 24dp for the status bar size (Essential Ph-1)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To include it in your project, add this to your module's `build.gradle` file:
```groovy
dependencies {
...
compile 'com.klinkerapps:drag-dismiss-activity:1.5.0'
compile 'com.klinkerapps:drag-dismiss-activity:1.5.1'
}
```

Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
# limitations under the License.
#

GRADLE_PLUGIN_VERSION=3.0.0-beta6
BUILD_TOOLS_VERSION=26.0.1
GRADLE_PLUGIN_VERSION=3.0.1
BUILD_TOOLS_VERSION=27.0.1

ANDROID_SUPPORT_VERSION=26.0.1
ANDROID_SUPPORT_VERSION=27.1.0

MIN_SDK=15
TARGET_SDK=26
COMPILE_SDK=26
TARGET_SDK=27
COMPILE_SDK=27

VERSION_NAME=1.5.0
VERSION_NAME=1.5.1
VERSION_CODE=1
GROUP=com.klinkerapps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.graphics.RectF;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
Expand Down Expand Up @@ -63,6 +64,7 @@ public class ElasticDragDismissFrameLayout extends FrameLayout {
private float totalDrag;
private boolean draggingDown = false;
private boolean draggingUp = false;
private int lastEventAction = Integer.MIN_VALUE;

private boolean enabled = true;

Expand Down Expand Up @@ -152,6 +154,12 @@ public void onNestedScroll(View target, int dxConsumed, int dyConsumed,
}
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
lastEventAction = ev.getAction();
return super.onInterceptTouchEvent(ev);
}

@Override
public void onStopNestedScroll(View child) {
if (enabled) {
Expand All @@ -162,14 +170,24 @@ public void onStopNestedScroll(View child) {
fastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(),
android.R.interpolator.fast_out_slow_in);
}
getChildAt(0).animate()
.translationY(0f)
.scaleX(1f)
.scaleY(1f)
.setDuration(200L)
.setInterpolator(fastOutSlowInInterpolator)
.setListener(null)
.start();

if (lastEventAction == MotionEvent.ACTION_DOWN) {
// this is a 'defensive cleanup for new gestures',
// don't animate here
// see also https://github.com/nickbutcher/plaid/issues/185
setTranslationY(0f);
setScaleX(1f);
setScaleY(1f);
} else {
getChildAt(0).animate()
.translationY(0f)
.scaleX(1f)
.scaleY(1f)
.setDuration(200L)
.setInterpolator(fastOutSlowInInterpolator)
.setListener(null)
.start();
}

ValueAnimator animator = null;
if (draggingUp) {
Expand Down

0 comments on commit 79750ee

Please sign in to comment.