Skip to content

Commit 9554e17

Browse files
committed
UIKit demo
We can revert this or start maintaining these...
1 parent bf88588 commit 9554e17

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

Examples/CaseStudies/SwiftUICaseStudies/00-RootView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ struct RootView: View {
4040
AlertAndConfirmationDialog()
4141
}
4242
) { store in
43-
AlertAndConfirmationDialogView(store: store)
43+
UIViewControllerRepresenting {
44+
AlertAndConfirmationDialogViewController(store: store)
45+
}
4446
}
4547
}
4648
NavigationLink("Focus State") {

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-AlertsAndConfirmationDialogs.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,67 @@ struct AlertAndConfirmationDialog {
101101
}
102102
}
103103

104+
import UIKit
105+
final class AlertAndConfirmationDialogViewController: UIViewController {
106+
@UIBindable var store: StoreOf<AlertAndConfirmationDialog>
107+
108+
init(store: StoreOf<AlertAndConfirmationDialog>) {
109+
self.store = store
110+
super.init(nibName: nil, bundle: nil)
111+
}
112+
113+
required init?(coder: NSCoder) {
114+
fatalError("init(coder:) has not been implemented")
115+
}
116+
117+
override func viewDidLoad() {
118+
super.viewDidLoad()
119+
120+
let countLabel = UILabel()
121+
122+
let alertButton = UIButton(type: .system, primaryAction: UIAction { [weak self] _ in
123+
self?.store.send(.alertButtonTapped)
124+
})
125+
alertButton.setTitle("Alert", for: .normal)
126+
127+
let confirmationDialogButton = UIButton(type: .system, primaryAction: UIAction { [weak self] _ in
128+
self?.store.send(.confirmationDialogButtonTapped)
129+
})
130+
confirmationDialogButton.setTitle("Confirmation Dialog", for: .normal)
131+
132+
let stack = UIStackView(arrangedSubviews: [
133+
countLabel,
134+
alertButton,
135+
confirmationDialogButton,
136+
])
137+
stack.axis = .vertical
138+
stack.translatesAutoresizingMaskIntoConstraints = false
139+
140+
view.addSubview(stack)
141+
142+
NSLayoutConstraint.activate([
143+
stack.topAnchor.constraint(equalTo: view.topAnchor),
144+
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
145+
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
146+
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
147+
])
148+
149+
observe { [weak self] in
150+
guard let self else { return }
151+
countLabel.text = "Count: \(store.count)"
152+
}
153+
154+
present(item: $store.scope(state: \.alert, action: \.alert)) { store in
155+
UIAlertController(store: store)
156+
}
157+
present(
158+
item: $store.scope(state: \.confirmationDialog, action: \.confirmationDialog)
159+
) { store in
160+
UIAlertController(store: store)
161+
}
162+
}
163+
}
164+
104165
struct AlertAndConfirmationDialogView: View {
105166
@Bindable var store: StoreOf<AlertAndConfirmationDialog>
106167

0 commit comments

Comments
 (0)