diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index 710f845589c..d41fe7cd3fd 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -28,7 +28,7 @@ using namespace facebook::react; @implementation RCTTextInputComponentView { TextInputShadowNode::ConcreteState::Shared _state; UIView *_backedTextInputView; - BOOL _ignoreStateUpdate; + size_t _stateRevision; } - (instancetype)initWithFrame:(CGRect)frame @@ -41,7 +41,7 @@ using namespace facebook::react; _backedTextInputView = props.traits.multiline ? [[RCTUITextView alloc] init] : [[RCTUITextField alloc] init]; _backedTextInputView.frame = self.bounds; _backedTextInputView.textInputDelegate = self; - _ignoreStateUpdate = NO; + _stateRevision = State::initialRevisionValue; [self addSubview:_backedTextInputView]; } @@ -166,9 +166,10 @@ using namespace facebook::react; return; } - if (!_ignoreStateUpdate) { + if (_state->getRevision() != _stateRevision) { auto data = _state->getData(); - [self _setAttributedString:RCTNSAttributedStringFromAttributedStringBox(data.attributedStringBox)]; + _stateRevision = _state->getRevision(); + _backedTextInputView.attributedText = RCTNSAttributedStringFromAttributedStringBox(data.attributedStringBox); } } @@ -183,18 +184,12 @@ using namespace facebook::react; RCTUIEdgeInsetsFromEdgeInsets(layoutMetrics.contentInsets - layoutMetrics.borderWidth); } -- (void)_setAttributedString:(NSAttributedString *)attributedString -{ - UITextRange *selectedRange = [_backedTextInputView selectedTextRange]; - _backedTextInputView.attributedText = attributedString; - [_backedTextInputView setSelectedTextRange:selectedRange notifyDelegate:NO]; -} - - (void)prepareForRecycle { [super prepareForRecycle]; _backedTextInputView.attributedText = [[NSAttributedString alloc] init]; _state.reset(); + _stateRevision = State::initialRevisionValue; } #pragma mark - RCTComponentViewProtocol @@ -333,9 +328,8 @@ using namespace facebook::react; auto data = _state->getData(); data.attributedStringBox = RCTAttributedStringBoxFromNSAttributedString(attributedString); - _ignoreStateUpdate = YES; _state->updateState(std::move(data), EventPriority::SynchronousUnbatched); - _ignoreStateUpdate = NO; + _stateRevision = _state->getRevision() + 1; } - (AttributedString::Range)_selectionRange @@ -385,7 +379,7 @@ using namespace facebook::react; [[NSMutableAttributedString alloc] initWithAttributedString:_backedTextInputView.attributedText]; [mutableString replaceCharactersInRange:NSMakeRange(0, _backedTextInputView.attributedText.length) withString:value]; - [self _setAttributedString:mutableString]; + _backedTextInputView.attributedText = mutableString; [self _updateState]; } diff --git a/ReactCommon/fabric/components/textinput/iostextinput/TextInputShadowNode.cpp b/ReactCommon/fabric/components/textinput/iostextinput/TextInputShadowNode.cpp index 38ab5d2c7ae..0912e891324 100644 --- a/ReactCommon/fabric/components/textinput/iostextinput/TextInputShadowNode.cpp +++ b/ReactCommon/fabric/components/textinput/iostextinput/TextInputShadowNode.cpp @@ -69,19 +69,9 @@ void TextInputShadowNode::setTextLayoutManager( void TextInputShadowNode::updateStateIfNeeded() { ensureUnsealed(); - auto attributedStringFromJS = getAttributedString(); - bool hasJSUpdatedAttributedString = false; - if (getState()) { - hasJSUpdatedAttributedString = - attributedStringFromJS.compareTextAttributesWithoutFrame( - getStateData().lastAttributedStringFromJS); - } - - if (!getState() || getState()->getRevision() == State::initialRevisionValue || - hasJSUpdatedAttributedString) { + if (!getState() || getState()->getRevision() == State::initialRevisionValue) { auto state = TextInputState{}; - state.attributedStringBox = AttributedStringBox{attributedStringFromJS}; - state.lastAttributedStringFromJS = attributedStringFromJS; + state.attributedStringBox = AttributedStringBox{getAttributedString()}; state.paragraphAttributes = getConcreteProps().paragraphAttributes; state.layoutManager = textLayoutManager_; setStateData(std::move(state)); diff --git a/ReactCommon/fabric/components/textinput/iostextinput/TextInputState.h b/ReactCommon/fabric/components/textinput/iostextinput/TextInputState.h index 57ec10d2614..7c6773c8477 100644 --- a/ReactCommon/fabric/components/textinput/iostextinput/TextInputState.h +++ b/ReactCommon/fabric/components/textinput/iostextinput/TextInputState.h @@ -28,11 +28,6 @@ class TextInputState final { */ AttributedStringBox attributedStringBox; - /* - * Last attributed string that came from JavaScript. - */ - AttributedString lastAttributedStringFromJS; - /* * Represents all visual attributes of a paragraph of text represented as * a ParagraphAttributes.