TextInput setSelection method was moved to base class

Summary: This method was identical between two subclasses, so it was moved to baseclass.

Reviewed By: javache

Differential Revision: D5297401

fbshipit-source-id: 8f56bef33f9ab0184f69da76177b5e8da10d7514
This commit is contained in:
Valentin Shergin
2017-07-18 14:33:33 -07:00
committed by Facebook Github Bot
parent ee9697e515
commit da9a183e81
6 changed files with 29 additions and 46 deletions

View File

@@ -30,12 +30,10 @@
RCTText *_richTextView;
NSAttributedString *_pendingAttributedText;
UITextRange *_previousSelectionRange;
NSString *_predictedText;
BOOL _blockTextShouldChange;
BOOL _nativeUpdatesInFlight;
NSInteger _nativeEventCount;
}
- (instancetype)initWithBridge:(RCTBridge *)bridge
@@ -208,26 +206,6 @@ static NSAttributedString *removeReactTagFromString(NSAttributedString *string)
[self setNeedsLayout];
}
- (void)setSelection:(RCTTextSelection *)selection
{
if (!selection) {
return;
}
UITextRange *currentSelection = _backedTextInput.selectedTextRange;
UITextPosition *start = [_backedTextInput positionFromPosition:_backedTextInput.beginningOfDocument offset:selection.start];
UITextPosition *end = [_backedTextInput positionFromPosition:_backedTextInput.beginningOfDocument offset:selection.end];
UITextRange *selectedTextRange = [_backedTextInput textRangeFromPosition:start toPosition:end];
NSInteger eventLag = _nativeEventCount - _mostRecentEventCount;
if (eventLag == 0 && ![currentSelection isEqual:selectedTextRange]) {
_previousSelectionRange = selectedTextRange;
_backedTextInput.selectedTextRange = selectedTextRange;
} else if (eventLag > RCTTextUpdateLagWarningThreshold) {
RCTLogWarn(@"Native TextInput(%@) is %zd events ahead of JS - try to make your JS faster.", self.text, eventLag);
}
}
- (NSString *)text
{
return _backedTextInput.text;