-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHeader.swift
More file actions
137 lines (120 loc) · 4.7 KB
/
Header.swift
File metadata and controls
137 lines (120 loc) · 4.7 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import SwiftUI
struct Header: View {
@Environment(CalculatorInputManager.self) private var calculatorInput
@AppStorage(PaykitFeatureFlags.uiEnabledKey) private var isPaykitUIEnabled = false
@EnvironmentObject var app: AppViewModel
@EnvironmentObject var navigation: NavigationViewModel
@EnvironmentObject var pubkyProfile: PubkyProfileManager
/// When true, shows the widget edit button (only on the widgets tab).
var showWidgetEditButton: Bool = false
/// Binding to widgets edit state; used when showWidgetEditButton is true.
@Binding var isEditingWidgets: Bool
private var isPaykitUIActive: Bool {
PaykitFeatureFlags.isUIAvailable && isPaykitUIEnabled
}
init(showWidgetEditButton: Bool = false, isEditingWidgets: Binding<Bool> = .constant(false)) {
self.showWidgetEditButton = showWidgetEditButton
_isEditingWidgets = isEditingWidgets
}
var body: some View {
HStack(alignment: .center, spacing: 0) {
if isPaykitUIActive {
profileButton
}
Spacer()
HStack(alignment: .center, spacing: 8) {
AppStatus(
testID: "HeaderAppStatus",
onPress: {
if dismissCalculatorIfNeeded() { return }
navigation.navigate(.appStatus)
}
)
if showWidgetEditButton {
Button(action: {
if dismissCalculatorIfNeeded() { return }
isEditingWidgets.toggle()
}) {
Image(isEditingWidgets ? "check-mark" : "pencil")
.resizable()
.foregroundColor(.textPrimary)
.frame(width: 24, height: 24)
.frame(width: 32, height: 32)
.padding(.leading, 16)
.contentShape(Rectangle())
}
.accessibilityIdentifier("WidgetsEdit")
}
Button {
if dismissCalculatorIfNeeded() { return }
withAnimation {
app.showDrawer = true
}
} label: {
Image("burger")
.resizable()
.foregroundColor(.textPrimary)
.frame(width: 24, height: 24)
.frame(width: 32, height: 32)
.contentShape(Rectangle())
}
.accessibilityIdentifier("HeaderMenu")
}
}
.frame(height: 48)
.zIndex(.infinity)
.padding(.leading, 16)
.padding(.trailing, 10)
}
private var profileButton: some View {
Button {
if dismissCalculatorIfNeeded() { return }
if pubkyProfile.isAuthenticated || pubkyProfile.cachedName != nil {
navigation.navigate(.profile)
} else if pubkyProfile.initializationErrorMessage != nil {
navigation.navigate(.profile)
} else if !pubkyProfile.isInitialized {
// Still initializing — don't navigate to choice screen yet
return
} else if app.hasSeenProfileIntro {
navigation.navigate(.pubkyChoice)
} else {
navigation.navigate(.profileIntro)
}
} label: {
HStack(alignment: .center, spacing: 16) {
profileAvatar
if let name = pubkyProfile.displayName {
TitleText(name)
} else {
TitleText(t("slashtags__your_name_capital"))
}
}
.contentShape(Rectangle())
}
.accessibilityLabel(pubkyProfile.displayName ?? t("profile__nav_title"))
.accessibilityIdentifier("ProfileButton")
}
private func dismissCalculatorIfNeeded() -> Bool {
guard calculatorInput.isPresented else { return false }
calculatorInput.dismiss()
return true
}
@ViewBuilder
private var profileAvatar: some View {
if let imageUri = pubkyProfile.displayImageUri {
PubkyImage(uri: imageUri, size: 32)
} else {
Circle()
.fill(Color.gray4)
.frame(width: 32, height: 32)
.overlay {
Image("user-square")
.resizable()
.scaledToFit()
.foregroundColor(.white32)
.frame(width: 16, height: 16)
}
}
}
}