@@ -28,7 +28,7 @@ @interface RCTTextInputComponentView () <RCTBackedTextInputDelegate, RCTTextInpu
28
28
@implementation RCTTextInputComponentView {
29
29
TextInputShadowNode::ConcreteState::Shared _state;
30
30
UIView<RCTBackedTextInputViewProtocol> *_backedTextInputView;
31
- size_t _stateRevision ;
31
+ NSUInteger _mostRecentEventCount ;
32
32
NSAttributedString *_lastStringStateWasUpdatedWith;
33
33
34
34
/*
@@ -55,7 +55,6 @@ - (instancetype)initWithFrame:(CGRect)frame
55
55
_backedTextInputView.frame = self.bounds ;
56
56
_backedTextInputView.textInputDelegate = self;
57
57
_ignoreNextTextInputCall = NO ;
58
- _stateRevision = State::initialRevisionValue;
59
58
[self addSubview: _backedTextInputView];
60
59
}
61
60
@@ -180,9 +179,8 @@ - (void)updateState:(State::Shared const &)state oldState:(State::Shared const &
180
179
return ;
181
180
}
182
181
183
- if (_state->getRevision () != _stateRevision ) {
182
+ if (_mostRecentEventCount == _state->getData (). mostRecentEventCount ) {
184
183
auto data = _state->getData ();
185
- _stateRevision = _state->getRevision ();
186
184
[self _setAttributedString: RCTNSAttributedStringFromAttributedStringBox (data.attributedStringBox)];
187
185
}
188
186
}
@@ -221,8 +219,8 @@ - (void)prepareForRecycle
221
219
{
222
220
[super prepareForRecycle ];
223
221
_backedTextInputView.attributedText = [[NSAttributedString alloc ] init ];
222
+ _mostRecentEventCount = 0 ;
224
223
_state.reset ();
225
- _stateRevision = State::initialRevisionValue;
226
224
_lastStringStateWasUpdatedWith = nil ;
227
225
_ignoreNextTextInputCall = NO ;
228
226
}
@@ -360,6 +358,7 @@ - (TextInputMetrics)_textInputMetrics
360
358
TextInputMetrics metrics;
361
359
metrics.text = RCTStringFromNSString (_backedTextInputView.attributedText .string );
362
360
metrics.selectionRange = [self _selectionRange ];
361
+ metrics.eventCount = _mostRecentEventCount;
363
362
return metrics;
364
363
}
365
364
@@ -370,12 +369,12 @@ - (void)_updateState
370
369
if (!_state) {
371
370
return ;
372
371
}
373
-
374
372
auto data = _state->getData ();
375
373
_lastStringStateWasUpdatedWith = attributedString;
376
374
data.attributedStringBox = RCTAttributedStringBoxFromNSAttributedString (attributedString);
377
- _state->updateState (std::move (data), EventPriority::SynchronousUnbatched);
378
- _stateRevision = _state->getRevision () + 1 ;
375
+ _mostRecentEventCount += 1 ;
376
+ data.mostRecentEventCount = _mostRecentEventCount;
377
+ _state->updateState (std::move (data));
379
378
}
380
379
381
380
- (AttributedString::Range)_selectionRange
@@ -407,19 +406,18 @@ - (void)blur
407
406
408
407
- (void )setMostRecentEventCount : (NSInteger )eventCount
409
408
{
410
- // no-op. `eventCount` isn't used in Fabric's TextInput.
411
- // We are keeping it so commands are backwards
412
- // compatible with Paper's TextInput.
409
+ _mostRecentEventCount = eventCount;
413
410
}
414
411
415
412
- (void )setTextAndSelection : (NSInteger )eventCount
416
413
value : (NSString *__nullable)value
417
414
start : (NSInteger )start
418
415
end : (NSInteger )end
419
416
{
420
- // `eventCount` is ignored, isn't used in Fabric's TextInput.
421
- // We are keeping it so commands are
422
- // backwards compatible with Paper's TextInput.
417
+ if (_mostRecentEventCount != eventCount) {
418
+ return ;
419
+ }
420
+
423
421
if (value) {
424
422
NSMutableAttributedString *mutableString =
425
423
[[NSMutableAttributedString alloc ] initWithAttributedString: _backedTextInputView.attributedText];
0 commit comments