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
added || initialFrame.value === null check in onLayout callback
π€ How Has This Been Tested?
Tested manually on iPhone 15 Pro (iOS 17.2, simulator).
πΈ Screenshots (if appropriate):
Before
After
π Checklist
[x] CI successfully passed
[x] I added new mocks and corresponding unit-tests if library API was changed
π 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 updateinitialFrame
(because we update it only whenonLayout
is fired and keyboard is closed - to avoid concurrent re-calculations) and it remains alwaysnull
. As a resultrelativeKeyboardHeight
returns0
and we interpolate from[0, 1]
to[0, 0]
, so ourpadding
will be always0
.In this PR I'm fixing this problem by adding
initialFrame.value === null
condition. Such check will be executed only on initial mount. And sincerelativeKeyboardHeight
returns0
wheninitialFrame.value === null
-> we will not have concurrent calculations that can interfere with each other.π’ Changelog
JS
|| initialFrame.value === null
check inonLayout
callbackπ€ How Has This Been Tested?
Tested manually on iPhone 15 Pro (iOS 17.2, simulator).
πΈ Screenshots (if appropriate):
π Checklist