Skip to content
Merged
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 @@ -113,7 +113,7 @@ extension View {

@available(OpenSwiftUI_v3_0, *)
@frozen
public struct _InsetViewModifier<Content>: ViewModifier where Content: View {
public struct _InsetViewModifier<Content>: ViewModifier, MultiViewModifier, PrimitiveViewModifier where Content: View {
@usableFromInline
var content: Content

Expand All @@ -139,7 +139,7 @@ public struct _InsetViewModifier<Content>: ViewModifier where Content: View {
) -> _ViewOutputs {
var primaryInputs = inputs
var secondaryInputs = inputs
secondaryInputs.base.pushStableIndex(0)
primaryInputs.base.pushStableIndex(0)
secondaryInputs.implicitRootType = _ZStackLayout.self
secondaryInputs.base.pushStableIndex(1)

Expand Down Expand Up @@ -226,6 +226,7 @@ public struct _InsetViewModifier<Content>: ViewModifier where Content: View {
for key in inputs.preferences.keys {
key.visitKey(&visitor)
}
visitor.result.layoutComputer = layoutComputer
return visitor.result
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// InsetViewModifierTests.swift
// OpenSwiftUICoreTests

import Foundation
import OpenAttributeGraphShims
@_spi(ForOpenSwiftUIOnly) @testable import OpenSwiftUICore
import OpenSwiftUITestsSupport
import Testing

@MainActor
@Suite(.tags(.aigc), .disabled(if: attributeGraphVendor == .oag))
struct InsetViewModifierTests {
@Test
func safeAreaInsetPreservesViewListChildren() {
checkViewList(
TupleView((Color.red, Color.blue))
.safeAreaInset(edge: .top, spacing: 0) {
Color.clear.frame(height: 12)
}
)
}

@Test
func safeAreaPaddingPreservesViewListChildren() {
checkViewList(
TupleView((Color.red, Color.blue))
.safeAreaPadding(.horizontal, 20)
)
}

@Test(arguments: [VerticalEdge.top, .bottom])
func verticalSafeAreaInsetPreservesContentLayout(edge: VerticalEdge) {
checkLayout(
Color.red.frame(width: 32, height: 48)
.safeAreaInset(edge: edge, spacing: 0) {
Color.clear.frame(width: 12, height: 12)
},
expectedSize: CGSize(width: 32, height: 60)
)
}

@Test(arguments: [HorizontalEdge.leading, .trailing])
func horizontalSafeAreaInsetPreservesContentLayout(edge: HorizontalEdge) {
checkLayout(
Color.red.frame(width: 32, height: 48)
.safeAreaInset(edge: edge, spacing: 0) {
Color.clear.frame(width: 12, height: 12)
},
expectedSize: CGSize(width: 44, height: 48)
)
}

@Test(arguments: [
(Edge.top, CGSize(width: 32, height: 60)),
(.bottom, CGSize(width: 32, height: 60)),
(.leading, CGSize(width: 44, height: 48)),
(.trailing, CGSize(width: 44, height: 48)),
])
func safeAreaPaddingPreservesContentLayout(edge: Edge, expectedSize: CGSize) {
checkLayout(
Color.red.frame(width: 32, height: 48)
.safeAreaPadding(Edge.Set(edge), 12),
expectedSize: expectedSize
)
}

private func checkLayout<Content: View>(_ content: Content, expectedSize: CGSize) {
Update.perform {
let graph = ViewGraph(rootViewType: Content.self, requestedOutputs: .layout)
defer { graph.invalidate() }
graph.setRootView(content)
#expect(graph.sizeThatFits(.unspecified) == expectedSize)
}
}

private func checkViewList<Content: View>(_ content: Content) {
Update.perform {
let graph = ViewGraph(rootViewType: Content.self)
defer { graph.invalidate() }
graph.rootSubgraph.apply {
let inputs = _ViewListInputs(graph.graphInputs)
let outputs = Content._makeViewList(
view: _GraphValue(Attribute(value: content)),
inputs: inputs
)
#expect(outputs.staticCount == 2)
#expect(outputs.nextImplicitID == 2)
#expect(outputs.makeAttribute(inputs: inputs).value.count(style: .init()) == 2)
}
}
}
}
Loading