Skip to content

Commit e9cf4ed

Browse files
committed
Add Form and Section
1 parent 8112d09 commit e9cf4ed

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

  • AndroidSwiftUICore/Sources/AndroidSwiftUICore/Primitives
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// Form.swift
3+
// AndroidSwiftUICore
4+
//
5+
// A Form is a grouped, scrolling container of Sections; a Section groups rows
6+
// under an optional header and footer. The interpreter renders sections as
7+
// inset, rounded groups with dividers between rows.
8+
//
9+
10+
public struct Form<Content: View>: View {
11+
internal let content: Content
12+
public init(@ViewBuilder content: () -> Content) { self.content = content() }
13+
public typealias Body = Never
14+
}
15+
16+
extension Form: PrimitiveView {
17+
public func _render(in context: ResolveContext) -> RenderNode {
18+
RenderNode(
19+
type: "Form",
20+
id: context.path,
21+
children: Evaluator.resolveChildren(content, context.descending("content"))
22+
)
23+
}
24+
}
25+
26+
public struct Section<Content: View>: View {
27+
28+
internal let header: String?
29+
internal let footer: String?
30+
internal let content: Content
31+
32+
public init(@ViewBuilder content: () -> Content) {
33+
self.header = nil
34+
self.footer = nil
35+
self.content = content()
36+
}
37+
38+
public init<S: StringProtocol>(_ header: S, @ViewBuilder content: () -> Content) {
39+
self.header = String(header)
40+
self.footer = nil
41+
self.content = content()
42+
}
43+
44+
public init<H: StringProtocol, F: StringProtocol>(header: H, footer: F, @ViewBuilder content: () -> Content) {
45+
self.header = String(header)
46+
self.footer = String(footer)
47+
self.content = content()
48+
}
49+
50+
public typealias Body = Never
51+
}
52+
53+
extension Section: PrimitiveView {
54+
public func _render(in context: ResolveContext) -> RenderNode {
55+
var props: [String: PropValue] = [:]
56+
if let header { props["header"] = .string(header) }
57+
if let footer { props["footer"] = .string(footer) }
58+
return RenderNode(
59+
type: "Section",
60+
id: context.path,
61+
props: props,
62+
children: Evaluator.resolveChildren(content, context.descending("content"))
63+
)
64+
}
65+
}

0 commit comments

Comments
 (0)