-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[useAnimatedKeyboard][iOS] Keyboard interpolation #5705
Conversation
…ftware-mansion/react-native-reanimated into @piaskowyk/ios-keyboard-interpolation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good to me, but I don't really know much about this part of iOS Reanimated. Please make sure that those changes work when you rapidly switch focus between TextInputs.
I can confirm that, the focus switching between two inputs works correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like equation
A legend was born. And then did this pull request. Thanks. |
Summary
The
useAnimatedKeyboard()
hook doesn't sync with the keyboard animation because keyboard animations use CAAnimations that are computed on the window server. This means they have their own timer and presentation layer. The info we get about the actual keyboard height is just an approximation of the real size shown by the window server.Our hook, on the other hand, uses a DisplayLink timer, which is different from the CAAnimation timer. With this PR, we are adding a function that attempts to better estimate the keyboard position using easing and Bezier curves. While this solution might not be perfect down to the pixel because window server animations aren't entirely straightforward, it's still a big improvement compared to before.
The Bezier curves are based on the measured keyboard height from screen recordings, and then I adjusted the curves to fit them better.
Basic estimation function:
Where:
Example of curve:
Keyboard appearing: https://www.desmos.com/calculator/aw4ocksord
Keyboard hiding: https://www.desmos.com/calculator/6zay2c6jou
Related info: https://forums.developer.apple.com/forums/thread/712762
Comparison
before.mp4
after.mp4
Test plan
code