mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Validate selection range passed to setTextAndSelection
Summary: Changelog: [Internal] # Fabric 1. If `start` and `end` parameters in `setTextAndSelection` are -1, we don't move the cursor. Previously the cursor would be moved to beginning of text input. 2. In view commands, do not validate `eventCount`. It is passed in as undefined from JS because Fabric's text input doesn't use `eventCount`. # Paper 1. If `start` and `end` parameters in `setTextAndSelection` are -1, we don't move the cursor. Previously the cursor would be moved to beginning of text input. Reviewed By: shergin Differential Revision: D20538290 fbshipit-source-id: c7aeddc25f58697254474058ce901df958321f7c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fb9a7be2bd
commit
56cf99a96e
@@ -208,8 +208,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
||||
offset:start];
|
||||
UITextPosition *endPosition = [self.backedTextInputView positionFromPosition:self.backedTextInputView.beginningOfDocument
|
||||
offset:end];
|
||||
UITextRange *range = [self.backedTextInputView textRangeFromPosition:startPosition toPosition:endPosition];
|
||||
[self.backedTextInputView setSelectedTextRange:range notifyDelegate:NO];
|
||||
if (startPosition && endPosition) {
|
||||
UITextRange *range = [self.backedTextInputView textRangeFromPosition:startPosition toPosition:endPosition];
|
||||
[self.backedTextInputView setSelectedTextRange:range notifyDelegate:NO];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTextContentType:(NSString *)type
|
||||
|
||||
@@ -387,8 +387,11 @@ using namespace facebook::react;
|
||||
offset:start];
|
||||
UITextPosition *endPosition = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument
|
||||
offset:end];
|
||||
UITextRange *range = [_backedTextInputView textRangeFromPosition:startPosition toPosition:endPosition];
|
||||
[_backedTextInputView setSelectedTextRange:range notifyDelegate:NO];
|
||||
|
||||
if (startPosition && endPosition) {
|
||||
UITextRange *range = [_backedTextInputView textRangeFromPosition:startPosition toPosition:endPosition];
|
||||
[_backedTextInputView setSelectedTextRange:range notifyDelegate:NO];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -51,23 +51,7 @@ RCTTextInputHandleCommand(id<RCTTextInputViewProtocol> componentView, NSString c
|
||||
}
|
||||
|
||||
if ([commandName isEqualToString:@"setMostRecentEventCount"]) {
|
||||
#if RCT_DEBUG
|
||||
if ([args count] != 1) {
|
||||
RCTLogError(
|
||||
@"%@ command %@ received %d arguments, expected %d.", @"TextInput", commandName, (int)[args count], 1);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
NSObject *arg0 = args[0];
|
||||
#if RCT_DEBUG
|
||||
if (!RCTValidateTypeOfViewCommandArgument(arg0, [NSNumber class], @"number", @"TextInput", commandName, @"1st")) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
NSInteger eventCount = [(NSNumber *)arg0 intValue];
|
||||
|
||||
[componentView setMostRecentEventCount:eventCount];
|
||||
[componentView setMostRecentEventCount:0];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,13 +64,7 @@ RCTTextInputHandleCommand(id<RCTTextInputViewProtocol> componentView, NSString c
|
||||
}
|
||||
#endif
|
||||
|
||||
NSObject *arg0 = args[0];
|
||||
#if RCT_DEBUG
|
||||
if (!RCTValidateTypeOfViewCommandArgument(arg0, [NSNumber class], @"number", @"TextInput", commandName, @"1st")) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
NSInteger eventCount = [(NSNumber *)arg0 intValue];
|
||||
NSInteger eventCount = 0;
|
||||
|
||||
NSObject *arg1 = args[1];
|
||||
#if RCT_DEBUG
|
||||
@@ -100,7 +78,7 @@ RCTTextInputHandleCommand(id<RCTTextInputViewProtocol> componentView, NSString c
|
||||
|
||||
NSObject *arg2 = args[2];
|
||||
#if RCT_DEBUG
|
||||
if (!RCTValidateTypeOfViewCommandArgument(arg0, [NSNumber class], @"number", @"TextInput", commandName, @"3rd")) {
|
||||
if (!RCTValidateTypeOfViewCommandArgument(arg2, [NSNumber class], @"number", @"TextInput", commandName, @"3rd")) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -108,7 +86,7 @@ RCTTextInputHandleCommand(id<RCTTextInputViewProtocol> componentView, NSString c
|
||||
|
||||
NSObject *arg3 = args[3];
|
||||
#if RCT_DEBUG
|
||||
if (!RCTValidateTypeOfViewCommandArgument(arg0, [NSNumber class], @"number", @"TextInput", commandName, @"4th")) {
|
||||
if (!RCTValidateTypeOfViewCommandArgument(arg3, [NSNumber class], @"number", @"TextInput", commandName, @"4th")) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user