Repository navigation
Commit f6c9a85
authored
[iOS] Reset ScrollView frame when recycling
## Summary:
An interactive native-stack swipe-back with keyboard dismissal and native-driven `Animated` height updates can leave the internal `UIScrollView` with a negative frame origin. `prepareForRecycle` resets the outer component's frame, but retains the inner view's geometry. Reopening the screen reuses that offset view, shifting its content upward and leaving a gap at the bottom.
Reset `_scrollView.frame` to `self.bounds` at the end of `prepareForRecycle`.
> [!WARNING]
> To reproduce this problem I had to use new experimental shared Animated backend + drive `height` updates. And also use native-stack. I didn't find a way to reproduce it without `react-native-screens`/`native-stack`, but I strongly believe that root cause lives in `react-native` core.
[Minimal runnable reproduction](https://github.com/kirillzyusko/react-native-scrollview-recycling-repro/tree/f77137dceb5d2190278aec7400e5bcedf4a676db) | [App.js code](https://github.com/kirillzyusko/react-native-scrollview-recycling-repro/blob/f77137dceb5d2190278aec7400e5bcedf4a676db/App.js) | [Reproduction changes](kirillzyusko/react-native-scrollview-recycling-repro@f77137d)
The repro uses React Native Animated, native-stack, screens and safe-area-context. It has no Reanimated, Worklets or keyboard-controller dependency (though original problem was discovered with `react-native-keyboard-controller` ([#1200](kirillzyusko/react-native-keyboard-controller#1200)) /`react-native-reanimated`/`react-native-worklets` - in this PR I tried to isolate changes as close to bare RN as possible, but I still had to use `react-native-screens` for native navigation with gestures and all that stuff. Without navigation I didn't find a way to reproduce this problem - but repro confirms that it's not reanimated/keyboard-controlelr specific issue).
The public Experimental release preset enables the shared Animated backend and C++ Native Animated.
Related report: [react-native-keyboard-controller#1200](kirillzyusko/react-native-keyboard-controller#1200).
## Changelog:
[IOS] [FIXED] - Reset the inner ScrollView frame when recycling to prevent a stale offset on reuse.
## Test Plan:
Verified using **iPhone 16 Pro Simulator (iOS 18.5)**, Xcode 27.0, **React Native 0.87.1 / Fabric**.
### Reproduction
At the pinned reproduction commit:
```sh
yarn
bundle install
cd ios && bundle exec pod install && cd ..
yarn start
# In another terminal:
yarn ios --simulator "iPhone 16 Pro"
```
Enable the simulator's software keyboard. The interpolation constants target this device's 402 × 874 pt screen.
1. Freshly launch the app.
2. Press **Open ScrollView**.
3. Focus **Type a message** and wait for the keyboard.
4. Press **Scroll to end**.
5. Swipe back from the left phone bezel, with the keyboard initially open.
6. Press **Open ScrollView** again.
> [!IMPORTANT]
> The first opening maps native `onScroll` events to height using `Animated.event` with `useNativeDriver: true`. Keyboard dismissal triggers a second resize after 100 ms.
>
>1 parent edf2b86 commit f6c9a85
1 file changed
Lines changed: 1 addition & 0 deletions
File tree
- packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
725 | 725 | | |
726 | 726 | | |
727 | 727 | | |
| 728 | + | |
728 | 729 | | |
729 | 730 | | |
730 | 731 | | |
| |||
0 commit comments