kirillzyusko / react-native-keyboard-controller

Keyboard manager which works in identical way on both iOS and Android
https://kirillzyusko.github.io/react-native-keyboard-controller/
MIT License
1.54k stars 61 forks source link

fix: `KeyboardAvoidingView` is not reacting on keyboard movements if was mounted when keyboard is open #391

Closed kirillzyusko closed 5 months ago

kirillzyusko commented 5 months ago

πŸ“œ Description

Update initialFrame on first render.

πŸ’‘ Motivation and Context

The problem with the old condition is the case when screen that uses KeyboardAvoidingView is pushed/gets mounted and the keyboard is already in open state. In this case we don't update initialFrame (because we update it only when onLayout is fired and keyboard is closed - to avoid concurrent re-calculations) and it remains always null. As a result relativeKeyboardHeight returns 0 and we interpolate from [0, 1] to [0, 0], so our padding will be always 0.

In this PR I'm fixing this problem by adding initialFrame.value === null condition. Such check will be executed only on initial mount. And since relativeKeyboardHeight returns 0 when initialFrame.value === null -> we will not have concurrent calculations that can interfere with each other.

πŸ“’ Changelog

JS

πŸ€” How Has This Been Tested?

Tested manually on iPhone 15 Pro (iOS 17.2, simulator).

πŸ“Έ Screenshots (if appropriate):

Before After

πŸ“ Checklist

github-actions[bot] commented 5 months ago

πŸ“Š Package size report

Current size Target Size Difference
129630 bytes 129578 bytes 52 bytes πŸ“ˆ