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

feat: new behavior="translate-with-padding" for KeyboardAvoidingView #830

Merged
merged 8 commits into from
Feb 24, 2025

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Feb 23, 2025

📜 Description

Added new behavior="translate-with-padding" for KeyboardAvoidingView.

💡 Motivation and Context

The new mode ideally fits for chat-like applications and has very good performance.

The implementation was mostly inspired by WindowInsetsAnimation sample app. However when I tried to replace translateY to 0 and apply paddingBottom which is equal to previous translateY I had flashes on Android (mostly because of nature of Android - transform properties (e.g., translateY) only trigger a repaint (no reflow) and are applied immediately. Changes to layout properties like padding force the Android rendering system to recalculate layout (reflow), which can take an extra frame to resolve). So instead of switching those properties I decided to keep translateY and add paddingTop (in the end of animation to resize the container).

Since we change paddingTop only in the beginning or in the end of animation the transition is unbelievable smooth, because we trigger layout re-calculation only once (so in terms of complexity new approach is O(1) vs O(n)).

Closes #719 (comment) software-mansion/react-native-reanimated#6854 #650 (comment)

🔢 Things to do

  • write e2e tests for chat FlatList example screen (to cover new functionality with e2e tests);
  • update documentation page with detailed explanation of modes and when to use each of them.

📢 Changelog

JS

  • added new "translate-with-padding" behavior for KeyboardAvoidingView
  • added useTranslateAnimation hook;
  • integrate useTranslateAnimation with "translate-with-padding";
  • update example app to more performant implementation;

Docs

  • mention new behavior;

🤔 How Has This Been Tested?

Tested both paper and fabric on:

  • iPhone 15 Pro (iOS 17.5);
  • Medium phone (API 35).

📸 Screenshots (if appropriate):

Paper

Android iOS
Screen.Recording.2025-02-23.at.18.44.49.mov
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2025-02-23.at.18.46.27.mp4

Fabric

Android iOS
Screen.Recording.2025-02-23.at.18.44.49.mov
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2025-02-23.at.18.53.48.mp4

📝 Checklist

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

@kirillzyusko kirillzyusko added enhancement New feature or request KeyboardAvoidingView 🧪 Anything related to KeyboardAvoidingView component labels Feb 23, 2025
@kirillzyusko kirillzyusko self-assigned this Feb 23, 2025
Copy link
Contributor

github-actions bot commented Feb 23, 2025

📊 Package size report

Current size Target Size Difference
169483 bytes 167647 bytes 1836 bytes 📈

Copy link
Contributor

github-actions bot commented Feb 23, 2025

PR Preview Action v1.6.0
Preview removed because the pull request was closed.
2025-02-24 10:38 UTC

Copy link

argos-ci bot commented Feb 23, 2025

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) 👍 Changes approved 1 changed Feb 24, 2025, 9:50 AM

@kirillzyusko kirillzyusko marked this pull request as ready for review February 24, 2025 10:10
@kirillzyusko kirillzyusko changed the title feat: new behavior="translate" for KeyboardAvoidingView feat: new behavior="translate-with-padding" for KeyboardAvoidingView Feb 24, 2025
@kirillzyusko kirillzyusko merged commit fa6d67d into main Feb 24, 2025
21 checks passed
@kirillzyusko kirillzyusko deleted the feat/kav-new-mode branch February 24, 2025 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request KeyboardAvoidingView 🧪 Anything related to KeyboardAvoidingView component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyboardAwareScrollView on android is not as smooth as ios
1 participant