Skip to content

Commit 1da8dc5

Browse files
committed
Move diffs to HostPlatformTouch
1 parent 337dff4 commit 1da8dc5

File tree

5 files changed

+79
-42
lines changed

5 files changed

+79
-42
lines changed

packages/react-native/Libraries/Types/CoreEventTypes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ export type NativeTouchEvent = $ReadOnly<{
242242
* The Y position of the touch, relative to the element
243243
*/
244244
locationY: number,
245-
246245
/**
247246
* The X position of the touch, relative to the screen
248247
*/

packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ void setTouchPayloadOnObject(
2323
object.setProperty(runtime, "target", touch.target);
2424
object.setProperty(runtime, "timestamp", touch.timestamp * 1000);
2525
object.setProperty(runtime, "force", touch.force);
26-
#if TARGET_OS_OSX // [macOS
27-
object.setProperty(runtime, "button", touch.button);
28-
object.setProperty(runtime, "altKey", touch.altKey);
29-
object.setProperty(runtime, "ctrlKey", touch.ctrlKey);
30-
object.setProperty(runtime, "shiftKey", touch.shiftKey);
31-
object.setProperty(runtime, "metaKey", touch.metaKey);
32-
#endif // macOS]
3326
}
3427

3528
#if RN_DEBUG_STRING_CONVERTIBLE
@@ -49,13 +42,6 @@ std::vector<DebugStringConvertibleObject> getDebugProps(
4942
{"target", getDebugDescription(touch.target, options)},
5043
{"force", getDebugDescription(touch.force, options)},
5144
{"timestamp", getDebugDescription(touch.timestamp, options)},
52-
#if TARGET_OS_SX // [macOS
53-
{"button", getDebugDescription(touch.button, options)},
54-
{"altKey", getDebugDescription(touch.altKey, options)},
55-
{"ctrlKey", getDebugDescription(touch.ctrlKey, options)},
56-
{"shiftKey", getDebugDescription(touch.shiftKey, options)},
57-
{"metaKey", getDebugDescription(touch.metaKey, options)},
58-
#endif // macOS]
5945
};
6046
}
6147

packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,6 @@ struct BaseTouch {
5555
* The time in seconds when the touch occurred or when it was last mutated.
5656
*/
5757
Float timestamp;
58-
#if TARGET_OS_OSX // [macOS
59-
/*
60-
* The button indicating which pointer is used.
61-
*/
62-
int button;
63-
64-
/*
65-
* A flag indicating if the alt key is pressed.
66-
*/
67-
bool altKey;
68-
69-
/*
70-
* A flag indicating if the control key is pressed.
71-
*/
72-
bool ctrlKey;
73-
74-
/*
75-
* A flag indicating if the shift key is pressed.
76-
*/
77-
bool shiftKey;
78-
79-
/*
80-
* A flag indicating if the meta key is pressed.
81-
*/
82-
bool metaKey;
83-
#endif // macOS]
8458

8559
/*
8660
* The particular implementation of `Hasher` and (especially) `Comparator`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
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+
#include "HostPlatformTouch.h"
9+
#include "Touch.h"
10+
11+
namespace facebook::react {
12+
13+
void setTouchPayloadOnObject(
14+
jsi::Object& object,
15+
jsi::Runtime& runtime,
16+
const HostPlatformTouch& touch) {
17+
setTouchPayloadOnObject(object, runtime, static_cast<const BaseTouch&>(touch));
18+
#if TARGET_OS_OSX // [macOS
19+
object.setProperty(runtime, "button", touch.button);
20+
object.setProperty(runtime, "altKey", touch.altKey);
21+
object.setProperty(runtime, "ctrlKey", touch.ctrlKey);
22+
object.setProperty(runtime, "shiftKey", touch.shiftKey);
23+
object.setProperty(runtime, "metaKey", touch.metaKey);
24+
#endif // macOS]
25+
}
26+
27+
#if RN_DEBUG_STRING_CONVERTIBLE
28+
29+
std::string getDebugName(const HostPlatformTouch& /*touch*/) {
30+
return "Touch";
31+
}
32+
33+
std::vector<DebugStringConvertibleObject> getDebugProps(
34+
const HostPlatformTouch& touch,
35+
DebugStringConvertibleOptions options) {
36+
auto debugProps = getDebugProps(static_cast<const BaseTouch&>(touch), options);
37+
debugProps.insert(
38+
debugProps.end(),
39+
{
40+
{"button", getDebugDescription(touch.button, options)},
41+
{"altKey", getDebugDescription(touch.altKey, options)},
42+
{"ctrlKey", getDebugDescription(touch.ctrlKey, options)},
43+
{"shiftKey", getDebugDescription(touch.shiftKey, options)},
44+
{"metaKey", getDebugDescription(touch.metaKey, options)},
45+
});
46+
return debugProps;
47+
};
48+
49+
#endif
50+
51+
} // namespace facebook::react

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,32 @@
1212
#include <react/renderer/components/view/BaseTouch.h>
1313

1414
namespace facebook::react {
15-
using HostPlatformTouch = BaseTouch;
15+
16+
struct HostPlatformTouch : public BaseTouch {
17+
/*
18+
* The button indicating which pointer is used.
19+
*/
20+
int button;
21+
22+
/*
23+
* A flag indicating if the alt key is pressed.
24+
*/
25+
bool altKey;
26+
27+
/*
28+
* A flag indicating if the control key is pressed.
29+
*/
30+
bool ctrlKey;
31+
32+
/*
33+
* A flag indicating if the shift key is pressed.
34+
*/
35+
bool shiftKey;
36+
37+
/*
38+
* A flag indicating if the meta key is pressed.
39+
*/
40+
bool metaKey;
41+
};
42+
1643
} // namespace facebook::react

0 commit comments

Comments
 (0)