Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[fabric] Add draggedTypes prop to View
Summary: Add support for `draggedTypes` to the View component, enabling the configuration of a native view as a drop target.

Test Plan:
* Run Zeratul with Fabric enabled
* Drag a file over the messages view and check that the cursor is changing indicating a drop target

 https://pxl.cl/4ldkW

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Subscribers: taskcreeper

Differential Revision: https://phabricator.intern.facebook.com/D53674739
  • Loading branch information
Nick Lefever authored and Saadnajmi committed Oct 1, 2025
commit 52f025e6ded2235f391bad044540d867a1eb57b7
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,30 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
needsInvalidateLayer = YES;
}

#if TARGET_OS_OSX // [macOS
// `draggedTypes`
if (oldViewProps.draggedTypes != newViewProps.draggedTypes) {
if (oldViewProps.draggedTypes.has_value()) {
[self unregisterDraggedTypes];
}

if (newViewProps.draggedTypes.has_value()) {
NSMutableArray<NSPasteboardType> *pasteboardTypes = [NSMutableArray new];
for (const auto &draggedType : *newViewProps.draggedTypes) {
if (draggedType == "fileUrl") {
[pasteboardTypes addObject:NSFilenamesPboardType];
} else if (draggedType == "image") {
[pasteboardTypes addObject:NSPasteboardTypePNG];
[pasteboardTypes addObject:NSPasteboardTypeTIFF];
} else if (draggedType == "string") {
[pasteboardTypes addObject:NSPasteboardTypeString];
}
}
[self registerForDraggedTypes:pasteboardTypes];
}
}
#endif // macOS]

_needsInvalidateLayer = _needsInvalidateLayer || needsInvalidateLayer;

_props = std::static_pointer_cast<const ViewProps>(props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ HostPlatformViewProps::HostPlatformViewProps(
rawProps,
"keyUpEvents",
sourceProps.keyUpEvents,
{})) {}
{})),
draggedTypes(
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
? sourceProps.draggedTypes
: convertRawProp(
context,
rawProps,
"draggedTypes",
sourceProps.draggedTypes,
{})) {};

#define VIEW_EVENT_CASE_MACOS(eventType) \
case CONSTEXPR_RAW_PROPS_KEY_HASH("on" #eventType): { \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ class HostPlatformViewProps : public BaseViewProps {

std::vector<HandledKey> keyDownEvents{};
std::vector<HandledKey> keyUpEvents{};

std::vector<std::string> draggedTypes{};
};
} // namespace facebook::react