Skip to content

Commit

Permalink
add dampen
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyufei committed Dec 1, 2018
1 parent 0444ab8 commit 60300cf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
.DS_Store
/build
.externalNativeBuild
.idea/

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public class NestedTouchScrollingLayout extends FrameLayout implements NestedScr
*/
private @SheetDirection int mSheetDirection = SheetDirection.ALL;

/**
* 手指向上阻尼值
*/
private float mDampingUp = 1;

/**
* 手指向下阻尼值
*/
private float mDampingDown = 1;

/**
************* 键盘收起,导致 reLayout,getHeight 发生改变,所以一开始就锁定高度
*/
Expand Down Expand Up @@ -226,6 +236,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {

@Override
public boolean onTouchEvent(MotionEvent event) {
float velocityY = 0;
if (getChildAt(0) == null || !isParentDispatchTouchEvent) {
return super.onTouchEvent(event);
}
Expand All @@ -241,7 +252,7 @@ public boolean onTouchEvent(MotionEvent event) {
mParentOwnsTouch = false;
mDownY = event.getY();
mDownX = event.getX();
mSheetTranslation = getMeasuredHeight() - mOriginTranslate;
mSheetTranslation = mTouchParentViewOriginMeasureHeight - mOriginTranslate;
mDownSheetTranslation = mSheetTranslation;
velocityTracker.clear();

Expand All @@ -255,13 +266,16 @@ public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
isFingerHolderTouch = false;
isLeftorRightTouchLimit = true;
velocityTracker.computeCurrentVelocity(1000);
velocityY = velocityTracker.getYVelocity();
notifyOnFingerUp(velocityY);
}

getParent().requestDisallowInterceptTouchEvent(true);

velocityTracker.addMovement(event);

float maxSheetTranslation = getMeasuredHeight();
float maxSheetTranslation = mTouchParentViewOriginMeasureHeight;

float deltaY = mDownY - event.getY();
float deltaX = mDownX - event.getX();
Expand Down Expand Up @@ -312,22 +326,25 @@ public boolean onTouchEvent(MotionEvent event) {
}

if (isHoldTouch) {
event.offsetLocation(0, mSheetTranslation - getMeasuredHeight());
event.offsetLocation(0, mSheetTranslation - mTouchParentViewOriginMeasureHeight);
getChildAt(0).dispatchTouchEvent(event);
} else {
setSheetTranslation(newSheetTranslation);

if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
isHoldTouch = true;
getParent().requestDisallowInterceptTouchEvent(false);
velocityTracker.computeCurrentVelocity(1000);
float velocityY = velocityTracker.getYVelocity();
// recover(0);

if (Math.abs(velocityY) < minFlingVelocity) {
if (mSheetTranslation > getHeight() / 2) { } else { }
} else {
if (velocityY < 0) { } else { }
}
notifyNestScrollChildReleaseCallback((int) velocityY);
}
}
} else {
event.offsetLocation(0, mSheetTranslation - getMeasuredHeight());
event.offsetLocation(0, mSheetTranslation - mTouchParentViewOriginMeasureHeight);
getChildAt(0).dispatchTouchEvent(event);
}
return true;
Expand Down Expand Up @@ -475,12 +492,13 @@ public void setTranslation(float transY) {
if (mSheetDirection == SheetDirection.TOP && transY > 0) {
return;
}
transY = transY > 0 ? transY * mDampingDown : transY * mDampingUp;
notifyNestScrollChildChangeCallback(transY);
if (mChildView != null) {
mChildView.setTranslationY(transY);
}
if (transY == 0) {
mDownSheetTranslation = getMeasuredHeight();
mDownSheetTranslation = mTouchParentViewOriginMeasureHeight;
mOriginTranslate = 0;
}
}
Expand Down Expand Up @@ -694,4 +712,12 @@ public void peek(int offset, Runnable runnable) {
public void hiden(Runnable runnable) {
recover(getMeasuredHeight(), runnable);
}

public void setDampingDown(float mDampingDown) {
this.mDampingDown = mDampingDown;
}

public void setDampingUp(float mDampingUp) {
this.mDampingUp = mDampingUp;
}
}

0 comments on commit 60300cf

Please sign in to comment.