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
40 changes: 40 additions & 0 deletions Example/OpenSwiftUIUITests/Layout/Stack/ZStackIndexUITests.swift
Original file line number Diff line number Diff line change
@@ -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)
)
}
}
}
5 changes: 4 additions & 1 deletion Sources/OpenSwiftUICore/Layout/Stack/ZIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -39,6 +40,8 @@ extension View {
}

}

@available(OpenSwiftUI_v1_0, *)
@usableFromInline
package struct ZIndexTraitKey: _ViewTraitKey {
@inlinable
Expand Down
14 changes: 6 additions & 8 deletions Tests/OpenSwiftUICoreTests/Layout/ZIndexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}