-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
@samtstern Every Travis build is going to fail now because 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 |
@@ -1,235 +1,242 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<ScrollView | |||
<android.support.design.widget.CoordinatorLayout |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, haha! 😄
The diff got all messed up, the only change in
auth_ui_layout.xml
is being wrapped with aCoordinatorLayout
and adding theroot
id.