Skip to content

Handle "Escape" key for TextInput #1044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Libraries/Text/TextInput/RCTBackedTextInputDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)textInputShouldHandleDeleteBackward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteBackward event handled normally. Return `NO` to disallow it and handle it yourself. TODO(OSS Candidate ISS#2710739)
#if TARGET_OS_OSX // [TODO(macOS GH#774)
- (BOOL)textInputShouldHandleDeleteForward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteForward event handled normally. Return `NO` to disallow it and handle it yourself.

- (void)textInputDidCancel; // Handle `Escape` key press.
#endif // ]TODO(macOS GH#774)

@optional
Expand Down
18 changes: 15 additions & 3 deletions Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,17 @@ - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor

- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector
{
id<RCTBackedTextInputDelegate> textInputDelegate = [_backedTextInputView textInputDelegate];
BOOL commandHandled = NO;
// enter/return
if (commandSelector == @selector(insertNewline:) || commandSelector == @selector(insertNewlineIgnoringFieldEditor:)) {
[self textFieldDidEndEditingOnExit];
if ([[_backedTextInputView textInputDelegate] textInputShouldReturn]) {
if ([textInputDelegate textInputShouldReturn]) {
[[_backedTextInputView window] makeFirstResponder:nil];
}
commandHandled = YES;
//backspace
} else if (commandSelector == @selector(deleteBackward:)) {
id<RCTBackedTextInputDelegate> textInputDelegate = [_backedTextInputView textInputDelegate];
if (textInputDelegate != nil && ![textInputDelegate textInputShouldHandleDeleteBackward:_backedTextInputView]) {
commandHandled = YES;
} else {
Expand All @@ -214,7 +214,13 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doComman
//paste
} else if (commandSelector == @selector(paste:)) {
_backedTextInputView.textWasPasted = YES;
}
//escape
} else if (commandSelector == @selector(cancelOperation:)) {
[textInputDelegate textInputDidCancel];
[[_backedTextInputView window] makeFirstResponder:nil];
commandHandled = YES;
}

return commandHandled;
}

Expand Down Expand Up @@ -411,6 +417,12 @@ - (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector
//deleteForward
} else if (commandSelector == @selector(deleteForward:)) {
commandHandled = textInputDelegate != nil && ![textInputDelegate textInputShouldHandleDeleteForward:_backedTextInputView];
//escape
} else if (commandSelector == @selector(cancelOperation:)) {
[textInputDelegate textInputDidCancel];
[_backedTextInputView.window makeFirstResponder:nil];
commandHandled = YES;

}

return commandHandled;
Expand Down
9 changes: 9 additions & 0 deletions Libraries/Text/TextInput/RCTBaseTextInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,15 @@ - (BOOL)textInputShouldHandleDeleteBackward:(__unused id)sender {
- (BOOL)textInputShouldHandleDeleteForward:(__unused id)sender {
return YES;
}

- (void)textInputDidCancel {
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeKeyPress
reactTag:self.reactTag
text:nil
key:@"Escape"
eventCount:_nativeEventCount];
[self textInputDidEndEditing];
}
#endif // ]TODO(macOS GH#774)

- (void)updateLocalData
Expand Down
60 changes: 30 additions & 30 deletions packages/rn-tester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ SPEC CHECKSUMS:
boost-for-react-native: 8f7c9ecfe357664c072ffbe2432569667cbf1f1b
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: ed15e075aa758ac0e4c1f8b830bd4e4d40d669e8
FBLazyVector: 11bc87f472827a73ff114494b2e80e0b805a32d7
FBReactNativeSpec: f58c30a99b669cb145e7a8c0c0c721de83951240
FBLazyVector: c6aa9a9619d963282360abc4bb47d2712717504e
FBReactNativeSpec: 0ca7ec65c7f09ab67e221ac5f0532b8385bc2138
Flipper: 30e8eeeed6abdc98edaf32af0cda2f198be4b733
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
Flipper-DoubleConversion: 57ffbe81ef95306cc9e69c4aa3aeeeeb58a6a28c
Expand All @@ -557,35 +557,35 @@ SPEC CHECKSUMS:
glog: 42c4bf47024808486e90b25ea9e5ac3959047641
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b
RCT-Folly: 5c589d0de10e841479ad79352fae591dc0e9533a
RCTRequired: 2eb1355625e25d08081cfe239db7d3874d77d208
RCTTypeSafety: 9f298b5aa98b080b67792676b6243f1ca032520c
React: 3cd3b5138e36d870bfefaf4a9f0e8d4d658cf499
React-callinvoker: bfbb455c76da9a24732560d956a4458057bb1021
React-Core: 160b28e71f337fa24c27937cecbeebce7af1693f
React-CoreModules: 38f6c3f85421cbbe43f26fb7eec281269f502fe1
React-cxxreact: c72a2ce5d5fa068fe72130d2530caeb8cf6e6790
React-jsi: c6a502974929a68d0c706dec909de949d3a184cf
React-jsiexecutor: 6194311bab350a51c265c42424ce3377b58e776b
React-jsinspector: 98a8edfdf1a77275d1e1ad8832ed2ca6ebe4ea61
React-logger: 745a29a1f97e1725bab7888b8d501dda06b7f485
React-perflogger: 3dcb37ac059350488c74211912731f88d4207b9a
React-RCTActionSheet: aca58af0c729d4d70e2e25565fbd6f6322b18764
React-RCTAnimation: 18e68a8ba438155cefe4b3fb91450492036aca48
React-RCTBlob: ee8067d9c6af4557a9bde315e91bac756498e91c
React-RCTImage: a4167a4967505eaa04a82f5b9573065c30ecf69e
React-RCTLinking: d9034395129c1e4d9c7e60c9deb5b987daf79554
React-RCTNetwork: 80bfb1e3f3498c067293e709a78ad07355a5b05c
React-RCTPushNotification: 899e34163eb7e632fa5164f2c1a2b8e7fb02e7a3
React-RCTSettings: 8049c8ffdd76393479d731ab350d6fd0550a7549
React-RCTTest: c2d9a4516b734322e8df43d192cc3db97d58b092
React-RCTText: 9f435bd5c5f631bf791bf60e501780192ec376af
React-RCTVibration: ed1e5e188b6ed93739d39bc23a20aa87d7eb47f0
React-runtimeexecutor: c433f9ba42e6bcc0bd5e42d2710538f3591edc02
RCT-Folly: 43adc9ce880eb76792f88c011773cb5c664c1419
RCTRequired: 633fe8690af80ea0d6d1743ea0fbeee6a8de0978
RCTTypeSafety: 2a1aa8c0ffa214900ea5e96dd1ce844be196decc
React: 4f7007b4f9f59b3d935cfc415e0b3e3dd03d2021
React-callinvoker: 775c5ec2ad1d1b7f0f4a8458397bfd68aced33a7
React-Core: b1cdd30e896e76499480e4603f5cad119d238885
React-CoreModules: c6609f09932ba5fc8dae3c20f8ba294653159370
React-cxxreact: 3d44d388b2feccc0d6b2f0735cf4ac78f71c26be
React-jsi: 743b50fb3db21ad787c384fd6601c7e3e6784dec
React-jsiexecutor: cc19fe20e9f6c261c8f1eed5727f2b724f945494
React-jsinspector: 90fbbc33233c45021327ddd921f5b91622c77190
React-logger: 4f94752a4d8e071ac861865ea5f1d341650b6d70
React-perflogger: 0eaad01e3aaefb12799c39333d0b584dd5b4dae8
React-RCTActionSheet: e80fd63af2c04195f544a51f237f0bb8c999ba02
React-RCTAnimation: 5827d917ff6c716a50b0008856ffb1772578c446
React-RCTBlob: cd43b543b917d9b66eb303dc08c4058f7b3e52c4
React-RCTImage: 9d0661b1b0de30e825cadd8b94fefb6b8485b370
React-RCTLinking: 1e0f88ba8ecc3e36fe7f4ca89e3a7bb8ba9b033d
React-RCTNetwork: c9ac771311a39f42c43ad5633f090e2d01d2710d
React-RCTPushNotification: 9398208d33368b68b6afb3887c04e3f5ae1c7049
React-RCTSettings: 99d2d69f4183c6e9ef89ba589a8dc77c6465a2c8
React-RCTTest: a57ea516520309b75fc9c152847beedf26c7926e
React-RCTText: 0732843b7d073ae2dd7687b95774a534c0fae0fb
React-RCTVibration: 8a50e8ddd4402a7b123fcfe41efd1220d1b23798
React-runtimeexecutor: 8993403523caba788cd6483b26a6e67384ec2224
React-TurboModuleCxx-RNW: f2e32cbfced49190a61d66c993a8975de79a158a
React-TurboModuleCxx-WinRTPort: 523c514e00e9136f0d048fdce302e976e24357f1
ReactCommon: 57264a0de7cd051c3495c78775056e8582988388
Yoga: a4c667843470ecfe7ed3a1bc546889f4730534c7
React-TurboModuleCxx-WinRTPort: e7647958397b6cdafa0deb18f9db886d6acf6fcf
ReactCommon: 90d5510f055f513dd4f1123ef1883062903b56b8
Yoga: d7d6de52ed443bd01bfa17cb314b95e86876289b
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: c7a7110b242497f2bf323ba74caedb9ee61ee05e
Expand Down
4 changes: 2 additions & 2 deletions packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@
ENABLE_BITCODE = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -1953,7 +1953,7 @@
ENABLE_BITCODE = NO;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
Expand Down