From 5c853cb8d8e263df1d9e3c9793103500307a6b82 Mon Sep 17 00:00:00 2001 From: dominictb Date: Wed, 4 Dec 2024 22:04:22 +0700 Subject: [PATCH] scroll cursor into view when focus --- ...roll-the-cursor-into-view-when-focus.patch | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 patches/react-native+0.75.2+025+fix-scroll-the-cursor-into-view-when-focus.patch diff --git a/patches/react-native+0.75.2+025+fix-scroll-the-cursor-into-view-when-focus.patch b/patches/react-native+0.75.2+025+fix-scroll-the-cursor-into-view-when-focus.patch new file mode 100644 index 0000000000000..00124f144a2e7 --- /dev/null +++ b/patches/react-native+0.75.2+025+fix-scroll-the-cursor-into-view-when-focus.patch @@ -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(*_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(*_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];