diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 78e51a9b4f5..114bc21478b 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -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 diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index f8ec40bd1ab..d41fe7cd3fd 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -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 diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputNativeCommands.h b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputNativeCommands.h index 889a980703f..61fb33c08fb 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputNativeCommands.h +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputNativeCommands.h @@ -51,23 +51,7 @@ RCTTextInputHandleCommand(id 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 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 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 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