Skip to content

Commit 4951973

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 757b951 commit 4951973

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
@@ -572,22 +572,32 @@ - (void)submitOnKeyDownIfNeeded:(nonnull NSEvent *)event {}
572572
- (void)textInputDidCancel {}
573573

574574
- (NSDragOperation)textInputDraggingEntered:(nonnull id<NSDraggingInfo>)draggingInfo {
575+
if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
576+
return [self draggingEntered:draggingInfo];
577+
}
575578
return NSDragOperationNone;
576579
}
577580

578581
- (void)textInputDraggingExited:(nonnull id<NSDraggingInfo>)draggingInfo {
579-
return;
582+
if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
583+
[self draggingExited:draggingInfo];
584+
}
580585
}
581586

582-
- (BOOL)textInputShouldHandleDeleteBackward:(nonnull id<RCTBackedTextInputViewProtocol>)sender {
587+
- (BOOL)textInputShouldHandleDragOperation:(nonnull id<NSDraggingInfo>)draggingInfo {
588+
if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
589+
[self performDragOperation:draggingInfo];
590+
return NO;
591+
}
592+
583593
return YES;
584594
}
585595

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

590-
- (BOOL)textInputShouldHandleDragOperation:(nonnull id<NSDraggingInfo>)draggingInfo {
600+
- (BOOL)textInputShouldHandleDeleteForward:(nonnull id<RCTBackedTextInputViewProtocol>)sender {
591601
return YES;
592602
}
593603

0 commit comments

Comments
 (0)