Skip to content

Commit ca5ead8

Browse files
committed
Improve native text field keyboard offsetting
1 parent 8798130 commit ca5ead8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#import <React/RCTTextAttributes.h>
2121
#import <React/RCTTextSelection.h>
2222

23-
/** Native iOS empty text field bottom keyboard offset amount */
24-
static const CGFloat kEmptyKeyboardBottomOffset = 15.0;
23+
/** Native iOS text field bottom keyboard offset amount */
24+
static const CGFloat kSingleLineKeyboardBottomOffset = 15.0;
2525

2626
@implementation RCTBaseTextInputView {
2727
__weak RCTBridge *_bridge;
@@ -45,11 +45,12 @@ - (void)reactUpdateResponderOffsetForScrollView:(RCTScrollView *)scrollView
4545
scrollView.firstResponderFocus = [self convertRect:self.bounds toView:nil];
4646
} else {
4747
// Focus on text selection frame
48+
BOOL isMultiline = [self.backedTextInputView isKindOfClass:[UITextView class]];
4849
CGRect focusRect = CGRectMake(
4950
selection.rect.origin.x,
5051
selection.rect.origin.y,
5152
selection.rect.size.width,
52-
selection.rect.size.height + (selectedTextRange.empty ? kEmptyKeyboardBottomOffset : 0)
53+
selection.rect.size.height + (isMultiline ? 0 : kSingleLineKeyboardBottomOffset)
5354
);
5455
scrollView.firstResponderFocus = [self convertRect:focusRect toView:nil];
5556
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
331331
if ([[UIApplication sharedApplication] sendAction:@selector(reactUpdateResponderOffsetForScrollView:) to:nil from:self forEvent:nil]) {
332332
// Inner text field focused
333333
CGFloat focusEnd = CGRectGetMaxY(self.firstResponderFocus);
334-
if (focusEnd > endFrame.origin.y && focusEnd != INFINITY) {
334+
BOOL didFocusExternalTextField = focusEnd == INFINITY;
335+
if (!didFocusExternalTextField && focusEnd > endFrame.origin.y) {
335336
// Text field active region is below visible area with keyboard - update diff to bring into view
336337
contentDiff = endFrame.origin.y - focusEnd;
337338
}

0 commit comments

Comments
 (0)