From 755d05700903ed5e370d7896cd13b64066836721 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 18 Oct 2025 16:07:16 +0800 Subject: [PATCH 1/2] Update ZIndex implementation --- Sources/OpenSwiftUICore/Layout/Stack/ZIndex.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 From 5ce4276a933b80d31cd86253c29a5510f8c6e2de Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 18 Oct 2025 18:08:18 +0800 Subject: [PATCH 2/2] Update ZIndex test case --- .../Layout/Stack/ZStackIndexUITests.swift | 40 +++++++++++++++++++ .../Layout/ZIndexTests.swift | 14 +++---- 2 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 Example/OpenSwiftUIUITests/Layout/Stack/ZStackIndexUITests.swift 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/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)) } }