fab: slide fab up when a snackbar shows

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2018-07-17 20:31:41 +05:30 committed by Jason A. Donenfeld
parent df03bdd7f9
commit d43e77867c
2 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,32 @@
/*
* Copyright © 2018 Harsh Shandilya <msfjarvis@gmail.com>
* Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package com.wireguard.android.widget.fab;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.util.AttributeSet;
import android.view.View;
public class FloatingActionButtonBehavior extends CoordinatorLayout.Behavior<FloatingActionsMenu> {
public FloatingActionButtonBehavior(final Context context, final AttributeSet attrs) { }
@Override
public boolean layoutDependsOn(final CoordinatorLayout parent, final FloatingActionsMenu child,
final View dependency) {
return dependency instanceof Snackbar.SnackbarLayout;
}
@Override
public boolean onDependentViewChanged(final CoordinatorLayout parent, final FloatingActionsMenu child,
final View dependency) {
final float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
child.setTranslationY(translationY);
return true;
}
}

View File

@ -43,7 +43,8 @@
android:layout_margin="16dp" android:layout_margin="16dp"
app:fab_labelStyle="@style/fab_label" app:fab_labelStyle="@style/fab_label"
android:clipChildren="false" android:clipChildren="false"
app:fab_labelsPosition="left" > app:fab_labelsPosition="left"
app:layout_behavior="com.wireguard.android.widget.fab.FloatingActionButtonBehavior" >
<com.wireguard.android.widget.fab.LabeledFloatingActionButton <com.wireguard.android.widget.fab.LabeledFloatingActionButton
android:id="@+id/create_empty" android:id="@+id/create_empty"