From b8f1bb50f7734cbccb19808aae6f86a92fa8eea5 Mon Sep 17 00:00:00 2001 From: Prakash Gurung Date: Tue, 24 Jan 2023 03:25:25 -0800 Subject: [PATCH] Fix ScrollView automaticallyAdjustKeyboardInsets not resetting when Prefer Cross-Fade Transitions is enabled (#35933) Summary: Similar to the issue here https://github.com/facebook/react-native/pull/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 [IOS] [FIXED] - Fix ScrollView `automaticallyAdjustKeyboardInsets` not resetting when Prefer Cross-Fade Transitions is enabled and keyboard hides Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- React/Views/ScrollView/RCTScrollView.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/React/Views/ScrollView/RCTScrollView.m b/React/Views/ScrollView/RCTScrollView.m index f0f64021aca..f9819b47bc3 100644 --- a/React/Views/ScrollView/RCTScrollView.m +++ b/React/Views/ScrollView/RCTScrollView.m @@ -331,6 +331,16 @@ static inline UIViewAnimationOptions animationOptionsWithCurve(UIViewAnimationCu 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)