Skip to content

Commit e960a14

Browse files
committed
Add overlay modifier
1 parent 4884b6d commit e960a14

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

  • AndroidSwiftUICore/Sources/AndroidSwiftUICore/Primitives
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Overlay.swift
3+
// AndroidSwiftUICore
4+
//
5+
// `.overlay { … }` layers content over a view, sized to the base. Emitted as an
6+
// Overlay node whose first child is the base and second is the overlay; the
7+
// interpreter stacks the overlay at the base's size with the given alignment.
8+
//
9+
10+
public struct _OverlayView<Base: View, Overlay: View>: View {
11+
internal let base: Base
12+
internal let overlay: Overlay
13+
internal let alignment: Alignment
14+
public typealias Body = Never
15+
}
16+
17+
extension _OverlayView: PrimitiveView {
18+
public func _render(in context: ResolveContext) -> RenderNode {
19+
RenderNode(
20+
type: "Overlay",
21+
id: context.path,
22+
props: [
23+
"horizontal": .string(alignment.horizontal.rawValue),
24+
"vertical": .string(alignment.vertical.rawValue),
25+
],
26+
children: [
27+
Evaluator.resolve(base, context.descending("base")),
28+
Evaluator.resolve(overlay, context.descending("overlay")),
29+
]
30+
)
31+
}
32+
}
33+
34+
public extension View {
35+
func overlay<V: View>(
36+
alignment: Alignment = .center,
37+
@ViewBuilder content: () -> V
38+
) -> _OverlayView<Self, V> {
39+
_OverlayView(base: self, overlay: content(), alignment: alignment)
40+
}
41+
}

0 commit comments

Comments
 (0)