nowinandroid icon indicating copy to clipboard operation
nowinandroid copied to clipboard

[Bug]: Snackbar appears in the wrong position when the keyboard is visible

Open henni99 opened this issue 7 months ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Is there a StackOverflow question about this issue?

  • [x] I have searched StackOverflow

What happened?

Problem

When the network is disconnected, a Snackbar appears correctly above the BottomNavigation. However, when a search is attempted and the keyboard is shown, the Snackbar also moves upward — but it moves up too far. It looks as if excessive keyboard padding is being applied to the Snackbar, causing it to appear much higher than expected.

The problem arises because both the system and Compose apply IME insets independently:

  • System: Uses InsetsListener to apply IME insets
  • Compose: Applies the same insets again via WindowInsets.ime

As a result, excessive padding appears above the IME — causing UI elements like Snackbars to shift too far upwards. In short, the same WindowInsets are applied twice, resulting in duplicated padding.

https://github.com/user-attachments/assets/8122d441-2798-4f7f-806d-ed9523d334ed

Solution

I implemented a custom modifier that adjusts the composable’s padding based on the bottom of the window. As shown in the video below, it works correctly.

https://github.com/user-attachments/assets/2e108cb4-6a42-439a-a38a-911c9a2527ea

If you find this issue reasonable, I would appreciate it if you could assign me to it.

Relevant logcat output


Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

henni99 avatar Apr 13 '25 11:04 henni99

@henni99 The keyboard hiding animation in your solution's video is significantly slow. Not sure if it's correct solution for compose or not. Also, you can upload your solution anytime, you don't have to wait to be assigned.

anhtuannd avatar Apr 13 '25 14:04 anhtuannd

I think this problem is not because of the double ime, but because the scaffold location is in NavigationSuiteScaffold, and it turns out that the snackbar is displayed with an indent of the imepadding + the height of the bottomnavbar (80dp)

danl12 avatar May 10 '25 16:05 danl12