Skip to content

Commit 5f334af

Browse files
committed
Followup changes
1 parent dff7ce8 commit 5f334af

File tree

3 files changed

+97
-91
lines changed

3 files changed

+97
-91
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ @implementation RCTViewComponentView {
4949
BOOL _needsInvalidateLayer;
5050
BOOL _isJSResponder;
5151
BOOL _removeClippedSubviews;
52-
BOOL _hasMouseOver; // [macOS]
53-
BOOL _hasClipViewBoundsObserver; // [macOS]
54-
NSTrackingArea *_trackingArea; // [macOS]
52+
#if TARGET_OS_OSX // [macOS
53+
BOOL _hasMouseOver;
54+
BOOL _hasClipViewBoundsObserver;
55+
NSTrackingArea *_trackingArea;
56+
#endif // macOS]
5557
NSMutableArray<RCTUIView *> *_reactSubviews; // [macOS]
5658
NSSet<NSString *> *_Nullable _propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN;
5759
RCTPlatformView *_containerView; // [macOS]
@@ -649,8 +651,10 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
649651
_needsInvalidateLayer = NO;
650652
[self invalidateLayer];
651653

654+
#if TARGET_OS_OSX // [macOS
652655
[self updateTrackingAreas];
653656
[self updateClipViewBoundsObserverIfNeeded];
657+
#endif // macOS]
654658
}
655659

656660
- (void)prepareForRecycle
@@ -1730,8 +1734,9 @@ - (void)updateClipViewBoundsObserverIfNeeded
17301734

17311735
NSClipView *clipView = self.window ? self.enclosingScrollView.contentView : nil;
17321736

1733-
BOOL hasMouseEventHandler = _props->macOSViewEvents[facebook::react::MacOSViewEvents::Offset::MouseEnter] ||
1734-
_props->macOSViewEvents[facebook::react::MacOSViewEvents::Offset::MouseLeave];
1737+
BOOL hasMouseEventHandler =
1738+
_props->hostPlatformEvents[HostPlatformViewEvents::Offset::MouseEnter] ||
1739+
_props->hostPlatformEvents[HostPlatformViewEvents::Offset::MouseLeave];
17351740

17361741
if (_hasClipViewBoundsObserver && (!clipView || !hasMouseEventHandler)) {
17371742
_hasClipViewBoundsObserver = NO;
@@ -1760,10 +1765,11 @@ - (void)updateTrackingAreas
17601765
[self removeTrackingArea:_trackingArea];
17611766
}
17621767

1763-
if (
1764-
_props->macOSViewEvents[facebook::react::MacOSViewEvents::Offset::MouseEnter] ||
1765-
_props->macOSViewEvents[facebook::react::MacOSViewEvents::Offset::MouseLeave]
1766-
) {
1768+
BOOL hasMouseEventHandler =
1769+
_props->hostPlatformEvents[HostPlatformViewEvents::Offset::MouseEnter] ||
1770+
_props->hostPlatformEvents[HostPlatformViewEvents::Offset::MouseLeave];
1771+
1772+
if (hasMouseEventHandler) {
17671773
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
17681774
options:NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited
17691775
owner:self
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/HostPlatformViewTraitsInitializer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ inline bool formsStackingContext(const ViewProps& props) {
1818

1919
inline bool formsView(const ViewProps& props) {
2020
return props.focusable ||
21-
props.macOSViewEvents[MacOSViewEvents::Offset::MouseEnter] ||
22-
props.macOSViewEvents[MacOSViewEvents::Offset::MouseLeave];
21+
props.hostPlatformEvents[HostPlatformViewEvents::Offset::MouseEnter] ||
22+
props.hostPlatformEvents[HostPlatformViewEvents::Offset::MouseLeave];
2323
}
2424

2525
} // namespace facebook::react::HostPlatformViewTraitsInitializer

0 commit comments

Comments
 (0)