Skip to content

Commit f5e2be7

Browse files
Nick LefeverSaadnajmi
authored andcommitted
[fabric] Add keyboard event handling to TextInput component
Summary: This diff adds keyboard event handling to the TextInput component by testing the valid keys for manual keyboard event handling and dispatching key events to the View component keyboard handling method. Test Plan: - Run Workplace Chat with Fabric enabled. - Open a message thread with 3 or more participants. - Type `@` to display the reference selector. - Change the selection with the up and down arrows and select an entry with tab to test the custom keyboard event handling. https://pxl.cl/4ghtH Reviewers: shawndempsey, #rn-desktop Reviewed By: shawndempsey Differential Revision: https://phabricator.intern.facebook.com/D53241729 Tasks: T157889406, T154618477
1 parent 199cbdc commit f5e2be7

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,6 @@ - (void)grammarCheckingDidChange:(BOOL)enabled
563563
}
564564
}
565565

566-
- (BOOL)hasValidKeyDownOrValidKeyUp:(nonnull NSString *)key {
567-
return YES;
568-
}
569-
570566
- (void)submitOnKeyDownIfNeeded:(nonnull NSEvent *)event {}
571567

572568
- (void)textInputDidCancel {}
@@ -602,7 +598,7 @@ - (BOOL)textInputShouldHandleDeleteForward:(nonnull id<RCTBackedTextInputViewPro
602598
}
603599

604600
- (BOOL)textInputShouldHandleKeyEvent:(nonnull NSEvent *)event {
605-
return YES;
601+
return ![self handleKeyboardEvent:event];
606602
}
607603

608604
- (BOOL)textInputShouldHandlePaste:(nonnull id<RCTBackedTextInputViewProtocol>)sender {

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ NS_ASSUME_NONNULL_BEGIN
7979
- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask NS_REQUIRES_SUPER;
8080
- (void)prepareForRecycle NS_REQUIRES_SUPER;
8181

82+
#if TARGET_OS_OSX // [macOS
83+
- (BOOL)handleKeyboardEvent:(NSEvent *)event;
84+
- (void)buildDataTransferItems:(std::vector<facebook::react::DataTransferItem> &)dataTransferItems forPasteboard:(NSPasteboard *)pasteboard;
85+
#endif // macOS]
86+
8287
/*
8388
* This is a fragment of temporary workaround that we need only temporary and will get rid of soon.
8489
*/

0 commit comments

Comments
 (0)