1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Shared/Navigation/AccountViewButton.swift

51 lines
1.6 KiB
Swift
Raw Normal View History

2021-09-25 13:48:22 +05:30
import Defaults
import SwiftUI
2022-12-12 05:48:29 +05:30
struct AccountViewButton: View {
@ObservedObject private var model = AccountsModel.shared
2022-12-12 03:45:56 +05:30
private var navigation = NavigationModel.shared
2021-09-25 13:48:22 +05:30
@Default(.accounts) private var accounts
2021-09-25 13:48:22 +05:30
@Default(.instances) private var instances
@Default(.accountPickerDisplaysUsername) private var accountPickerDisplaysUsername
@Default(.accountPickerDisplaysAnonymousAccounts) private var accountPickerDisplaysAnonymousAccounts
2021-09-25 13:48:22 +05:30
@ViewBuilder var body: some View {
if !instances.isEmpty {
2022-12-12 03:45:56 +05:30
Button {
navigation.presentingAccounts = true
} label: {
HStack {
if !accountPickerDisplaysUsername || !(model.current?.isPublic ?? true) {
2022-12-12 05:48:29 +05:30
if let name = model.current?.app?.rawValue.capitalized {
Image(name)
.resizable()
2022-12-13 16:18:04 +05:30
.frame(width: accountImageSize, height: accountImageSize)
2022-12-12 05:48:29 +05:30
} else {
Image(systemName: "globe")
}
}
if accountPickerDisplaysUsername {
label
.labelStyle(.titleOnly)
}
2021-11-28 20:07:55 +05:30
}
}
.transaction { t in t.animation = .none }
2021-09-25 13:48:22 +05:30
}
}
2022-12-13 16:18:04 +05:30
private var accountImageSize: Double {
#if os(macOS)
20
#else
30
#endif
}
2021-11-28 20:07:55 +05:30
private var label: some View {
Label(model.current?.description ?? "Select Account", systemImage: "globe")
2021-11-28 20:07:55 +05:30
}
2021-09-25 13:48:22 +05:30
}