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

@@ -27,9 +27,7 @@
@implementation RCTTextField
{
RCTUITextField *_backedTextInput;
NSInteger _nativeEventCount;
BOOL _submitted;
UITextRange *_previousSelectionRange;
NSString *_finalText;
CGSize _previousContentSize;
}
@@ -71,26 +69,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
#pragma mark - Properties
- (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;