-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContextMenuPlaygrounds.swift
More file actions
47 lines (44 loc) · 1.73 KB
/
Copy pathContextMenuPlaygrounds.swift
File metadata and controls
47 lines (44 loc) · 1.73 KB
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
#if canImport(AndroidSwiftUI)
import AndroidSwiftUI
#else
import SwiftUI
#endif
struct ContextMenuPlayground: View {
@State private var status = "Long-press a row"
@State private var pinned = false
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 0) {
Example("Long-press for a menu") {
VStack(alignment: .leading, spacing: 12) {
Text("Project Alpha")
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(8)
.contextMenu {
Button("Rename") { status = "Renamed Alpha" }
Button("Duplicate") { status = "Duplicated Alpha" }
Button("Delete") { status = "Deleted Alpha" }
}
Text(status)
}
}
Example("Menu that reads state") {
VStack(alignment: .leading, spacing: 12) {
Text(pinned ? "📌 Pinned note" : "Note")
.foregroundColor(.white)
.padding()
.background(Color.purple)
.cornerRadius(8)
.contextMenu {
Button(pinned ? "Unpin" : "Pin") { pinned.toggle() }
Button("Share") { status = "Shared note" }
}
}
}
}
}
.navigationTitle("Context Menu")
}
}