Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: slow back transitions on Android < 11 in KeyboardAwareScrollView #342

Merged
merged 5 commits into from
Jan 29, 2024

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Jan 21, 2024

📜 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
telegram-cloud-document-2-5291837971429870538.mp4
telegram-cloud-document-2-5291837971429870537.mp4
telegram-cloud-document-2-5291837971429870536.mp4

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko added 🤖 android Android specific 🚀 optimization You optimize something and it becomes working faster 📚 components Anything related to the exported components of this library labels Jan 21, 2024
@kirillzyusko kirillzyusko self-assigned this Jan 21, 2024
Copy link
Contributor

github-actions bot commented Jan 21, 2024

📊 Package size report

Current size Target Size Difference
115228 bytes 114019 bytes 1209 bytes 📈

@kirillzyusko kirillzyusko changed the title fix: slow back transitions on Android < 10 in KeyboardAwareScrollView fix: slow back transitions on Android < 10 in KeyboardAwareScrollView Jan 23, 2024
@kirillzyusko kirillzyusko marked this pull request as ready for review January 29, 2024 17:08
@kirillzyusko kirillzyusko changed the title fix: slow back transitions on Android < 10 in KeyboardAwareScrollView fix: slow back transitions on Android < 11 in KeyboardAwareScrollView Jan 29, 2024
@kirillzyusko kirillzyusko merged commit 2c93b82 into main Jan 29, 2024
6 checks passed
@kirillzyusko kirillzyusko deleted the fix/335-slow-back-transitions branch January 29, 2024 18:40
@kirillzyusko kirillzyusko added the KeyboardAwareScrollView 📜 Anything related to KeyboardAwareScrollView component label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Android specific 📚 components Anything related to the exported components of this library KeyboardAwareScrollView 📜 Anything related to KeyboardAwareScrollView component 🚀 optimization You optimize something and it becomes working faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slow back scroll on KeyboardAwareScollView on some Android devices
1 participant