Skip to content

Commit 64d756b

Browse files
Nick LefeverSaadnajmi
authored andcommitted
[fabric] Add drag and drop support to TextInput component
Summary: Add support for drag and drop to the TextInput component. This re-uses the drag and drop handlers implemented on the View component to support dropping images/files on TextInput views directly. Test Plan: * Run Zeratul with Fabric enabled * Drag and drop an image on the message composer * Send the attachment https://pxl.cl/4ldBX Reviewers: shawndempsey, #rn-desktop Reviewed By: shawndempsey Differential Revision: https://phabricator.intern.facebook.com/D53674740
1 parent 63b15c6 commit 64d756b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,22 +568,32 @@ - (void)submitOnKeyDownIfNeeded:(nonnull NSEvent *)event {}
568568
- (void)textInputDidCancel {}
569569

570570
- (NSDragOperation)textInputDraggingEntered:(nonnull id<NSDraggingInfo>)draggingInfo {
571+
if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
572+
return [self draggingEntered:draggingInfo];
573+
}
571574
return NSDragOperationNone;
572575
}
573576

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

578-
- (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+
579589
return YES;
580590
}
581591

582-
- (BOOL)textInputShouldHandleDeleteForward:(nonnull id<RCTBackedTextInputViewProtocol>)sender {
592+
- (BOOL)textInputShouldHandleDeleteBackward:(nonnull id<RCTBackedTextInputViewProtocol>)sender {
583593
return YES;
584594
}
585595

586-
- (BOOL)textInputShouldHandleDragOperation:(nonnull id<NSDraggingInfo>)draggingInfo {
596+
- (BOOL)textInputShouldHandleDeleteForward:(nonnull id<RCTBackedTextInputViewProtocol>)sender {
587597
return YES;
588598
}
589599

0 commit comments

Comments
 (0)