Skip to content

Use WindowInsetsCompat for navigation bar height#12

Open
latidoremi wants to merge 1 commit intonschairer:mainfrom
latidoremi:fix_nav_bar_height
Open

Use WindowInsetsCompat for navigation bar height#12
latidoremi wants to merge 1 commit intonschairer:mainfrom
latidoremi:fix_nav_bar_height

Conversation

@latidoremi
Copy link

getNavigationBarHeight() and isNavigationBarVisible() can return incorrect values on some devices in gesture navigation mode, leading to wrong keyboard height calculation

On the Huawei v40 lite I have:

  • Gesture navigation + indicator bar disabled

    • Original code: height = 38, visible = true
    • Correct values: height = 0, visible = false
  • Gesture navigation + indicator bar enabled

    • Original code: height = 16
    • Correct value: height = 38
  • Button navigation

    • Original code returns the correct height of 38

I propose switching to WindowInsetsCompat to retrieve the navigation bar height:

val insets = ViewCompat.getRootWindowInsets(rootView)
val navigationBarHeight = insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom ?: 0
val isNavigationBarVisible = insets?.isVisible(WindowInsetsCompat.Type.navigationBars()) ?: false

This returns the correct values on all devices I tested (Huawei V40 Lite, Redmi K70, Samsung S9)

This may also fix #11

@latidoremi
Copy link
Author

latidoremi commented Aug 15, 2025

I also tuned down the threadshold that triggers the event, when using the google Gboard voice typing mode, you can half collapse the keyboard and the keyboard height can get pretty low, 0.15 is too high for that

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.

[Android][Huawei] The keyboard height obtained by some Huawei phones is incorrect

1 participant