diff --git a/Example/OpenSwiftUIUITests/Layout/Stack/ZStackIndexUITests.swift b/Example/OpenSwiftUIUITests/Layout/Stack/ZStackIndexUITests.swift new file mode 100644 index 000000000..dcad0457d --- /dev/null +++ b/Example/OpenSwiftUIUITests/Layout/Stack/ZStackIndexUITests.swift @@ -0,0 +1,40 @@ +// +// ZIndexCompatibilityTests.swift +// OpenSwiftUICompatibilityTests + +import Foundation +import Testing +import SnapshotTesting + +@MainActor +@Suite(.snapshots(record: .never, diffTool: diffTool)) +struct ZStackIndexUITests { + @Test + func zIndexExample() { + struct ContentView: View { + var body: some View { + VStack { + // TODO: Path & Shape is not implemented yet. + Color.yellow +// Rectangle() +// .fill(Color.yellow) + .frame(width: 100, height: 100, alignment: .center) + .zIndex(1) // Top layer. + Color.red +// Rectangle() +// .fill(Color.red) + .frame(width: 100, height: 100, alignment: .center) + .rotationEffect(.degrees(45)) + // Here a zIndex of 0 is the default making + // this the bottom layer. + } + } + } + withKnownIssue { + openSwiftUIAssertSnapshot( + of: ContentView(), + size: CGSize(width: 200, height: 200) + ) + } + } +} diff --git a/Sources/OpenSwiftUICore/Layout/Stack/ZIndex.swift b/Sources/OpenSwiftUICore/Layout/Stack/ZIndex.swift index fa6c93623..56d79f9b9 100644 --- a/Sources/OpenSwiftUICore/Layout/Stack/ZIndex.swift +++ b/Sources/OpenSwiftUICore/Layout/Stack/ZIndex.swift @@ -2,9 +2,10 @@ // ZIndex.swift // OpenSwiftUICore // -// Audited for 6.0.87 +// Audited for 6.5.4 // Status: Complete +@available(OpenSwiftUI_v1_0, *) extension View { /// Controls the display order of overlapping views. /// @@ -39,6 +40,8 @@ extension View { } } + +@available(OpenSwiftUI_v1_0, *) @usableFromInline package struct ZIndexTraitKey: _ViewTraitKey { @inlinable diff --git a/Tests/OpenSwiftUICoreTests/Layout/ZIndexTests.swift b/Tests/OpenSwiftUICoreTests/Layout/ZIndexTests.swift index 2cda207d6..8924eef12 100644 --- a/Tests/OpenSwiftUICoreTests/Layout/ZIndexTests.swift +++ b/Tests/OpenSwiftUICoreTests/Layout/ZIndexTests.swift @@ -3,19 +3,17 @@ // OpenSwiftUICoreTests import OpenAttributeGraphShims +@_spi(ForOpenSwiftUIOnly) import OpenSwiftUICore import Testing @MainActor struct ZIndexTests { @Test - func indexOrder() { - struct ContentView: View { - var body: some View { - Color.red - .zIndex(0.5) - } - } - // TODO: Add a test helper to hook into makeViewList and retrieve the zIndex value to verify it + func traitCollectionZIndex() { + var collection = ViewTraitCollection() + #expect(collection.zIndex.isApproximatelyEqual(to: 0.0)) + collection.zIndex = 1.5 + #expect(collection.zIndex.isApproximatelyEqual(to: 1.5)) } }