Skip to content

Commit 669dcff

Browse files
committed
Simplify calculating text input focus area
1 parent ca5ead8 commit 669dcff

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,19 @@ - (void)reactUpdateResponderOffsetForScrollView:(RCTScrollView *)scrollView
4040

4141
UITextRange *selectedTextRange = self.backedTextInputView.selectedTextRange;
4242
UITextSelectionRect *selection = [self.backedTextInputView selectionRectsForRange:selectedTextRange].firstObject;
43+
CGRect focusRect;
4344
if (selection == nil) {
4445
// No active selection or caret - fallback to entire input frame
45-
scrollView.firstResponderFocus = [self convertRect:self.bounds toView:nil];
46+
focusRect = self.bounds;
4647
} else {
4748
// Focus on text selection frame
49+
focusRect = selection.rect;
4850
BOOL isMultiline = [self.backedTextInputView isKindOfClass:[UITextView class]];
49-
CGRect focusRect = CGRectMake(
50-
selection.rect.origin.x,
51-
selection.rect.origin.y,
52-
selection.rect.size.width,
53-
selection.rect.size.height + (isMultiline ? 0 : kSingleLineKeyboardBottomOffset)
54-
);
55-
scrollView.firstResponderFocus = [self convertRect:focusRect toView:nil];
51+
if (!isMultiline) {
52+
focusRect.size.height += kSingleLineKeyboardBottomOffset;
53+
}
5654
}
55+
scrollView.firstResponderFocus = [self convertRect:focusRect toView:nil];
5756
}
5857

5958
- (instancetype)initWithBridge:(RCTBridge *)bridge

0 commit comments

Comments
 (0)