Skip to content

Commit 9c6efe8

Browse files
authored
feat(fabric): Add some missing macOS only props (#2730)
## Summary: Add the remaining view props we have on Paper that are missing on Fabric. I determined this by looking at BaseViewConfig.macos.js ## Test Plan: CI should pass
1 parent 98eb33d commit 9c6efe8

File tree

4 files changed

+70
-5
lines changed

4 files changed

+70
-5
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ @implementation RCTViewComponentView {
5757
BOOL _hasMouseOver;
5858
BOOL _hasClipViewBoundsObserver;
5959
NSTrackingArea *_trackingArea;
60+
BOOL _allowsVibrancy;
6061
#endif // macOS]
6162
NSMutableArray<RCTUIView *> *_reactSubviews; // [macOS]
6263
NSSet<NSString *> *_Nullable _propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN;
@@ -81,6 +82,10 @@ - (instancetype)initWithFrame:(CGRect)frame
8182
#endif // [macOS]
8283
_useCustomContainerView = NO;
8384
_removeClippedSubviews = NO;
85+
#if TARGET_OS_OSX // [macOS
86+
_allowsVibrancy = NO;
87+
self.mouseDownCanMoveWindow = YES;
88+
#endif // macOS]
8489
}
8590
return self;
8691
}
@@ -141,6 +146,11 @@ - (void)resetCursorRects
141146
[self addCursorRect:self.bounds cursor:cursor];
142147
}
143148
}
149+
150+
- (BOOL)allowsVibrancy
151+
{
152+
return _allowsVibrancy;
153+
}
144154
#endif // macOS]
145155

146156
#if !TARGET_OS_OSX
@@ -593,6 +603,21 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
593603
}
594604

595605
#if TARGET_OS_OSX // [macOS
606+
// `acceptsFirstMouse`
607+
if (oldViewProps.acceptsFirstMouse != newViewProps.acceptsFirstMouse) {
608+
self.acceptsFirstMouse = newViewProps.acceptsFirstMouse;
609+
}
610+
611+
// `mouseDownCanMoveWindow`
612+
if (oldViewProps.mouseDownCanMoveWindow != newViewProps.mouseDownCanMoveWindow) {
613+
self.mouseDownCanMoveWindow = newViewProps.mouseDownCanMoveWindow;
614+
}
615+
616+
// `allowsVibrancy`
617+
if (oldViewProps.allowsVibrancy != newViewProps.allowsVibrancy) {
618+
_allowsVibrancy = newViewProps.allowsVibrancy;
619+
}
620+
596621
// `draggedTypes`
597622
if (oldViewProps.draggedTypes != newViewProps.draggedTypes) {
598623
if (!oldViewProps.draggedTypes.empty()) {
@@ -712,6 +737,11 @@ - (void)prepareForRecycle
712737
_isJSResponder = NO;
713738
_removeClippedSubviews = NO;
714739
_reactSubviews = [NSMutableArray new];
740+
#if TARGET_OS_OSX // [macOS
741+
_allowsVibrancy = NO;
742+
self.acceptsFirstMouse = NO;
743+
self.mouseDownCanMoveWindow = YES;
744+
#endif // macOS]
715745
}
716746

717747
- (void)setPropKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN:(NSSet<NSString *> *_Nullable)props

packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformViewProps.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,34 @@ HostPlatformViewProps::HostPlatformViewProps(
8383
rawProps,
8484
"tooltip",
8585
sourceProps.tooltip,
86-
{})) {}
86+
{})),
87+
acceptsFirstMouse(
88+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
89+
? sourceProps.acceptsFirstMouse
90+
: convertRawProp(
91+
context,
92+
rawProps,
93+
"acceptsFirstMouse",
94+
sourceProps.acceptsFirstMouse,
95+
{})),
96+
allowsVibrancy(
97+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
98+
? sourceProps.allowsVibrancy
99+
: convertRawProp(
100+
context,
101+
rawProps,
102+
"allowsVibrancy",
103+
sourceProps.allowsVibrancy,
104+
{})),
105+
mouseDownCanMoveWindow(
106+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
107+
? sourceProps.mouseDownCanMoveWindow
108+
: convertRawProp(
109+
context,
110+
rawProps,
111+
"mouseDownCanMoveWindow",
112+
sourceProps.mouseDownCanMoveWindow,
113+
{})) {}
87114

88115
#define VIEW_EVENT_CASE_MACOS(eventType) \
89116
case CONSTEXPR_RAW_PROPS_KEY_HASH("on" #eventType): { \
@@ -122,6 +149,9 @@ void HostPlatformViewProps::setProp(
122149
RAW_SET_PROP_SWITCH_CASE_BASIC(keyUpEvents);
123150
RAW_SET_PROP_SWITCH_CASE_BASIC(draggedTypes);
124151
RAW_SET_PROP_SWITCH_CASE_BASIC(tooltip);
152+
RAW_SET_PROP_SWITCH_CASE_BASIC(acceptsFirstMouse);
153+
RAW_SET_PROP_SWITCH_CASE_BASIC(allowsVibrancy);
154+
RAW_SET_PROP_SWITCH_CASE_BASIC(mouseDownCanMoveWindow);
125155
}
126156
}
127157

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,9 @@ class HostPlatformViewProps : public BaseViewProps {
5050
std::vector<std::string> draggedTypes{};
5151

5252
std::optional<std::string> tooltip{};
53+
54+
bool acceptsFirstMouse{false};
55+
bool allowsVibrancy{false};
56+
bool mouseDownCanMoveWindow{true};
5357
};
5458
} // namespace facebook::react

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
namespace facebook::react::HostPlatformViewTraitsInitializer {
1414

1515
inline bool formsStackingContext(const ViewProps& props) {
16-
return false;
16+
return props.allowsVibrancy ||
17+
props.mouseDownCanMoveWindow ||
18+
props.acceptsFirstMouse ||
19+
props.hostPlatformEvents.bits.any();
1720
}
1821

1922
inline bool formsView(const ViewProps& props) {
20-
return props.focusable ||
21-
props.hostPlatformEvents[HostPlatformViewEvents::Offset::MouseEnter] ||
22-
props.hostPlatformEvents[HostPlatformViewEvents::Offset::MouseLeave];
23+
return props.focusable;
2324
}
2425

2526
} // namespace facebook::react::HostPlatformViewTraitsInitializer

0 commit comments

Comments
 (0)