Skip to content

Commit 37cf136

Browse files
committed
Implement ZStack alignment
1 parent 9faf0fe commit 37cf136

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Sources/SwiftCrossUI/Views/ZStack.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
public struct ZStack<Content: View>: View {
2+
public var alignment: Alignment
23
public var body: Content
34

4-
public init(@ViewBuilder content: () -> Content) {
5-
self.init(content: content())
5+
public init(
6+
alignment: Alignment = .center,
7+
@ViewBuilder content: () -> Content
8+
) {
9+
self.init(
10+
alignment: alignment,
11+
content: content()
12+
)
613
}
714

8-
init(content: Content) {
15+
init(alignment: Alignment, content: Content) {
16+
self.alignment = alignment
917
body = content
1018
}
1119

@@ -56,7 +64,10 @@ public struct ZStack<Content: View>: View {
5664

5765
if !dryRun {
5866
for (i, childSize) in childSizes.enumerated() {
59-
let position = (size.size &- childSize.size) / 2
67+
let position = alignment.position(
68+
ofChild: childSize.size,
69+
in: size.size
70+
)
6071
backend.setPosition(ofChildAt: i, in: widget, to: position)
6172
}
6273
backend.setSize(of: widget, to: size.size)

0 commit comments

Comments
 (0)