-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContentView.swift
80 lines (74 loc) · 1.86 KB
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// ContentView.swift
// Shared
//
// Created by Maxim Krouk on 15.01.22.
//
import SwiftUI
import DynamicFormsUI
struct ContentView: View {
@State
var form = DynamicForm {
DynamicStack(.vertical) {
DynamicText("Title").bold()
DynamicText("Description")
DynamicStack(.horizontal) {
DynamicText("State: ")
DynamicText("Initial")
}
DynamicStack(.horizontal) {
DynamicButton(action: "content.ok") {
DynamicText("OK")
}
DynamicButton(action: "content.cancel") {
DynamicText("Cancel")
}
}
}
}
@State
var actionMessages: [String] = []
var body: some View {
ZStack {
DynamicViews.Form($form)
VStack {
Spacer()
ScrollView(.vertical, showsIndicators: false) {
VStack {
ForEach(actionMessages, id: \.self) { message in
Text(message)
.rotationEffect(.radians(.pi))
}
}
.padding(.top)
.frame(maxWidth: .infinity)
}
.rotationEffect(.radians(.pi))
.frame(height: 100)
}
}
.onReceive(
DynamicFormClient.shared.publisher(for: "content.ok")
) {
form.node.stack?.children[2].primitive?.stack?.children[1].primitive?.text = DynamicText("ok").bold()
printMessage("OK")
}
.onReceive(
DynamicFormClient.shared.publisher(for: "content.cancel")
) {
form.node.stack?.children[2].primitive?.stack?.children[1].primitive?.text = DynamicText("cancel").bold()
printMessage("CANCEL")
}
}
func printMessage(_ text: String) {
actionMessages.insert(text, at: 0)
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
_ = actionMessages.popLast()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}