Skip to content
This repository has been archived by the owner on Oct 23, 2020. It is now read-only.

Add default behavior with Snakebars (FloatingActionMenu) #394

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions library/src/main/java/com/github/clans/fab/FloatingActionMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
Expand All @@ -23,11 +26,13 @@
import android.view.animation.AnticipateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;
import android.util.AttributeSet;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

@CoordinatorLayout.DefaultBehavior(FloatingActionMenu.Behavior.class)
public class FloatingActionMenu extends ViewGroup {

private static final int ANIMATION_DURATION = 300;
Expand Down Expand Up @@ -1013,4 +1018,37 @@ public void setOnMenuButtonClickListener(OnClickListener clickListener) {
public void setOnMenuButtonLongClickListener(OnLongClickListener longClickListener) {
mMenuButton.setOnLongClickListener(longClickListener);
}

/**
* Behavior designed for use with {@link FloatingActionMenu} instances. Its main function
* is to move {@link FloatingActionMenu} views so that any displayed {@link Snackbar}s do
* not cover them.
*/
public static class Behavior extends CoordinatorLayout.Behavior<FloatingActionMenu> {
public Behavior(){
super();
}

public Behavior(Context context, AttributeSet attrs){
super(context, attrs);
}

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

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionMenu child, View dependency) {
float translationY = Math.min(0, ViewCompat.getTranslationY(dependency) - dependency.getHeight());
ViewCompat.setTranslationY(child, translationY);
return true;
}

@Override
public void onDependentViewRemoved(CoordinatorLayout parent, FloatingActionMenu child, View dependency) {
ViewCompat.animate(child).translationY(0).start();

}
}
}