Skip to content

Commit

Permalink
Fix ScrollView automaticallyAdjustKeyboardInsets not resetting when P…
Browse files Browse the repository at this point in the history
…refer Cross-Fade Transitions is enabled (#35933)

Summary:
Similar to the issue here #34503 but this is also happening if we just use `ScrollView` and `TextInput` with `automaticallyAdjustKeyboardInsets` enabled.

When we enable `Prefer Cross-Fade Transitions` in `iOS` we get a keyboard height of `0` which causes the inset/offset miscalculation and the content jumps up when the keyboard gets hidden.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[IOS] [FIXED] - Fix ScrollView `automaticallyAdjustKeyboardInsets` not resetting when Prefer Cross-Fade Transitions is enabled and keyboard hides

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[IOS] [FIXED] - Fix ScrollView `automaticallyAdjustKeyboardInsets` not resetting when Prefer Cross-Fade Transitions is enabled and keyboard hides

Pull Request resolved: #35933

Test Plan:
Tested with brand new react native project with/without the fix

before fix `automaticallyAdjustKeyboardInsets` with enabled/disabled opening/closing keyboard

https://user-images.githubusercontent.com/6507800/214039873-33bfb016-f99f-4644-9174-20bf32cf07d6.mov

after fix `automaticallyAdjustKeyboardInsets` with enabled/disabled opening/closing keyboard

https://user-images.githubusercontent.com/6507800/214039887-4054a749-ab15-4399-b6a9-73dc9283aa6b.mov

Reviewed By: christophpurrer

Differential Revision: D42686390

Pulled By: jacdebug

fbshipit-source-id: 98488e0c9639c19a4acae1a1de1a5fde411e2462
  • Loading branch information
grgmo authored and facebook-github-bot committed Jan 24, 2023
1 parent efe5f62 commit b8f1bb5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions React/Views/ScrollView/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
newContentOffset.y -= contentDiff;
}

if (@available(iOS 14.0, *)) {
// On iOS when Prefer Cross-Fade Transitions is enabled, the keyboard position
// & height is reported differently (0 instead of Y position value matching height of frame)
// Fixes similar issue we saw with https://github.com/facebook/react-native/pull/34503
if (UIAccessibilityPrefersCrossFadeTransitions() && endFrame.size.height == 0) {
newContentOffset.y = 0;
newEdgeInsets.bottom = 0;
}
}

[UIView animateWithDuration:duration
delay:0.0
options:animationOptionsWithCurve(curve)
Expand Down

0 comments on commit b8f1bb5

Please sign in to comment.