godot
godot copied to clipboard
Use the new API for virtual keyboard height detection on Android, bugfix for old API
Uses the new WindowInsetsAnimation.Callback
to get the virtual keyboard height on Android 11 or above. We can now get the interpolated height values as the animation plays, which allows us to synchronize UI with the keyboard animation. The implementation is based on this guide on Android Blog.
Uses the old approach when API level 30 is not available. However, I updated the old code to fix #41388. It works by subtracting the visible height from view height. Also it doesn't create a new Rect
on each callback anymore, decreasing the load on JVM GC.
I tested both APIs on Galaxy Note 10 Lite running Android 13 (features a navbar) in portrait orientation. (Sensor orientation seems to be broken when switching to landscape, will look into it later.)
A basic test project: keyboard_test.zip
Minor changes are required to apply this PR for the 3.x branch. 3.x version: #74399. I will update it if we make changes here.
Pinging @m4gr3d since he assigned himself to #41388.