Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: slow back transitions on Android < 11 in `KeyboardAwareScrollVie…
…w` (#342) ## 📜 Description Improved FPS for `KeyboardAwareScrollView` when keyboard gets closed (and scroll position is the end of the scroll view). ## 💡 Motivation and Context The fix consist of several stages. Below they are: ### 1️⃣ Incorrect `persistentHeight` update When we reset `persistentHeight` in `onEnd` we: - produce potential race condition (`persistentHeight` can be set to `0` after timing animation completion and because of that `onEnd` handler may not be fired at all) - calculate `progress` incorrectly (it can be `Infinity` or `NaN` in last frames of animation ### 2️⃣ Avoid double `onMove`/`onEnd` events If we reset `persistentHeight` to `0` in `useAnimatedReaction` (where we dispatch `onEnd`) -> we run animation effect again, and it may produce additional `onMove`/`onEnd` events after `onEnd` event. So I added `if (persistentHeight.value === 0)` check. ### 3️⃣ Don't re-calculate layout in every animation frame When we scroll to the end of ScrollView and change padding, it seems like we do a heavy layout re-calculation. That's why I added `+1` padding. Closes #335 ## 📢 Changelog ### JS - fixed `useSmoothKeyboardHandler` for Android < 10; ## 🤔 How Has This Been Tested? Tested manually on Xiaomi Redmi Note 5 Pro. Also I use 2500ms instead of 250ms timing to see more detailed difference. ## 📸 Screenshots (if appropriate): |Original performance|With corrected `useSmoothKeyboardHandler`|With `+1` fix| |---------------------|----------------------------------------------|----------------| |<video src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/e7f95f23-ed88-4d8c-80cb-1fca06d4697f">|<video src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/fe9cc67f-61e8-40f2-8d17-b3fce4bd1c10">|<video src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/1bb7f2b6-726b-47f6-b71e-c96c2086344f"> ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
- Loading branch information