Use ConcreteStateTeller in RCTTextInputComponentView

Summary: Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D23216864

fbshipit-source-id: 2b82e2d43cc694251a1873ad9059eff4abca4e73
This commit is contained in:
Samuel Susla
2020-08-24 06:39:29 -07:00
committed by Facebook GitHub Bot
parent 2bc8ce1549
commit e454863bca
@@ -29,7 +29,7 @@ using namespace facebook::react;
@end
@implementation RCTTextInputComponentView {
TextInputShadowNode::ConcreteState::Shared _state;
TextInputShadowNode::ConcreteStateTeller _stateTeller;
UIView<RCTBackedTextInputViewProtocol> *_backedTextInputView;
NSUInteger _mostRecentEventCount;
NSAttributedString *_lastStringStateWasUpdatedWith;
@@ -214,21 +214,21 @@ using namespace facebook::react;
- (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState
{
_state = std::static_pointer_cast<TextInputShadowNode::ConcreteState const>(state);
_stateTeller.setConcreteState(state);
if (!_state) {
if (!_stateTeller.isValid()) {
assert(false && "State is `null` for <TextInput> component.");
_backedTextInputView.attributedText = nil;
return;
}
auto data = _state->getData();
auto data = _stateTeller.getData().value();
if (!oldState) {
_mostRecentEventCount = _state->getData().mostRecentEventCount;
_mostRecentEventCount = data.mostRecentEventCount;
}
if (_mostRecentEventCount == _state->getData().mostRecentEventCount) {
if (_mostRecentEventCount == data.mostRecentEventCount) {
_comingFromJS = YES;
[self _setAttributedString:RCTNSAttributedStringFromAttributedStringBox(data.attributedStringBox)];
_comingFromJS = NO;
@@ -251,7 +251,7 @@ using namespace facebook::react;
[super prepareForRecycle];
_backedTextInputView.attributedText = nil;
_mostRecentEventCount = 0;
_state.reset();
_stateTeller.invalidate();
_comingFromJS = NO;
_lastStringStateWasUpdatedWith = nil;
_ignoreNextTextInputCall = NO;
@@ -442,16 +442,17 @@ using namespace facebook::react;
- (void)_updateState
{
if (!_state) {
if (!_stateTeller.isValid()) {
return;
}
NSAttributedString *attributedString = _backedTextInputView.attributedText;
auto data = _state->getData();
auto data = _stateTeller.getData().value();
_lastStringStateWasUpdatedWith = attributedString;
data.attributedStringBox = RCTAttributedStringBoxFromNSAttributedString(attributedString);
_mostRecentEventCount += _comingFromJS ? 0 : 1;
data.mostRecentEventCount = _mostRecentEventCount;
_state->updateState(std::move(data));
_stateTeller.updateState(std::move(data));
}
- (AttributedString::Range)_selectionRange