Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

laenger/ViewPagerBottomSheet#4 #26

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-rc03'
classpath 'com.android.tools.build:gradle:3.1.0'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public abstract static class BottomSheetCallback {

private static final float HIDE_FRICTION = 0.1f;

private float mMinimumVelocity;

private float mMaximumVelocity;

private int mPeekHeight;
Expand All @@ -146,8 +148,6 @@ public abstract static class BottomSheetCallback {

private boolean mIgnoreEvents;

private int mLastNestedScrollDy;

private boolean mNestedScrolled;

int mParentHeight;
Expand Down Expand Up @@ -195,6 +195,7 @@ public ViewPagerBottomSheetBehavior(Context context, AttributeSet attrs) {
a.recycle();
ViewConfiguration configuration = ViewConfiguration.get(context);
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
}

@Override
Expand Down Expand Up @@ -338,7 +339,6 @@ public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, V child,
View directTargetChild, View target, int nestedScrollAxes) {
mLastNestedScrollDy = 0;
mNestedScrolled = false;
return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
}
Expand Down Expand Up @@ -376,7 +376,6 @@ public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View
}
}
dispatchOnSlide(child.getTop());
mLastNestedScrollDy = dy;
mNestedScrolled = true;
}

Expand All @@ -390,15 +389,24 @@ public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, Vie
|| !mNestedScrolled) {
return;
}

mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
float xVel = mVelocityTracker.getXVelocity(mActivePointerId);
float yVel = mVelocityTracker.getYVelocity(mActivePointerId);

int top;
int targetState;
if (mLastNestedScrollDy > 0) {
if (yVel < 0 && Math.abs(yVel) > mMinimumVelocity && Math.abs(yVel) > Math.abs(xVel)) {
top = mMinOffset;
targetState = STATE_EXPANDED;
} else if (mHideable && shouldHide(child, getYVelocity())) {
} else if (mHideable && shouldHide(child, yVel)) {
top = mParentHeight;
targetState = STATE_HIDDEN;
} else if (mLastNestedScrollDy == 0) {
} else if (yVel > 0 && Math.abs(yVel) > mMinimumVelocity && Math.abs(yVel) > Math.abs(xVel)) {
top = mMaxOffset;
targetState = STATE_COLLAPSED;
} else {
// not scrolling much, i.e. stationary
int currentTop = child.getTop();
if (Math.abs(currentTop - mMinOffset) < Math.abs(currentTop - mMaxOffset)) {
top = mMinOffset;
Expand All @@ -407,10 +415,8 @@ public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, Vie
top = mMaxOffset;
targetState = STATE_COLLAPSED;
}
} else {
top = mMaxOffset;
targetState = STATE_COLLAPSED;
}

if (mViewDragHelper.smoothSlideViewTo(child, child.getLeft(), top)) {
setStateInternal(STATE_SETTLING);
ViewCompat.postOnAnimation(child, new SettleRunnable(child, targetState));
Expand Down Expand Up @@ -692,13 +698,17 @@ public void onViewDragStateChanged(int state) {
public void onViewReleased(View releasedChild, float xvel, float yvel) {
int top;
@State int targetState;
if (yvel < 0) { // Moving up
if (yvel < 0 && Math.abs(yvel) > mMinimumVelocity && Math.abs(yvel) > Math.abs(xvel)) {
top = mMinOffset;
targetState = STATE_EXPANDED;
} else if (mHideable && shouldHide(releasedChild, yvel)) {
top = mParentHeight;
targetState = STATE_HIDDEN;
} else if (yvel == 0.f) {
} else if (yvel > 0 && Math.abs(yvel) > mMinimumVelocity && Math.abs(yvel) > Math.abs(xvel)) {
top = mMaxOffset;
targetState = STATE_COLLAPSED;
} else {
// not scrolling much, i.e. stationary
int currentTop = releasedChild.getTop();
if (Math.abs(currentTop - mMinOffset) < Math.abs(currentTop - mMaxOffset)) {
top = mMinOffset;
Expand All @@ -707,10 +717,8 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) {
top = mMaxOffset;
targetState = STATE_COLLAPSED;
}
} else {
top = mMaxOffset;
targetState = STATE_COLLAPSED;
}

if (mViewDragHelper.settleCapturedViewAt(releasedChild.getLeft(), top)) {
setStateInternal(STATE_SETTLING);
ViewCompat.postOnAnimation(releasedChild,
Expand Down