-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtonItemSheet_Example.swift
61 lines (42 loc) · 1.15 KB
/
ButtonItemSheet_Example.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
//
// ButtonItemSheet_Example.swift
// Preview-Target
//
// Created by Shunzhe Ma on R 2/10/14.
//
import SwiftUI
struct Cat: Identifiable, Hashable {
var id = UUID().uuidString
var catName: String
}
struct ButtonItemSheet_Example: View {
let myCats = [Cat(catName: "ネコノヒー"), Cat(catName: "ムギ"), Cat(catName: "レオ")]
@State var catItemToShow: Cat? = nil
var body: some View {
List(self.myCats) { item in
Button(action: {
self.catItemToShow = item
}) {
Text(item.catName)
}
}
.sheet(item: $catItemToShow) { item in
AnotherView(textContent: item.catName)
}
}
}
fileprivate struct AnotherView: View {
var textContent: String
var body: some View {
VStack {
Text(textContent)
.padding()
Spacer()
}
}
}
struct ButtonItemSheet_Example_Previews: PreviewProvider {
static var previews: some View {
ButtonItemSheet_Example()
}
}