react-native-safe-area-context icon indicating copy to clipboard operation
react-native-safe-area-context copied to clipboard

Android: Top inset is changed on keyboard dismissal when windowSoftInputMode = adjustPan

Open petekp opened this issue 7 years ago • 7 comments

Not sure if this is the expected behavior, but when windowSoftInputMode is set to adjustPan, the top inset changes significantly after opening and dismissing the keyboard, i.e. the top inset can increase from 0 to over 100 after the keyboard is dismissed.

On Android, the adjustPan input mode automatically shifts the screen upward so that focused text inputs are moved above the software keyboard. This input mode is often recommended for handling input/keyboard avoidance on Android due to inconsistent behavior with KeyboardAvoidingView. I assume that when the app screen is shifted back downwards, the top inset value is set to the Y offset value used to pan the view back into its original position.

If this is expected behavior, it seems inconsistent in that the bottom inset doesn't change when the pan-upwards effect is performed upon opening the keyboard.

In my particular use case, the fact that the adjustPan mode affects insets makes it difficult to rely on the safe area context insets in places that are intended to account only for the presence of notches: I'm using the top inset to add top padding to a navigation bar but the padding value jumps in size after dismissing the keyboard.

petekp avatar Dec 02 '19 16:12 petekp

Have same issue for Android 9.

  1. focus input field.
  2. hide keyboard with this button image
  3. Got large top padding image

sshmyg avatar Dec 06 '19 12:12 sshmyg

as investigation for https://github.com/react-navigation/stack/issues/326 looks like if you have windowSoftInputMode is set to adjustPan code here: https://github.com/th3rdwave/react-native-safe-area-context/blob/master/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.java#L69 is executed when view is moved and keyboard is still visible, so its generating wrong number which is breaking calculation in next lines.

I am not Android dev and I am not sure if i can help fixing this in code 😭 hope my investigation is helping, at least something 👍

alimek avatar Jan 02 '20 22:01 alimek

I decided to use react-native-status-bar-height in my project

henry25225 avatar Jan 06 '20 02:01 henry25225

Same issue here. For now using react-native-status-bar-height as @ninjacoder95 suggested.

papigers avatar Jan 07 '20 23:01 papigers

@ninjacoder95 @papigers I'm unsure how knowing the status bar height would get around this particular issue. The problem I ran into was the top inset increasing drastically after dismissing the keyboard, often to an arbitrary size not apparently based on the dimensions of other elements (status bar, keyboard height, notch sizes, etc).

Update: I saw the related react-navigation issue (https://github.com/react-navigation/stack/issues/326#issuecomment-570355089) — I'm not using this library but looks like the temporary fix is fixing your top inset to the status bar's height?

petekp avatar Jan 07 '20 23:01 petekp

Thanks for the detailed repro, looking at this issue today.

janicduplessis avatar Feb 05 '20 20:02 janicduplessis

Fixed in 0.7.0

janicduplessis avatar Feb 05 '20 23:02 janicduplessis