diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm index 826ff3a0de2..72cf885c37e 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm @@ -375,14 +375,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame) - (void)textInputDidBeginEditing { - if (_clearTextOnFocus) { - self.backedTextInputView.attributedText = [NSAttributedString new]; - } - - if (_selectTextOnFocus) { - [self.backedTextInputView selectAll:nil]; - } - [_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus reactTag:self.reactTag text:[self.backedTextInputView.attributedText.string copy] @@ -600,6 +592,14 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame) - (void)reactFocus { [self.backedTextInputView reactFocus]; + + if (_clearTextOnFocus) { + self.backedTextInputView.attributedText = [NSAttributedString new]; + } + + if (_selectTextOnFocus) { + [self.backedTextInputView selectAll:nil]; + } } - (void)reactBlur diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index 369cdf656a3..51914b7448e 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -280,18 +280,6 @@ static NSSet *returnKeyTypesSet; - (void)textInputDidBeginEditing { - const auto &props = static_cast(*_props); - - if (props.traits.clearTextOnFocus) { - _backedTextInputView.attributedText = nil; - [self textInputDidChange]; - } - - if (props.traits.selectTextOnFocus) { - [_backedTextInputView selectAll:nil]; - [self textInputDidChangeSelection]; - } - if (_eventEmitter) { static_cast(*_eventEmitter).onFocus([self _textInputMetrics]); } @@ -431,6 +419,18 @@ static NSSet *returnKeyTypesSet; - (void)focus { [_backedTextInputView becomeFirstResponder]; + + const auto &props = static_cast(*_props); + + if (props.traits.clearTextOnFocus) { + _backedTextInputView.attributedText = nil; + [self textInputDidChange]; + } + + if (props.traits.selectTextOnFocus) { + [_backedTextInputView selectAll:nil]; + [self textInputDidChangeSelection]; + } } - (void)blur