Skip to content

Commit 2b2f679

Browse files
authored
feat(fabric): Implement keyboard events and drag/drop APIs for TextInput (#2719)
1 parent aef0241 commit 2b2f679

File tree

3 files changed

+223
-138
lines changed

3 files changed

+223
-138
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,36 +563,42 @@ - (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 {}
573569

574570
- (NSDragOperation)textInputDraggingEntered:(nonnull id<NSDraggingInfo>)draggingInfo {
571+
if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
572+
return [self draggingEntered:draggingInfo];
573+
}
575574
return NSDragOperationNone;
576575
}
577576

578577
- (void)textInputDraggingExited:(nonnull id<NSDraggingInfo>)draggingInfo {
579-
return;
578+
if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
579+
[self draggingExited:draggingInfo];
580+
}
580581
}
581582

582-
- (BOOL)textInputShouldHandleDeleteBackward:(nonnull id<RCTBackedTextInputViewProtocol>)sender {
583+
- (BOOL)textInputShouldHandleDragOperation:(nonnull id<NSDraggingInfo>)draggingInfo {
584+
if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
585+
[self performDragOperation:draggingInfo];
586+
return NO;
587+
}
588+
583589
return YES;
584590
}
585591

586-
- (BOOL)textInputShouldHandleDeleteForward:(nonnull id<RCTBackedTextInputViewProtocol>)sender {
592+
- (BOOL)textInputShouldHandleDeleteBackward:(nonnull id<RCTBackedTextInputViewProtocol>)sender {
587593
return YES;
588594
}
589595

590-
- (BOOL)textInputShouldHandleDragOperation:(nonnull id<NSDraggingInfo>)draggingInfo {
596+
- (BOOL)textInputShouldHandleDeleteForward:(nonnull id<RCTBackedTextInputViewProtocol>)sender {
591597
return YES;
592598
}
593599

594600
- (BOOL)textInputShouldHandleKeyEvent:(nonnull NSEvent *)event {
595-
return YES;
601+
return ![self handleKeyboardEvent:event];
596602
}
597603

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

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#import <react/renderer/core/LayoutMetrics.h>
1818
#import <react/renderer/core/Props.h>
1919

20+
#if TARGET_OS_OSX // [macOS
21+
#include <react/renderer/components/view/MouseEvent.h>
22+
#endif // macOS]
23+
2024
NS_ASSUME_NONNULL_BEGIN
2125

2226
/**
@@ -79,6 +83,11 @@ NS_ASSUME_NONNULL_BEGIN
7983
- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask NS_REQUIRES_SUPER;
8084
- (void)prepareForRecycle NS_REQUIRES_SUPER;
8185

86+
#if TARGET_OS_OSX // [macOS
87+
- (BOOL)handleKeyboardEvent:(NSEvent *)event;
88+
- (void)buildDataTransferItems:(std::vector<facebook::react::DataTransferItem> &)dataTransferItems forPasteboard:(NSPasteboard *)pasteboard;
89+
#endif // macOS]
90+
8291
/*
8392
* This is a fragment of temporary workaround that we need only temporary and will get rid of soon.
8493
*/

0 commit comments

Comments
 (0)