Skip to content

Commit bba6afc

Browse files
authored
perf: don't change currentKeyboardFrame each frame (#1381)
## 📜 Description Don't change keyboard padding in `KeyboardAwareScrollView` each frame as keyboard moves and do it only in the beginning of the animation (when keyboard appears) or in the end of the animation (when keyboard closed). ## 💡 Motivation and Context After #797 introduced removal of `ghost padding` we don't need to change `inset` every frame. Instead we can use an optimized approach and: - add full keyboard frame padding only in the beginning of the animation (when keyboard appears) - remove full keyboard frame padding when keyboard fully closed. Roughly it gives us `2x` less load on UI thread because now we only need to adjust scroll position inside `onMove` handler. A similar approach is already used in `KeyboardChatScrollView` (we also change padding only one time there). So these changes just makes components consistent. ## 📢 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 - don't change `currentKeyboardFrame` each frame; ## 🤔 How Has This Been Tested? Tested manually on iPhone 17 Pro (iOS 26.2, simulator), Pixel 7 Pro (API 36, real device). ## 📸 Screenshots (if appropriate): |iOS|Android| |---|--------| |<video src="https://github.com/user-attachments/assets/9e5f72cc-b6c7-4ea5-999f-d5c56c046809">|<video src="https://github.com/user-attachments/assets/31f5a675-2de8-4136-91fe-7390364bbb97">| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent ecd3bbd commit bba6afc

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

  • src/components/KeyboardAwareScrollView

src/components/KeyboardAwareScrollView/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ const KeyboardAwareScrollView = forwardRef<
416416
keyboardWillChangeSize ||
417417
focusWasChanged
418418
) {
419+
syncKeyboardFrame(e);
419420
// persist scroll value
420421
scrollPosition.value = position.value;
421422
// just persist height - later will be used in interpolation
@@ -464,8 +465,6 @@ const KeyboardAwareScrollView = forwardRef<
464465
onMove: (e) => {
465466
"worklet";
466467

467-
syncKeyboardFrame(e);
468-
469468
if (removeGhostPadding(e.height)) {
470469
return;
471470
}

0 commit comments

Comments
 (0)