Skip to content

Commit 9392051

Browse files
committed
cherry pick microsoft#1044 + pod install
1 parent ae46547 commit 9392051

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

Libraries/Text/TextInput/RCTBackedTextInputDelegate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
3636
- (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)
3737
#if TARGET_OS_OSX // [TODO(macOS GH#774)
3838
- (BOOL)textInputShouldHandleDeleteForward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteForward event handled normally. Return `NO` to disallow it and handle it yourself.
39+
40+
- (void)textInputDidCancel; // Handle `Escape` key press.
3941
#endif // ]TODO(macOS GH#774)
4042

4143
@optional

Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,17 @@ - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
187187

188188
- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector
189189
{
190+
id<RCTBackedTextInputDelegate> textInputDelegate = [_backedTextInputView textInputDelegate];
190191
BOOL commandHandled = NO;
191192
// enter/return
192193
if (commandSelector == @selector(insertNewline:) || commandSelector == @selector(insertNewlineIgnoringFieldEditor:)) {
193194
[self textFieldDidEndEditingOnExit];
194-
if ([[_backedTextInputView textInputDelegate] textInputShouldReturn]) {
195+
if ([textInputDelegate textInputShouldReturn]) {
195196
[[_backedTextInputView window] makeFirstResponder:nil];
196197
}
197198
commandHandled = YES;
198199
//backspace
199200
} else if (commandSelector == @selector(deleteBackward:)) {
200-
id<RCTBackedTextInputDelegate> textInputDelegate = [_backedTextInputView textInputDelegate];
201201
if (textInputDelegate != nil && ![textInputDelegate textInputShouldHandleDeleteBackward:_backedTextInputView]) {
202202
commandHandled = YES;
203203
} else {
@@ -214,7 +214,13 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doComman
214214
//paste
215215
} else if (commandSelector == @selector(paste:)) {
216216
_backedTextInputView.textWasPasted = YES;
217-
}
217+
//escape
218+
} else if (commandSelector == @selector(cancelOperation:)) {
219+
[textInputDelegate textInputDidCancel];
220+
[[_backedTextInputView window] makeFirstResponder:nil];
221+
commandHandled = YES;
222+
}
223+
218224
return commandHandled;
219225
}
220226

@@ -411,6 +417,12 @@ - (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector
411417
//deleteForward
412418
} else if (commandSelector == @selector(deleteForward:)) {
413419
commandHandled = textInputDelegate != nil && ![textInputDelegate textInputShouldHandleDeleteForward:_backedTextInputView];
420+
//escape
421+
} else if (commandSelector == @selector(cancelOperation:)) {
422+
[textInputDelegate textInputDidCancel];
423+
[_backedTextInputView.window makeFirstResponder:nil];
424+
commandHandled = YES;
425+
414426
}
415427

416428
return commandHandled;

Libraries/Text/TextInput/RCTBaseTextInputView.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,15 @@ - (BOOL)textInputShouldHandleDeleteBackward:(__unused id)sender {
561561
- (BOOL)textInputShouldHandleDeleteForward:(__unused id)sender {
562562
return YES;
563563
}
564+
565+
- (void)textInputDidCancel {
566+
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeKeyPress
567+
reactTag:self.reactTag
568+
text:nil
569+
key:@"Escape"
570+
eventCount:_nativeEventCount];
571+
[self textInputDidEndEditing];
572+
}
564573
#endif // ]TODO(macOS GH#774)
565574

566575
- (void)updateLocalData

packages/rn-tester/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,19 +504,19 @@ EXTERNAL SOURCES:
504504
:path: "../../ReactCommon/yoga"
505505

506506
SPEC CHECKSUMS:
507-
boost-for-react-native: d5ad1140010aa8cb622323a781ecbeab4425d19a
507+
boost-for-react-native: 8f7c9ecfe357664c072ffbe2432569667cbf1f1b
508508
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
509-
DoubleConversion: 0ea4559a49682230337df966e735d6cc7760108e
509+
DoubleConversion: ed15e075aa758ac0e4c1f8b830bd4e4d40d669e8
510510
FBLazyVector: 858890de7b2b63c0ae2f3fc7fb1d182fcbad393a
511-
FBReactNativeSpec: 980a51c97a0adb58c5fced2211956e8c9634b180
511+
FBReactNativeSpec: c37c6facc6640925fa3bb36857570afda0cf3b2e
512512
Flipper: d3da1aa199aad94455ae725e9f3aa43f3ec17021
513513
Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41
514514
Flipper-Folly: 755929a4f851b2fb2c347d533a23f191b008554c
515515
Flipper-Glog: 1dfd6abf1e922806c52ceb8701a3599a79a200a6
516516
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
517517
Flipper-RSocket: 127954abe8b162fcaf68d2134d34dc2bd7076154
518518
FlipperKit: 8a20b5c5fcf9436cac58551dc049867247f64b00
519-
glog: 0dc7efada961c0793012970b60faebbd58b0decb
519+
glog: 42c4bf47024808486e90b25ea9e5ac3959047641
520520
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
521521
OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b
522522
RCT-Folly: b3998425a8ee9f695f57a204dc494534246f0fe9

0 commit comments

Comments
 (0)