Skip to content

Commit 7a4f466

Browse files
Nick LefeverSaadnajmi
authored andcommitted
[fabric] Add drag and drop event emitters to View
Summary: Add the drag and drop event emitters to View with the payload conversion matching the Paper API for dragEnter/dragLeave/drop events. Test Plan: Tested later in this stack. Reviewers: shawndempsey, #rn-desktop Reviewed By: shawndempsey Differential Revision: https://phabricator.intern.facebook.com/D53674738
1 parent 52f025e commit 7a4f466

File tree

3 files changed

+101
-81
lines changed

3 files changed

+101
-81
lines changed
Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
1-
/*
2-
* Copyright (c) Microsoft Corporation.
3-
*
4-
* This source code is licensed under the MIT license found in the
5-
* LICENSE file in the root directory of this source tree.
6-
*/
7-
8-
// [macOS]
9-
10-
#include <react/renderer/components/view/HostPlatformViewEventEmitter.h>
11-
#include <react/renderer/components/view/KeyEvent.h>
12-
13-
namespace facebook::react {
14-
15-
#pragma mark - Focus Events
16-
17-
void HostPlatformViewEventEmitter::onFocus() const {
18-
dispatchEvent("focus");
19-
}
20-
21-
void HostPlatformViewEventEmitter::onBlur() const {
22-
dispatchEvent("blur");
23-
}
24-
25-
#pragma mark - Keyboard Events
26-
27-
static jsi::Value keyEventPayload(jsi::Runtime& runtime, const KeyEvent& event) {
28-
auto payload = jsi::Object(runtime);
29-
payload.setProperty(runtime, "key", jsi::String::createFromUtf8(runtime, event.key));
30-
payload.setProperty(runtime, "ctrlKey", event.ctrlKey);
31-
payload.setProperty(runtime, "shiftKey", event.shiftKey);
32-
payload.setProperty(runtime, "altKey", event.altKey);
33-
payload.setProperty(runtime, "metaKey", event.metaKey);
34-
payload.setProperty(runtime, "capsLockKey", event.capsLockKey);
35-
payload.setProperty(runtime, "numericPadKey", event.numericPadKey);
36-
payload.setProperty(runtime, "helpKey", event.helpKey);
37-
payload.setProperty(runtime, "functionKey", event.functionKey);
38-
return payload;
39-
};
40-
41-
void HostPlatformViewEventEmitter::onKeyDown(const KeyEvent& keyEvent) const {
42-
dispatchEvent("keyDown", [keyEvent](jsi::Runtime& runtime) {
43-
return keyEventPayload(runtime, keyEvent);
44-
});
45-
}
46-
47-
void HostPlatformViewEventEmitter::onKeyUp(const KeyEvent& keyEvent) const {
48-
dispatchEvent("keyUp", [keyEvent](jsi::Runtime& runtime) {
49-
return keyEventPayload(runtime, keyEvent);
50-
});
51-
}
52-
53-
#pragma mark - Mouse Events
54-
55-
static jsi::Value mouseEventPayload(jsi::Runtime& runtime, const MouseEvent& event) {
56-
auto payload = jsi::Object(runtime);
57-
payload.setProperty(runtime, "clientX", event.clientX);
58-
payload.setProperty(runtime, "clientY", event.clientY);
59-
payload.setProperty(runtime, "screenX", event.screenX);
60-
payload.setProperty(runtime, "screenY", event.screenY);
61-
payload.setProperty(runtime, "altKey", event.altKey);
62-
payload.setProperty(runtime, "ctrlKey", event.ctrlKey);
63-
payload.setProperty(runtime, "shiftKey", event.shiftKey);
64-
payload.setProperty(runtime, "metaKey", event.metaKey);
65-
return payload;
66-
};
67-
68-
void HostPlatformViewEventEmitter::onMouseEnter(const MouseEvent& mouseEvent) const {
69-
dispatchEvent("mouseEnter", [mouseEvent](jsi::Runtime &runtime) {
70-
return mouseEventPayload(runtime, mouseEvent);
71-
});
72-
}
73-
74-
void HostPlatformViewEventEmitter::onMouseLeave(const MouseEvent& mouseEvent) const {
75-
dispatchEvent("mouseLeave", [mouseEvent](jsi::Runtime &runtime) {
76-
return mouseEventPayload(runtime, mouseEvent);
77-
});
78-
}
79-
80-
} // namespace facebook::react
1+
/*
2+
* Copyright (c) Microsoft Corporation.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// [macOS]
9+
10+
#include <react/renderer/components/view/HostPlatformViewEventEmitter.h>
11+
#include <react/renderer/components/view/KeyEvent.h>
12+
13+
namespace facebook::react {
14+
15+
#pragma mark - Focus Events
16+
17+
void HostPlatformViewEventEmitter::onFocus() const {
18+
dispatchEvent("focus");
19+
}
20+
21+
void HostPlatformViewEventEmitter::onBlur() const {
22+
dispatchEvent("blur");
23+
}
24+
25+
#pragma mark - Keyboard Events
26+
27+
static jsi::Value keyEventPayload(jsi::Runtime& runtime, const KeyEvent& event) {
28+
auto payload = jsi::Object(runtime);
29+
payload.setProperty(runtime, "key", jsi::String::createFromUtf8(runtime, event.key));
30+
payload.setProperty(runtime, "ctrlKey", event.ctrlKey);
31+
payload.setProperty(runtime, "shiftKey", event.shiftKey);
32+
payload.setProperty(runtime, "altKey", event.altKey);
33+
payload.setProperty(runtime, "metaKey", event.metaKey);
34+
payload.setProperty(runtime, "capsLockKey", event.capsLockKey);
35+
payload.setProperty(runtime, "numericPadKey", event.numericPadKey);
36+
payload.setProperty(runtime, "helpKey", event.helpKey);
37+
payload.setProperty(runtime, "functionKey", event.functionKey);
38+
return payload;
39+
};
40+
41+
void HostPlatformViewEventEmitter::onKeyDown(const KeyEvent& keyEvent) const {
42+
dispatchEvent("keyDown", [keyEvent](jsi::Runtime& runtime) {
43+
return keyEventPayload(runtime, keyEvent);
44+
});
45+
}
46+
47+
void HostPlatformViewEventEmitter::onKeyUp(const KeyEvent& keyEvent) const {
48+
dispatchEvent("keyUp", [keyEvent](jsi::Runtime& runtime) {
49+
return keyEventPayload(runtime, keyEvent);
50+
});
51+
}
52+
53+
#pragma mark - Mouse Events
54+
55+
static jsi::Value mouseEventPayload(jsi::Runtime& runtime, const MouseEvent& event) {
56+
auto payload = jsi::Object(runtime);
57+
payload.setProperty(runtime, "clientX", event.clientX);
58+
payload.setProperty(runtime, "clientY", event.clientY);
59+
payload.setProperty(runtime, "screenX", event.screenX);
60+
payload.setProperty(runtime, "screenY", event.screenY);
61+
payload.setProperty(runtime, "altKey", event.altKey);
62+
payload.setProperty(runtime, "ctrlKey", event.ctrlKey);
63+
payload.setProperty(runtime, "shiftKey", event.shiftKey);
64+
payload.setProperty(runtime, "metaKey", event.metaKey);
65+
return payload;
66+
};
67+
68+
void HostPlatformViewEventEmitter::onMouseEnter(const MouseEvent& mouseEvent) const {
69+
dispatchEvent("mouseEnter", [mouseEvent](jsi::Runtime &runtime) {
70+
return mouseEventPayload(runtime, mouseEvent);
71+
});
72+
}
73+
74+
void HostPlatformViewEventEmitter::onMouseLeave(const MouseEvent& mouseEvent) const {
75+
dispatchEvent("mouseLeave", [mouseEvent](jsi::Runtime &runtime) {
76+
return mouseEventPayload(runtime, mouseEvent);
77+
});
78+
}
79+
80+
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformViewEventEmitter.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class HostPlatformViewEventEmitter : public BaseViewEventEmitter {
3333

3434
void onMouseEnter(MouseEvent const& mouseEvent) const;
3535
void onMouseLeave(MouseEvent const& mouseEvent) const;
36+
37+
#pragma mark - Drag and Drop Events
38+
39+
void onDragEnter(DragEvent const& dragEvent) const;
40+
void onDragLeave(DragEvent const& dragEvent) const;
41+
void onDrop(DragEvent const& dragEvent) const;
3642
};
3743

38-
} // namespace facebook::react
44+
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/MouseEvent.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,18 @@ struct MouseEvent {
5656
bool metaKey{false};
5757
};
5858

59+
struct DataTransferItem {
60+
std::string name{};
61+
std::string kind{};
62+
std::string type{};
63+
std::string uri{};
64+
std::optional<int> size{};
65+
std::optional<int> width{};
66+
std::optional<int> height{};
67+
};
68+
69+
struct DragEvent : MouseEvent {
70+
std::vector<DataTransferItem> dataTransferItems;
71+
};
72+
5973
} // namespace facebook::react

0 commit comments

Comments
 (0)