Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up FloatButton when it shows the message #113

Open
zirouan opened this issue Apr 28, 2015 · 7 comments
Open

Up FloatButton when it shows the message #113

zirouan opened this issue Apr 28, 2015 · 7 comments

Comments

@zirouan
Copy link

zirouan commented Apr 28, 2015

Congratulations on your fantastic library.

I have the following situation.

I have a layout where it has a RecyclerView and FloatButton.
Can you explain your blibioteca, the message appears over my FloatButton and correct it would raise the FloatButton.

Know how I can fix this?

thank you.

@wmora
Copy link
Contributor

wmora commented Apr 28, 2015

Hi, there's an EventListener that will let you know when the Snackbar will show up through the onShow method. When this is called you should raise your FloatButton. Similarly, you should bring your button back down when onDismiss is called

@zlhaa23
Copy link

zlhaa23 commented Apr 29, 2015

Hi wmora,

I am having the same issue, due to a floating action button.

Unfortunately simply raising and lowering the FAB in the EventListener doesn't seem to work for me.

Here is my code. The FAB is a child of rlContent, positioned at bottom right.

private class SnackbarListener implements EventListener {

    @Override
    public void onShow(Snackbar snackbar) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT
        );
        params.setMargins(0, 0, 0, snackbar.getHeight());
        rlContent.setLayoutParams(params);
    }

    @Override
    public void onShowByReplace(Snackbar snackbar) {
    }

    @Override
    public void onShown(Snackbar snackbar) {
    }

    @Override
    public void onDismiss(Snackbar snackbar) {
    }

    @Override
    public void onDismissByReplace(Snackbar snackbar) {
    }

    @Override
    public void onDismissed(Snackbar snackbar) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT
        );
        rlContent.setLayoutParams(params);
    }
}

This would work in normal cases. But if a second snackbar is shown before the previous one is dismissed, when the first snackbar disappears, onDismissed is called, and the margin will be incorrectly set to 0, i.e. FAB not raised.

Currently my workaround is to maintain a snackbar counter in the activity. The counter is increased by one whenever a snackbar is shown, and in onDismissed, the margin to reset to 0 only if the counter becomes zero.

But to me my solution is not so elegant. Is there a better way to deal with FABs?

@zlhaa23
Copy link

zlhaa23 commented Apr 29, 2015

I figured it out... Just reset the margin to 0 in onDismiss instead of onDismissed
I guess onDismissed is called after either onDismiss or onDismissByReplace

@zlhaa23
Copy link

zlhaa23 commented Apr 30, 2015

Still, the movement of the FAB is not as smooth as the demo in http://www.google.com/design/spec/components/snackbars-toasts.html#snackbars-toasts-usage

@gedu
Copy link

gedu commented May 8, 2015

Hi zhangns, for make it a bit smoother i use this:
onShow(int i){
fabView.animate().translationY(-snackbarHeight).start();
}
and
onDismiss(int i){
fabView.animate().translationY(0).start();
}

hope this helps

@zlhaa23
Copy link

zlhaa23 commented May 11, 2015

@gedu Thanks! Works perfectly.

@chipcerio
Copy link

@gedu your solution works. At first I was attempting to add an Interpolator to fabView but couldn't get the animation on both fabView and snackbar to synchronize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants