FloatingActionButton fixes
- Remove default clickable state
- Fix FAB jumping around when used with
a Snackbar
BUG: 24252795
BUG: 24254664
Change-Id: I8946b2674e5a4147f9fd8b6d4a40fcc5bc0c32ac
diff --git a/design/api/current.txt b/design/api/current.txt
index 5523b5e..8652fea 100644
--- a/design/api/current.txt
+++ b/design/api/current.txt
@@ -202,7 +202,6 @@
ctor public FloatingActionButton.Behavior();
method public boolean layoutDependsOn(android.support.design.widget.CoordinatorLayout, android.support.design.widget.FloatingActionButton, android.view.View);
method public boolean onDependentViewChanged(android.support.design.widget.CoordinatorLayout, android.support.design.widget.FloatingActionButton, android.view.View);
- method public void onDependentViewRemoved(android.support.design.widget.CoordinatorLayout, android.support.design.widget.FloatingActionButton, android.view.View);
method public boolean onLayoutChild(android.support.design.widget.CoordinatorLayout, android.support.design.widget.FloatingActionButton, int);
}
diff --git a/design/src/android/support/design/widget/FloatingActionButton.java b/design/src/android/support/design/widget/FloatingActionButton.java
index fda99852..2fc0c54 100644
--- a/design/src/android/support/design/widget/FloatingActionButton.java
+++ b/design/src/android/support/design/widget/FloatingActionButton.java
@@ -139,8 +139,6 @@
mBackgroundTintMode, mRippleColor, mBorderWidth);
mImpl.setElevation(elevation);
mImpl.setPressedTranslationZ(pressedTranslationZ);
-
- setClickable(true);
}
@Override
@@ -327,6 +325,7 @@
// because we can use view translation properties which greatly simplifies the code.
private static final boolean SNACKBAR_BEHAVIOR_ENABLED = Build.VERSION.SDK_INT >= 11;
+ private float mFabTranslationY;
private Rect mTmpRect;
@Override
@@ -349,24 +348,6 @@
return false;
}
- @Override
- public void onDependentViewRemoved(CoordinatorLayout parent, FloatingActionButton child,
- View dependency) {
- if (dependency instanceof Snackbar.SnackbarLayout) {
- // If the removed view is a SnackbarLayout, we will animate back to our normal
- // position
- if (ViewCompat.getTranslationY(child) != 0f) {
- ViewCompat.animate(child)
- .translationY(0f)
- .scaleX(1f)
- .scaleY(1f)
- .alpha(1f)
- .setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR)
- .setListener(null);
- }
- }
- }
-
private boolean updateFabVisibility(CoordinatorLayout parent,
AppBarLayout appBarLayout, FloatingActionButton child) {
final CoordinatorLayout.LayoutParams lp =
@@ -401,8 +382,32 @@
return;
}
- final float translationY = getFabTranslationYForSnackbar(parent, fab);
- ViewCompat.setTranslationY(fab, translationY);
+ final float targetTransY = getFabTranslationYForSnackbar(parent, fab);
+ if (mFabTranslationY == targetTransY) {
+ // We're already at (or currently animating to) the target value, return...
+ return;
+ }
+
+ mFabTranslationY = targetTransY;
+ final float currentTransY = ViewCompat.getTranslationY(fab);
+ final float dy = currentTransY - targetTransY;
+
+ if (Math.abs(dy) > (fab.getHeight() * 0.667f)) {
+ // If the FAB will be travelling by more than 2/3 of it's height, let's animate
+ // it instead
+ ViewCompat.animate(fab)
+ .translationY(targetTransY)
+ .scaleX(1f)
+ .scaleY(1f)
+ .alpha(1f)
+ .setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR)
+ .setListener(null);
+ } else {
+ // Make sure that any current animation is cancelled
+ ViewCompat.animate(fab).cancel();
+ // Now update the translation Y
+ ViewCompat.setTranslationY(fab, targetTransY);
+ }
}
private float getFabTranslationYForSnackbar(CoordinatorLayout parent,