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.38k stars 55 forks source link

fix: random scrolls of `KeyboardAwareScrollView` during re-render (when keyboard is open) #477

Closed kirillzyusko closed 2 weeks ago

kirillzyusko commented 2 weeks ago

📜 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 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.

Closes https://github.com/kirillzyusko/react-native-keyboard-controller/issues/476 https://github.com/kirillzyusko/react-native-keyboard-controller/issues/384

📢 Changelog

JS

🤔 How Has This Been Tested?

Tested on CI.

📸 Screenshots (if appropriate):

Before After
image image

📝 Checklist

github-actions[bot] commented 2 weeks ago

📊 Package size report

Current size Target Size Difference
144234 bytes 144061 bytes 173 bytes 📈