From e6aa39659fc1b9060aaf8d74a744e74460c6f831 Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 24 Jul 2017 12:10:47 +0200 Subject: [PATCH] Make FAB appear again after it has been hidden --- .../calculator/view/PagerViewFabBehavior.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/view/PagerViewFabBehavior.java b/app/src/main/java/org/solovyev/android/calculator/view/PagerViewFabBehavior.java index ac734aae..d13d0ed9 100644 --- a/app/src/main/java/org/solovyev/android/calculator/view/PagerViewFabBehavior.java +++ b/app/src/main/java/org/solovyev/android/calculator/view/PagerViewFabBehavior.java @@ -1,6 +1,7 @@ package org.solovyev.android.calculator.view; import android.content.Context; +import android.support.annotation.NonNull; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; import android.support.v4.view.ViewCompat; @@ -11,6 +12,18 @@ import android.view.View; public class PagerViewFabBehavior extends FloatingActionButton.Behavior { + @NonNull + private final FloatingActionButton.OnVisibilityChangedListener + visibilityListener = new FloatingActionButton.OnVisibilityChangedListener() { + @Override + public void onHidden(FloatingActionButton fab) { + // by default, FloatingActionButton#hide causes FAB to be GONE which blocks any + // consequent scroll updates in CoordinatorLayout#onNestedScroll. Let's make the + // FAB invisible instead + fab.setVisibility(View.INVISIBLE); + } + }; + public PagerViewFabBehavior() { super(); } @@ -49,13 +62,13 @@ public class PagerViewFabBehavior extends FloatingActionButton.Behavior { private boolean onScroll(FloatingActionButton child, float scrollX, float scrollY) { if (scrollY > 0 && child.getVisibility() == View.VISIBLE) { - child.hide(); + child.hide(visibilityListener); return true; } else if (scrollY < 0 && child.getVisibility() != View.VISIBLE) { - child.show(); + child.show(visibilityListener); return true; } else if (scrollX != 0 && child.getVisibility() != View.VISIBLE) { - child.show(); + child.show(visibilityListener); return true; } return false;