[BottomSheetDialogFragment] Snackbar invisible when showing from BottomSheetDialogFragment
See original GitHub issueDescription: Full description of issue here
SnackBar invisible when showing from BottomSheetDialogFragment
Expected behavior: Screenshots and/or description of expected behavior
SnackBar visible when showing from BottomSheetDialogFragment
Source code: The code snippet which is causing this issue. Please consider attaching a minimal sample app that reproduces the issue.
class MyBottomSheetDialogFragment : BottomSheetDialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = createMyView()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Snackbar.make(view, "Test", Snackbar.LENGTH_INDEFINITE).show()
}
}
Android API version: Android API version here
29
Material Library version: Material Android Library version you are using here (e.g., 1.1.0-alpha07)
1.2.1
Device: Device on which the bug was encountered here
To help us triage faster, please check to make sure you are using the latest version of the library.
We also happily accept pull requests.
BottomSheet has a default elevation 16dp while Snackbar has a default elevation 6dp. Maybe BotomSheetTheme should override the default Snackbar style to have a larger elevation.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:5 (2 by maintainers)
Top GitHub Comments
it’s either the first CoordinatorLayout in the parent chain,
With this in mind what I’m doing as a “hack” is to add an empty CoordinatorLayout into my BottomSheet layout and using it as a snackbar host.
Snackbars are then displayed properly.
Hi folks, after several rounds of brainstorming and discussion with the team, we don’t really feel there’s a perfect solution for this.
Under the current implementation we have to find a suitable parent of the provided reference view to add snackbar to - and this parent has to be a frame/relative layout-like view group. (We use the first CoordinatorLayout we find or the root.) Due to the restriction of this, we cannot avoid that the reference view (or any other views under the same parent) has a higher elevation than the snackbar; and what makes things worse is that there’s no simple way to check if two views’ visible areas are overlapped.
The best solution we can think of is making Snackbars dialogs, but this may break the existing behavior, especially we need to support all existing extensions of BaseTransientBottomBar.
We will need to spend more time on investigating the dialog solution, so let me close this issue as WAI/infeasible for now.
The solution mentioned by @michaldrabik is a good workaround, if you don’t need to set Snackbar’s anchor view. (I didn’t try it, but it may work with it as well actually.)
Another possible workaround is customizing ?attr/snackbarStyle (by default Widget.Material3.Snackbar in M3) and setting a higher elevation to it, depending on your use case.
Hope this helps!!