diff --git a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
index 350cc316..ddae9640 100644
--- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
+++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
@@ -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;
@@ -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() {
diff --git a/bottom-bar/src/main/java/com/roughike/bottombar/BottomNavigationBehavior.java b/bottom-bar/src/main/java/com/roughike/bottombar/BottomNavigationBehavior.java
index 39f3d3b9..5f810fbe 100644
--- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomNavigationBehavior.java
+++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomNavigationBehavior.java
@@ -13,7 +13,7 @@
/**
* Created by Nikola D. on 3/15/2016.
- *
+ *
* Credit goes to Nikola Despotoski:
* https://github.com/NikolaDespotoski
*/
@@ -29,18 +29,48 @@ class BottomNavigationBehavior 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) {
}
@@ -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) {
@@ -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;
}