|
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 |
0 commit comments