Skip to content

Make Snackbar dismissable in sample #485

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

Merged
merged 5 commits into from
Jan 3, 2017
Merged

Make Snackbar dismissable in sample #485

merged 5 commits into from
Jan 3, 2017

Conversation

SUPERCILEX
Copy link
Collaborator

The diff got all messed up, the only change in auth_ui_layout.xml is being wrapped with a CoordinatorLayout and adding the root id.

@SUPERCILEX
Copy link
Collaborator Author

@samtstern Every Travis build is going to fail now because alpha1 is too old for the android gradle plugin. Because of that, I think the best course of action is to upgrade to beta1 while disabling RestrictedApi and then wait for beta2 which @tnorbye says fixes the RestrictedApi stuff. Hopefully beta2 will come out in the first week of January.

I have a PR coming that changes the disabled checks so I'll remember to remove the hack you're concerned about that (we don't need to disable InvalidPackage for all projects, only the auth module; my PR fixes that).

@@ -1,235 +1,242 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
<android.support.design.widget.CoordinatorLayout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a CoordinatorLayout here with only one child?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samtstern I read this great post from Ian Lake to get the PR to work. Turns out the FAB, Snackbar, and other design lib components rely on a Coordinator Layout to tell them when stuff is happening. Since the Snackbar wasn't dismissable, I took a guess that adding a Coordinator Layout would fix it, and it did!

Ian Lake:

This ability to tie Views together is how much of the cooler functionality of the Design Library works — take, for example, the interaction between the FloatingActionButton and the Snackbar. The FAB’s Behavior depends on instances of the Snackbar being added to the CoordinatorLayout, then using the onDependentViewChanged() callback to translate the FAB upward to avoid overlapping the Snackbar.


PS: you made me curious so I decided to find out how the Snackbar really works:
SwipeDismissBehavior<V extends View> extends CoordinatorLayout.Behavior<V>
and
Snackbar extends BaseTransientBottomBar<Snackbar>
In BaseTransientBottomBar:

behavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
    @Override
    public void onDismiss(View view) {
        view.setVisibility(View.GONE); // <<<<<<
        dispatchDismiss(BaseCallback.DISMISS_EVENT_SWIPE); // <<<<<<
    }

    @Override
    public void onDragStateChanged(int state) {
        switch (state) {
            case SwipeDismissBehavior.STATE_DRAGGING:
            case SwipeDismissBehavior.STATE_SETTLING:
                // If the view is being dragged or settling, cancel the timeout
                SnackbarManager.getInstance().cancelTimeout(mManagerCallback);
                break;
            case SwipeDismissBehavior.STATE_IDLE:
                // If the view has been released and is idle, restore the timeout
                SnackbarManager.getInstance().restoreTimeout(mManagerCallback);
                break;
        }
    }
});

Pretty cool!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all that! I realized I was confusing CoordinatorLayout and ConstraintLayout in my head! First day back fuzz I guess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, haha! 😄

@samtstern samtstern merged commit a62f5ec into firebase:version-1.1.0-dev Jan 3, 2017
@SUPERCILEX SUPERCILEX deleted the snackbars branch January 3, 2017 20:56
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

Successfully merging this pull request may close these issues.

2 participants