forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-native+0.75.2+025+fix-scroll-the-cursor-into-view-when-focus.patch
36 lines (34 loc) · 1.66 KB
/
react-native+0.75.2+025+fix-scroll-the-cursor-into-view-when-focus.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
diff --git a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
index db7cba4..6937720 100644
--- a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
+++ b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
@@ -88,6 +88,7 @@ - (void)didMoveToWindow
const auto &props = static_cast<const TextInputProps &>(*_props);
if (props.autoFocus) {
[_backedTextInputView becomeFirstResponder];
+ [self scrollCursorIntoView];
}
_didMoveToWindow = YES;
[self initializeReturnKeyType];
@@ -301,6 +302,7 @@ - (void)textInputDidBeginEditing
[self textInputDidChangeSelection];
}
+ [self scrollCursorIntoView];
if (_eventEmitter) {
static_cast<const TextInputEventEmitter &>(*_eventEmitter).onFocus([self _textInputMetrics]);
}
@@ -674,6 +676,15 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString
_lastStringStateWasUpdatedWith = attributedString;
}
+- (void)scrollCursorIntoView {
+ UITextRange *selectedRange = _backedTextInputView.selectedTextRange;
+ if (selectedRange.empty) {
+ NSInteger offsetStart = [_backedTextInputView offsetFromPosition:_backedTextInputView.beginningOfDocument
+ toPosition:selectedRange.start];
+ [_backedTextInputView scrollRangeToVisible:NSMakeRange(offsetStart, 0)];
+ }
+}
+
- (void)_setMultiline:(BOOL)multiline
{
[_backedTextInputView removeFromSuperview];