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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import SwiftUI
extension View {
/// Long-press context menu for profile avatars/rows.
/// Omit `onViewProfile` when already on the profile page.
/// Pass `hasStory: true` and a non-nil `onViewStory` to include "View story".
func profileContextMenu(
handle: String?,
hasStory: Bool,
onViewProfile: (() -> Void)? = nil,
onViewStory: (() -> Void)? = nil,
onAddStory: (() -> Void)? = nil,
onViewPhoto: (() -> Void)? = nil,
showSharingActions: Bool = true
) -> some View {
contextMenu {
profileMenuItems(
handle: handle,
hasStory: hasStory,
onViewProfile: onViewProfile,
onViewStory: onViewStory,
onAddStory: onAddStory,
onViewPhoto: onViewPhoto,
showSharingActions: showSharingActions
)
}
}
/// Variant with an explicit preview rendered directly in the system overlay —
/// use when the default "lift" animation is clipped by the surrounding layout.
func profileContextMenu(
handle: String?,
hasStory: Bool,
onViewProfile: (() -> Void)? = nil,
onViewStory: (() -> Void)? = nil,
onAddStory: (() -> Void)? = nil,
onViewPhoto: (() -> Void)? = nil,
showSharingActions: Bool = true,
@ViewBuilder preview: @escaping () -> some View
) -> some View {
contextMenu {
profileMenuItems(
handle: handle,
hasStory: hasStory,
onViewProfile: onViewProfile,
onViewStory: onViewStory,
onAddStory: onAddStory,
onViewPhoto: onViewPhoto,
showSharingActions: showSharingActions
)
} preview: {
preview()
}
}
/// Conditionally apply a view modifier without duplicating the entire view tree.
@ViewBuilder
func `if`(_ condition: Bool, transform: (Self) -> some View) -> some View {
if condition {
transform(self)
} else {
self
}
}
}
@ViewBuilder
private func profileMenuItems(
handle: String?,
hasStory: Bool,
onViewProfile: (() -> Void)?,
onViewStory: (() -> Void)?,
onAddStory: (() -> Void)?,
onViewPhoto: (() -> Void)?,
showSharingActions: Bool = true
) -> some View {
if hasStory, let onViewStory {
Button(action: onViewStory) {
Label("View story", systemImage: "play.circle")
}
}
if let onAddStory {
Button(action: onAddStory) {
Label("New story", systemImage: "plus.circle")
}
}
if let onViewProfile {
Button(action: onViewProfile) {
Label("View profile", systemImage: "person.circle")
}
}
if let onViewPhoto {
Button(action: onViewPhoto) {
Label("View profile photo", systemImage: "person.crop.circle.fill")
}
}
if showSharingActions, let handle {
Divider()
ShareLink(item: URL(string: "https://grain.social/profile/\(handle)") ?? URL(string: "https://grain.social")!) {
Label("Share profile", systemImage: "square.and.arrow.up")
}
}
}