diff --git a/Sources/OpenSwiftUICore/Layout/SafeAreaIgnoringLayout.swift b/Sources/OpenSwiftUICore/Layout/SafeAreaIgnoringLayout.swift index 92affacc3..2a53445ff 100644 --- a/Sources/OpenSwiftUICore/Layout/SafeAreaIgnoringLayout.swift +++ b/Sources/OpenSwiftUICore/Layout/SafeAreaIgnoringLayout.swift @@ -25,7 +25,7 @@ public struct _SafeAreaIgnoringLayout: UnaryLayout { in context: _PositionAwarePlacementContext ) -> _Placement { let insets = context.safeAreaInsets().in(edges) - let size = context.proposedSize.inset(by: insets) + let size = context.proposedSize.inset(by: -insets) return _Placement( proposedSize: size, anchoring: .topLeading, diff --git a/Tests/OpenSwiftUICoreTests/Layout/SafeAreaIgnoringLayoutTests.swift b/Tests/OpenSwiftUICoreTests/Layout/SafeAreaIgnoringLayoutTests.swift new file mode 100644 index 000000000..bc39cf6a5 --- /dev/null +++ b/Tests/OpenSwiftUICoreTests/Layout/SafeAreaIgnoringLayoutTests.swift @@ -0,0 +1,60 @@ +// +// SafeAreaIgnoringLayoutTests.swift +// OpenSwiftUICoreTests + +import Foundation +import OpenAttributeGraphShims +@_spi(ForOpenSwiftUIOnly) @testable import OpenSwiftUICore +import OpenSwiftUITestsSupport +import Testing + +@MainActor +@Suite(.tags(.aigc), .disabled(if: attributeGraphVendor == .oag)) +struct SafeAreaIgnoringLayoutTests { + @Test(arguments: [ + (.all, CGSize(width: 160, height: 240), CGPoint(x: -20, y: -10)), + (.bottom, CGSize(width: 100, height: 230), CGPoint.zero), + (.horizontal, CGSize(width: 160, height: 200), CGPoint(x: -20, y: 0)), + (Edge.Set(), CGSize(width: 100, height: 200), CGPoint.zero), + ] as [(Edge.Set, CGSize, CGPoint)]) + func placementExpandsSelectedEdges( + edges: Edge.Set, + expectedSize: CGSize, + expectedOrigin: CGPoint + ) { + Update.perform { + let graph = ViewGraph(rootViewType: EmptyView.self) + defer { graph.invalidate() } + graph.rootSubgraph.apply { + let space = CoordinateSpace.ID() + var transform = ViewTransform() + transform.appendSizedSpace(id: space, size: CGSize(width: 160, height: 240)) + transform.appendTranslation(CGSize(width: -20, height: -10)) + let insets = SafeAreaInsets( + space: space, + elements: [.init( + regions: .container, + insets: .init(top: 10, leading: 20, bottom: 30, trailing: 40) + )] + ) + let ruleContext = AnyRuleContext(attribute: graph.rootView) + let context = _PositionAwarePlacementContext( + context: ruleContext, + size: .init(value: .fixed(CGSize(width: 100, height: 200))), + environment: .init(value: graph.environment), + transform: .init(value: transform), + position: .init(value: graph.zeroPoint), + safeAreaInsets: .init(Attribute(value: insets)) + ) + let placement = _SafeAreaIgnoringLayout(edges: edges).placement( + of: LayoutProxy(context: ruleContext, attributes: .init()), + in: context + ) + + #expect(placement.proposedSize == expectedSize) + #expect(placement.anchor == .topLeading) + #expect(placement.anchorPosition == expectedOrigin) + } + } + } +}