Fixed random KeyboardAwareScrollView scrolls when user types a message on Android < 11.
💡 Motivation and Context
The problem happens when you update a state/props and KeyboardAwareScrollView gets re-rendered. In this case handler object gets re-created and useAnimatedReaction produce a new onMove/onEnd events.
Since we didn't call onStart -> we have out-of-date variables and because of that scroll happens to undesired position. The fix should be simple - onMove shouldn't be fired. So to fix that I changed [handler] -> deps (actually handler will be rebuild and new version will be used only when deps were updated -> otherwise new handler will not be used - this is how useKeyboardHandler hook works).
Additionally I cast deps to unknown to avoid types mismatches between REA and React.
📜 Description
Fixed random
KeyboardAwareScrollView
scrolls when user types a message on Android < 11.💡 Motivation and Context
The problem happens when you update a state/props and
KeyboardAwareScrollView
gets re-rendered. In this casehandler
object gets re-created anduseAnimatedReaction
produce a newonMove
/onEnd
events.Since we didn't call
onStart
-> we have out-of-date variables and because of that scroll happens to undesired position. The fix should be simple -onMove
shouldn't be fired. So to fix that I changed[handler] -> deps
(actually handler will be rebuild and new version will be used only when deps were updated -> otherwise new handler will not be used - this is howuseKeyboardHandler
hook works).Additionally I cast
deps
tounknown
to avoid types mismatches betweenREA
andReact
.Closes https://github.com/kirillzyusko/react-native-keyboard-controller/issues/476 https://github.com/kirillzyusko/react-native-keyboard-controller/issues/384
📢 Changelog
JS
deps
instead of[handler]
as an array of dependencies;🤔 How Has This Been Tested?
Tested on CI.
📸 Screenshots (if appropriate):
📝 Checklist