Skip to content

Commit 08976e4

Browse files
zhongwuzwblakef
authored andcommitted
automaticallyAdjustKeyboardInsets not shifting scrollview content (#46732)
Summary: Fixes #46595 . It seems #37766 broke the `automaticallyAdjustKeyboardInsets` when input accessory view become first responder. [IOS] [FIXED] - automaticallyAdjustKeyboardInsets not shifting scrollview content Pull Request resolved: #46732 Test Plan: Repro please see in ##46595 . Reviewed By: cipolleschi Differential Revision: D65072478 Pulled By: javache fbshipit-source-id: 7d5d7566438d4bb0e1d50074a953b18866e324d3
1 parent 94e2b5b commit 08976e4

6 files changed

Lines changed: 14 additions & 0 deletions

File tree

packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ - (void)reactUpdateResponderOffsetForScrollView:(RCTScrollView *)scrollView
3636
{
3737
if (![self isDescendantOfView:scrollView]) {
3838
// View is outside scroll view
39+
scrollView.firstResponderViewOutsideScrollView = self.backedTextInputView;
3940
return;
4041
}
4142

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ NS_ASSUME_NONNULL_BEGIN
3838
/** Focus area of newly-activated text input relative to the window to compare against UIKeyboardFrameBegin/End */
3939
@property (nonatomic, assign) CGRect firstResponderFocus;
4040

41+
/** newly-activated text input outside of the scroll view */
42+
@property (nonatomic, weak) UIView *firstResponderViewOutsideScrollView;
43+
4144
/*
4245
* Returns the subview of the scroll view that the component uses to mount all subcomponents into. That's useful to
4346
* separate component views from auxiliary views to be able to reliably implement pull-to-refresh- and RTL-related

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
182182
UIViewAnimationCurve curve =
183183
(UIViewAnimationCurve)[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue];
184184
CGRect keyboardEndFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
185+
CGRect keyboardBeginFrame = [notification.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
185186

186187
CGPoint absoluteViewOrigin = [self convertPoint:self.bounds.origin toView:nil];
187188
CGFloat scrollViewLowerY = isInverted ? absoluteViewOrigin.y : absoluteViewOrigin.y + self.bounds.size.height;

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ - (void)reactUpdateResponderOffsetForScrollView:(RCTScrollViewComponentView *)sc
126126
{
127127
if (![self isDescendantOfView:scrollView.scrollView] || !_backedTextInputView.isFirstResponder) {
128128
// View is outside scroll view or it's not a first responder.
129+
scrollView.firstResponderViewOutsideScrollView = _backedTextInputView;
129130
return;
130131
}
131132

packages/react-native/React/Views/ScrollView/RCTScrollView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
@property (nonatomic, assign) BOOL inverted;
5151
/** Focus area of newly-activated text input relative to the window to compare against UIKeyboardFrameBegin/End */
5252
@property (nonatomic, assign) CGRect firstResponderFocus;
53+
/** newly-activated text input outside of the scroll view */
54+
@property (nonatomic, weak) UIView *firstResponderViewOutsideScrollView;
5355

5456
// NOTE: currently these event props are only declared so we can export the
5557
// event names to JS - we don't call the blocks directly because scroll events

packages/react-native/React/Views/ScrollView/RCTScrollView.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
338338
if (!didFocusExternalTextField && focusEnd > endFrame.origin.y) {
339339
// Text field active region is below visible area with keyboard - update diff to bring into view
340340
contentDiff = endFrame.origin.y - focusEnd;
341+
} else {
342+
UIView *inputAccessoryView = _firstResponderViewOutsideScrollView.inputAccessoryView;
343+
if (inputAccessoryView) {
344+
// Text input view is within the inputAccessoryView.
345+
contentDiff = endFrame.origin.y - beginFrame.origin.y;
346+
}
341347
}
342348
} else if (endFrame.origin.y <= beginFrame.origin.y) {
343349
// Keyboard opened for other reason

0 commit comments

Comments
 (0)