-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53566 from dominictb/fix/48122-scroll-cursor-into…
…-view-when-focus scroll cursor into view when focus
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
patches/react-native+0.75.2+025+fix-scroll-the-cursor-into-view-when-focus.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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]; |