|
| 1 | +diff --git a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm |
| 2 | +index 7ce04da..123968f 100644 |
| 3 | +--- a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm |
| 4 | ++++ b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm |
| 5 | +@@ -452,6 +452,12 @@ - (void)blur |
| 6 | + [_backedTextInputView resignFirstResponder]; |
| 7 | + } |
| 8 | + |
| 9 | ++- (void)clear |
| 10 | ++{ |
| 11 | ++ [self setTextAndSelection:_mostRecentEventCount value:@"" start:0 end:0]; |
| 12 | ++ _mostRecentEventCount++; |
| 13 | ++} |
| 14 | ++ |
| 15 | + - (void)setTextAndSelection:(NSInteger)eventCount |
| 16 | + value:(NSString *__nullable)value |
| 17 | + start:(NSInteger)start |
| 18 | +diff --git a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputNativeCommands.h b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputNativeCommands.h |
| 19 | +index fe3376a..6a9a45f 100644 |
| 20 | +--- a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputNativeCommands.h |
| 21 | ++++ b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputNativeCommands.h |
| 22 | +@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN |
| 23 | + @protocol RCTTextInputViewProtocol <NSObject> |
| 24 | + - (void)focus; |
| 25 | + - (void)blur; |
| 26 | ++- (void)clear; |
| 27 | + - (void)setTextAndSelection:(NSInteger)eventCount |
| 28 | + value:(NSString *__nullable)value |
| 29 | + start:(NSInteger)start |
| 30 | +@@ -49,6 +50,19 @@ RCTTextInputHandleCommand(id<RCTTextInputViewProtocol> componentView, const NSSt |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | ++ if ([commandName isEqualToString:@"clear"]) { |
| 35 | ++#if RCT_DEBUG |
| 36 | ++ if ([args count] != 0) { |
| 37 | ++ RCTLogError( |
| 38 | ++ @"%@ command %@ received %d arguments, expected %d.", @"TextInput", commandName, (int)[args count], 0); |
| 39 | ++ return; |
| 40 | ++ } |
| 41 | ++#endif |
| 42 | ++ |
| 43 | ++ [componentView clear]; |
| 44 | ++ return; |
| 45 | ++ } |
| 46 | ++ |
| 47 | + if ([commandName isEqualToString:@"setTextAndSelection"]) { |
| 48 | + #if RCT_DEBUG |
| 49 | + if ([args count] != 4) { |
| 50 | +diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java |
| 51 | +index 8496a7d..e6bcfc4 100644 |
| 52 | +--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java |
| 53 | ++++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java |
| 54 | +@@ -331,6 +331,12 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout |
| 55 | + } |
| 56 | + reactEditText.maybeSetSelection(mostRecentEventCount, start, end); |
| 57 | + break; |
| 58 | ++ case "clear": |
| 59 | ++ int newEventCount = reactEditText.incrementAndGetEventCounter(); |
| 60 | ++ ReactTextUpdate textUpdate = getReactTextUpdate("", newEventCount); |
| 61 | ++ reactEditText.maybeSetTextFromJS(textUpdate); |
| 62 | ++ reactEditText.maybeSetSelection(newEventCount, 0, 0); |
| 63 | ++ break; |
| 64 | + } |
| 65 | + } |
| 66 | + |
0 commit comments