Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#pragma once

#include <react/renderer/components/view/ViewProps.h>
Expand All @@ -13,10 +15,12 @@
namespace facebook::react::HostPlatformViewTraitsInitializer {

inline bool formsStackingContext(const ViewProps& props) {
return props.allowsVibrancy ||
props.mouseDownCanMoveWindow ||
props.acceptsFirstMouse ||
props.hostPlatformEvents.bits.any();
// The default allows mouse-down events to pass through to superviews.
// Disabling window dragging needs a native boundary, not enabling it.
return props.allowsVibrancy || !props.mouseDownCanMoveWindow ||
props.acceptsFirstMouse || props.hostPlatformEvents.bits.any() ||
props.tooltip.has_value() || !props.draggedTypes.empty() ||
!props.keyDownEvents.empty() || !props.keyUpEvents.empty();
}
Comment on lines +18 to 24

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is very specific to the agent's context window, not to the code itself.
no-comments


inline bool formsView(const ViewProps& props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,70 @@ TEST_F(StackingContextTest, defaultPropsMakeEverythingFlattened) {
});
}

#if defined(TARGET_OS_OSX) && TARGET_OS_OSX // [macOS
TEST_F(StackingContextTest, windowDraggingBoundarySurvivesFlattening) {
mutateViewShadowNodeProps_(
Comment on lines +197 to +199

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't htink this is really the placce for platform specific tests, nor are they really necessary here.

nodeA_, [](ViewProps& props) { props.mouseDownCanMoveWindow = false; });
mutateViewShadowNodeProps_(nodeAA_, [](ViewProps& props) {
props.mouseDownCanMoveWindow = true;
props.backgroundColor = blackColor();
});

testViewTree_([](const StubViewTree& viewTree) {
EXPECT_EQ(viewTree.size(), 3);
auto& rootView = viewTree.getRootStubView();
ASSERT_EQ(rootView.children.size(), 1);
auto& boundaryView = *rootView.children.at(0);
EXPECT_EQ(boundaryView.tag, 2);
ASSERT_EQ(boundaryView.children.size(), 1);
EXPECT_EQ(boundaryView.children.at(0)->tag, 3);
});

mutateViewShadowNodeProps_(
nodeA_, [](ViewProps& props) { props.mouseDownCanMoveWindow = true; });

testViewTree_([](const StubViewTree& viewTree) {
EXPECT_EQ(viewTree.size(), 2);
auto& rootView = viewTree.getRootStubView();
ASSERT_EQ(rootView.children.size(), 1);
EXPECT_EQ(rootView.children.at(0)->tag, 3);
});
}

TEST_F(StackingContextTest, macOSNativeBehaviorPreventsFlattening) {
std::function<void(ViewProps&)> nativeProps[] = {
[](ViewProps& props) { props.tooltip = "Tooltip"; },
[](ViewProps& props) { props.draggedTypes = {"fileUrl"}; },
[](ViewProps& props) { props.keyDownEvents = {{.key = "Enter"}}; },
[](ViewProps& props) { props.keyUpEvents = {{.key = "Enter"}}; },
[](ViewProps& props) { props.allowsVibrancy = true; },
[](ViewProps& props) { props.acceptsFirstMouse = true; },
[](ViewProps& props) {
props.hostPlatformEvents[HostPlatformViewEvents::Offset::MouseEnter] =
true;
},
[](ViewProps& props) { props.focusable = true; },
};

for (size_t i = 0; i < std::size(nativeProps); i++) {
SCOPED_TRACE(i);
mutateViewShadowNodeProps_(nodeA_, nativeProps[i]);
testViewTree_([](const StubViewTree& viewTree) {
EXPECT_EQ(viewTree.size(), 2);
auto& rootView = viewTree.getRootStubView();
ASSERT_EQ(rootView.children.size(), 1);
EXPECT_EQ(rootView.children.at(0)->tag, 2);
});
}

mutateViewShadowNodeProps_(nodeA_, [](ViewProps&) {});
testViewTree_([](const StubViewTree& viewTree) {
EXPECT_EQ(viewTree.size(), 1);
EXPECT_TRUE(viewTree.getRootStubView().children.empty());
});
}
#endif // macOS]

TEST_F(StackingContextTest, mostPropsDoNotForceViewsToMaterialize) {
// ┌────────────── (Root) ──────────────┐ ┌────────── (Root) ───────────┐
// │ ┏━ A (tag: 2) ━━━━━━━━━━━━━━━━━━━┓ │ │ │
Expand Down
Loading