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

Fixed Behavior is too sensitive to scrolling #779

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.util.Log;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.ViewParent;
Expand Down Expand Up @@ -828,7 +829,7 @@ private void initializeShyBehavior() {

private void updateShyHeight(int height) {
((CoordinatorLayout.LayoutParams) getLayoutParams())
.setBehavior(new BottomNavigationBehavior(height, 0, false));
.setBehavior(new BottomNavigationBehavior(height, 0, ViewConfiguration.get(getContext()).getScaledTouchSlop()*2,false));
}

private void resizeForDrawingUnderNavbar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* Created by Nikola D. on 3/15/2016.
*
* <p>
* Credit goes to Nikola Despotoski:
* https://github.com/NikolaDespotoski
*/
Expand All @@ -29,18 +29,48 @@ class BottomNavigationBehavior<V extends View> extends VerticalScrollingBehavior
private final BottomNavigationWithSnackbar mWithSnackBarImpl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? new LollipopBottomNavWithSnackBarImpl() : new PreLollipopBottomNavWithSnackBarImpl();
private boolean mScrollingEnabled = true;

/**
* Minimum touch distance
*/
private final int scaledTouchSlop;

/**
* current Y offset
*/
private int offset;


BottomNavigationBehavior(int bottomNavHeight, int defaultOffset, boolean tablet) {
this(bottomNavHeight, defaultOffset, 0, tablet);
}

BottomNavigationBehavior(int bottomNavHeight, int defaultOffset, int scaledTouchSlop, boolean tablet) {
this.bottomNavHeight = bottomNavHeight;
this.defaultOffset = defaultOffset;
isTablet = tablet;
this.scaledTouchSlop = Math.max(0,scaledTouchSlop);
this.offset = 0;
}


@Override
public boolean layoutDependsOn(CoordinatorLayout parent, V child, View dependency) {
mWithSnackBarImpl.updateSnackbar(parent, dependency, child);
return dependency instanceof Snackbar.SnackbarLayout;
}

@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, V child, View directTargetChild, View target, int nestedScrollAxes) {
offset = 0;
return super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
}

@Override
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target) {
super.onStopNestedScroll(coordinatorLayout, child, target);
offset = 0;
}

@Override
public void onNestedVerticalOverScroll(CoordinatorLayout coordinatorLayout, V child, @ScrollDirection int direction, int currentOverScroll, int totalOverScroll) {
}
Expand All @@ -65,7 +95,14 @@ public boolean onDependentViewChanged(CoordinatorLayout parent, V child, View de

@Override
public void onDirectionNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx, int dy, int[] consumed, @ScrollDirection int scrollDirection) {
handleDirection(child, scrollDirection);
offset += dy;
if (offset > scaledTouchSlop) {
handleDirection(child, ScrollDirection.SCROLL_DIRECTION_UP);
offset = 0;
} else if (offset < -scaledTouchSlop) {
handleDirection(child, ScrollDirection.SCROLL_DIRECTION_DOWN);
offset = 0;
}
}

private void handleDirection(V child, int scrollDirection) {
Expand Down Expand Up @@ -101,11 +138,11 @@ private void ensureOrCancelAnimator(V child) {
}


void setHidden(@NonNull V view, boolean bottomLayoutHidden) {
void setHidden(@NonNull V view, boolean bottomLayoutHidden) {
if (!bottomLayoutHidden && hidden) {
animateOffset(view, defaultOffset);
} else if (bottomLayoutHidden && !hidden) {
animateOffset(view, bottomNavHeight + defaultOffset);
animateOffset(view, bottomNavHeight + defaultOffset);
}
hidden = bottomLayoutHidden;
}
Expand Down