mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Back out "Fix controlled TextInput with child nodes"
Summary: Changelog: [Internal] Original commit changeset: 1b8a2efabbfa Original diff D20587681 breaks non-controlled text input. Reviewed By: motiz88 Differential Revision: D20815935 fbshipit-source-id: 70577ed1e5701850ff0e30a6592945a31c2a8bec
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6f627f684b
commit
3d61dc9f36
@@ -28,7 +28,7 @@ using namespace facebook::react;
|
||||
@implementation RCTTextInputComponentView {
|
||||
TextInputShadowNode::ConcreteState::Shared _state;
|
||||
UIView<RCTBackedTextInputViewProtocol> *_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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user