Present modules tip as popover on macOS (#672)

This commit is contained in:
Davide 2024-10-03 17:50:19 +02:00 committed by GitHub
parent 429e79cd3a
commit 8ad144239e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 38 additions and 2 deletions

View File

@ -59,6 +59,7 @@ struct ModuleListView: View, Routable {
} header: {
if !profileEditor.modules.isEmpty {
Text(Strings.Global.modules)
.themeTip(Strings.Views.Profile.ModuleList.Section.footer, edge: .bottom)
}
}
}

View File

@ -38,8 +38,6 @@ struct ProfileGeneralView: View {
name: $profileEditor.name,
placeholder: Strings.Placeholders.Profile.name
)
EmptyView()
.themeSection(footer: Strings.Views.Profile.ModuleList.Section.footer)
StorageSection(
uuid: profileEditor.id
)

View File

@ -50,6 +50,7 @@ extension Theme {
case share
case show
case sleeping
case tip
case tunnelDisable
case tunnelEnable
case tunnelRestart

View File

@ -273,6 +273,37 @@ struct ThemeLockScreenModifier: ViewModifier {
}
}
struct ThemeTipModifier: ViewModifier {
let text: String
let edge: Edge
@State
private var isPresenting = false
func body(content: Content) -> some View {
HStack {
content
Button {
isPresenting = true
} label: {
ThemeImage(.tip)
}
.buttonStyle(.borderless)
}
.popover(isPresented: $isPresenting, arrowEdge: edge) {
VStack {
Text(text)
.foregroundStyle(.primary)
.lineLimit(nil)
.multilineTextAlignment(.leading)
.frame(width: 150.0)
}
.padding(12)
}
}
}
// MARK: - Views
public enum ThemeAnimationCategory: CaseIterable {

View File

@ -101,6 +101,7 @@ public final class Theme: ObservableObject {
case .share: return "square.and.arrow.up"
case .show: return "eye"
case .sleeping: return "powersleep"
case .tip: return "questionmark.circle"
case .tunnelDisable: return "arrow.down"
case .tunnelEnable: return "arrow.up"
case .tunnelRestart: return "arrow.clockwise"
@ -208,6 +209,10 @@ extension View {
public func themeLockScreen() -> some View {
modifier(ThemeLockScreenModifier())
}
public func themeTip(_ text: String, edge: Edge) -> some View {
modifier(ThemeTipModifier(text: text, edge: edge))
}
}
// MARK: - Views