Skip to content

[iOS] Fix ScrollView stale keyboard inset after dismiss#56189

Open
Miyou wants to merge 2 commits intofacebook:mainfrom
Miyou:fix/scrollview-keyboard-inset-reset
Open

[iOS] Fix ScrollView stale keyboard inset after dismiss#56189
Miyou wants to merge 2 commits intofacebook:mainfrom
Miyou:fix/scrollview-keyboard-inset-reset

Conversation

@Miyou
Copy link

@Miyou Miyou commented Mar 23, 2026

Summary:

This fixes an iOS ScrollView bug where using automaticallyAdjustKeyboardInsets together with contentInsetAdjustmentBehavior="automatic" can leave a stale bottom gap after the keyboard is dismissed. The extra space is not cleared until the user scrolls again.

The underlying issue is that the keyboard dismissal path can call scrollToOffset with an offset that needs to be clamped against the new inset-adjusted bounds, but the current code checks for an unchanged contentOffset before that clamping happens. When adjustedContentInset shrinks after the keyboard closes, the numeric offset can compare equal while still being outside the valid range, so setContentOffset is skipped and the stale gap remains visible.

This change:

  • clamps the target offset before the equality check
  • uses the effective inset (adjustedContentInset when available) when computing the valid scroll range
  • applies the same behavior to both Paper and Fabric iOS scroll view implementations
  • adds an RNTester repro for the automaticallyAdjustKeyboardInsets + contentInsetAdjustmentBehavior="automatic" combination

Changelog:

[IOS] [FIXED] Fix ScrollView leaving stale bottom inset after keyboard dismissal when using automaticallyAdjustKeyboardInsets with automatic content inset adjustment

Test Plan:

  1. Reproduced the issue in a minimal Expo app on iOS with:
    • automaticallyAdjustKeyboardInsets
    • contentInsetAdjustmentBehavior="automatic"
    • a TextInput near the bottom of the scroll view
  2. Built the app with React Native compiled from source so the native iOS changes were used.
  3. Verified on the iOS simulator that:
    • focusing the text input moves content above the keyboard
    • dismissing the keyboard returns the content to the original position
    • no extra bottom gap remains and no manual scroll is required to reset layout
  4. Added a dedicated RNTester scenario in ScrollViewKeyboardInsetsIOSExample.js that reproduces this exact prop combination for upstream verification.

Build/validation details:

  • npx expo prebuild --platform ios --no-install
  • npx pod-install ios
  • xcodebuild -workspace ios/scrollviewautomaticallyadjustkeyboardinsetsbug.xcworkspace -scheme scrollviewautomaticallyadjustkeyboardinsetsbug -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16 Pro' build

@meta-cla
Copy link

meta-cla bot commented Mar 23, 2026

Hi @Miyou!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@Miyou Miyou marked this pull request as ready for review March 23, 2026 10:44
@meta-cla
Copy link

meta-cla bot commented Mar 23, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 23, 2026
@meta-cla
Copy link

meta-cla bot commented Mar 23, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-tools facebook-github-tools bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant