You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: new behavior="translate-with-padding" for KeyboardAvoidingView (#830)
## 📜 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](https://github.com/android/user-interface-samples/tree/main/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
<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->
### 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|
|--------|---|
|<video
src="https://github.com/user-attachments/assets/f8d35138-77ae-432e-a95b-97104a01b4fe">|<video
src="https://github.com/user-attachments/assets/93db0cdb-4ef4-4fb0-8cd4-9ada0312ff7d">|
### Fabric
|Android|iOS|
|--------|---|
|<video
src="https://github.com/user-attachments/assets/e2398edc-d6c0-41e8-8fdc-eb95e7741f74">|<video
src="https://github.com/user-attachments/assets/379567d3-5d7a-482c-81af-ab359356a11c">|
## 📝 Checklist
- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
0 commit comments