package ru.dimorinny.floatingtextbutton.behavior;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.util.AttributeSet;
import android.view.View;

import ru.dimorinny.floatingtextbutton.FloatingTextButton;

public class SnackbarBehavior extends CoordinatorLayout.Behavior<FloatingTextButton> {

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

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

    @Override
    public boolean onDependentViewChanged(
            CoordinatorLayout parent,
            FloatingTextButton child,
            View dependency
    ) {
        if (child.getTranslationY() > 0) {
            return true;
        }

        child.setTranslationY(
                Math.min(0f, dependency.getTranslationY() - dependency.getHeight())
        );
        return true;
    }
}
@@ -179,16 +179,186 @@
 ackbar;%0A
+import android.support.v4.view.ViewCompat;%0Aimport android.support.v4.view.ViewPropertyAnimatorCompat;%0Aimport android.support.v4.view.animation.FastOutSlowInInterpolator;%0A
 import a
@@ -408,16 +408,60 @@
 ew.View;
+%0Aimport android.view.animation.Interpolator;
 %0A%0Aimport
@@ -602,16 +602,218 @@
 ton%3E %7B%0A%0A
+    private static final Interpolator HIDE_INTERPOLATOR = new FastOutSlowInInterpolator();%0A    private static final Long HIDE_DURATION = 250L;%0A%0A    private ViewPropertyAnimatorCompat animation = null;%0A%0A
     publ
@@ -1382,24 +1382,129 @@
 e;%0A        %7D
+%0A        if (animation != null) %7B%0A            animation.cancel();%0A            animation = null;%0A        %7D
 %0A%0A        ch
@@ -1645,10 +1645,545 @@
 e;%0A    %7D
+%0A%0A    @Override%0A    public void onDependentViewRemoved(%0A            CoordinatorLayout parent,%0A            FloatingTextButton child,%0A            View dependency%0A    ) %7B%0A        if (dependency instanceof Snackbar.SnackbarLayout) %7B%0A%0A            animation = ViewCompat.animate(child)%0A                    .translationY(0f)%0A                    .setInterpolator(HIDE_INTERPOLATOR)%0A                    .setDuration(HIDE_DURATION);%0A%0A            animation.start();%0A        %7D%0A        super.onDependentViewRemoved(parent, child, dependency);%0A    %7D
 %0A%7D

fix snackbar position when snackbar is hidden