mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-07 23:27:05 +08:00
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:
committed by
Facebook Github Bot
parent
ee9697e515
commit
da9a183e81
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user