As the title says, if I use withSnackbar method of UndoHelper and then I call remove passing just the positions, nothing happens. The Snackbar doesn't show up.
How to recreate the issue
In the sample app, inside MultiselectSampleActivity, change mUndoHelper to
I'd say that I identified the issue. Inside UndoHelper, when creating a new Snackbar :
fun remove(positions: Set<Int>): Snackbar? {
val snackBar = this.snackBar ?: return null
val snackBarView = snackBar.view
val snackBarText = snackBarView.findViewById<View>(com.google.android.material.R.id.snackbar_text) as TextView
return remove(snackBarView, snackBarText.text.toString(), snackBarActionText, snackBar.duration, positions)
}
In here, snackbar.view is wil not be the same as the view that you are passing inside Snackbar.make(view, ..., ...).
I see that we don't want to use the instance that was passed using withSnackbar method. Instead of trying to clone the Snackbar, we could pass in withSnackbar method a lambda that creates a Snackbar:
withSnackbar(actionText) { Snackbar.make(...) }
and use that lambda inside the remove method.
I would have made a PR but mabye there is a better way.
About this issue
As the title says, if I use
withSnackbar
method ofUndoHelper
and then I callremove
passing just the positions, nothing happens. TheSnackbar
doesn't show up.How to recreate the issue
In the sample app, inside
MultiselectSampleActivity
, changemUndoHelper
toThen further down replace
with
Details
I'd say that I identified the issue. Inside
UndoHelper
, when creating a newSnackbar
:In here,
snackbar.view
is wil not be the same as theview
that you are passing insideSnackbar.make(view, ..., ...)
. I see that we don't want to use the instance that was passed usingwithSnackbar
method. Instead of trying to clone theSnackbar
, we could pass inwithSnackbar
method a lambda that creates aSnackbar
:and use that lambda inside the
remove
method.I would have made a
PR
but mabye there is a better way.