2023-01-06 11:14:05 +00:00
|
|
|
import DesignSystem
|
2023-01-17 10:36:01 +00:00
|
|
|
import Env
|
|
|
|
import SwiftUI
|
2023-01-06 11:14:05 +00:00
|
|
|
|
2023-09-19 07:18:20 +00:00
|
|
|
@MainActor
|
2023-01-12 17:17:21 +00:00
|
|
|
public struct AppAccountsSelectorView: View {
|
2023-09-19 07:18:20 +00:00
|
|
|
@Environment(UserPreferences.self) private var preferences
|
2023-09-18 05:01:23 +00:00
|
|
|
@Environment(CurrentAccount.self) private var currentAccount
|
|
|
|
@Environment(AppAccountsManager.self) private var appAccounts
|
2023-09-18 19:03:52 +00:00
|
|
|
@Environment(Theme.self) private var theme
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-09-18 05:01:23 +00:00
|
|
|
var routerPath: RouterPath
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-06 11:14:05 +00:00
|
|
|
@State private var accountsViewModel: [AppAccountViewModel] = []
|
2023-03-08 18:02:31 +00:00
|
|
|
@State private var isPresented: Bool = false
|
2023-01-25 12:02:28 +00:00
|
|
|
|
2023-01-16 12:39:35 +00:00
|
|
|
private let accountCreationEnabled: Bool
|
2023-11-20 09:59:49 +00:00
|
|
|
private let avatarConfig: AvatarView.FrameConfig
|
2023-02-26 05:45:57 +00:00
|
|
|
|
2023-03-12 11:01:38 +00:00
|
|
|
private var showNotificationBadge: Bool {
|
2023-02-23 17:57:28 +00:00
|
|
|
accountsViewModel
|
2023-02-26 05:45:57 +00:00
|
|
|
.filter { $0.account?.id != currentAccount.account?.id }
|
2023-09-16 12:15:03 +00:00
|
|
|
.compactMap(\.appAccount.oauthToken)
|
2023-09-19 06:44:11 +00:00
|
|
|
.map { preferences.notificationsCount[$0] ?? 0 }
|
2023-02-26 05:45:57 +00:00
|
|
|
.reduce(0, +) > 0
|
2023-02-23 17:57:28 +00:00
|
|
|
}
|
2023-03-13 12:38:28 +00:00
|
|
|
|
2023-03-12 11:01:38 +00:00
|
|
|
private var preferredHeight: CGFloat {
|
2023-12-28 15:03:16 +00:00
|
|
|
var baseHeight: CGFloat = 310
|
2023-03-12 11:01:38 +00:00
|
|
|
baseHeight += CGFloat(60 * accountsViewModel.count)
|
|
|
|
return baseHeight
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-17 14:14:50 +00:00
|
|
|
public init(routerPath: RouterPath,
|
2023-01-16 12:39:35 +00:00
|
|
|
accountCreationEnabled: Bool = true,
|
2023-11-20 09:59:49 +00:00
|
|
|
avatarConfig: AvatarView.FrameConfig = .badge)
|
2023-01-17 10:36:01 +00:00
|
|
|
{
|
2023-01-17 14:14:50 +00:00
|
|
|
self.routerPath = routerPath
|
2023-01-16 12:39:35 +00:00
|
|
|
self.accountCreationEnabled = accountCreationEnabled
|
2023-11-20 09:59:49 +00:00
|
|
|
self.avatarConfig = avatarConfig
|
2023-01-12 17:17:21 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-12 17:17:21 +00:00
|
|
|
public var body: some View {
|
2023-03-08 18:02:31 +00:00
|
|
|
Button {
|
|
|
|
isPresented.toggle()
|
2023-11-07 10:22:36 +00:00
|
|
|
HapticManager.shared.fireHaptic(.buttonPress)
|
2023-03-08 18:02:31 +00:00
|
|
|
} label: {
|
|
|
|
labelView
|
2023-11-20 17:43:16 +00:00
|
|
|
.contentShape(Rectangle())
|
2023-01-24 10:40:18 +00:00
|
|
|
}
|
2023-03-08 18:02:31 +00:00
|
|
|
.sheet(isPresented: $isPresented, content: {
|
2023-10-16 17:08:59 +00:00
|
|
|
accountsView.presentationDetents([.height(preferredHeight), .large])
|
|
|
|
.presentationBackground(.thinMaterial)
|
|
|
|
.presentationCornerRadius(16)
|
|
|
|
.onAppear {
|
|
|
|
refreshAccounts()
|
|
|
|
}
|
2023-03-08 18:02:31 +00:00
|
|
|
})
|
2023-09-18 05:01:23 +00:00
|
|
|
.onChange(of: currentAccount.account?.id) {
|
2023-01-06 11:14:05 +00:00
|
|
|
refreshAccounts()
|
|
|
|
}
|
2023-03-10 07:13:40 +00:00
|
|
|
.onAppear {
|
|
|
|
refreshAccounts()
|
|
|
|
}
|
Timeline & Timeline detail accessibility uplift (#1323)
* Improve accessibility of StatusPollView
Previously, this view did not provide the proper context to indicate that it represented a poll.
Now, we’ve added
- A container that will stay “Active poll” or “Poll results” when the cursor first hits one of the options;
- A prefix to say “Option X of Y” before each option;
- A Selected trait on the selected option(s), if present
- Consolidating and adding an `.updatesFrequently` trait to the footer view with the countdown.
* Add poll description in StatusRowView combinedAccessibilityLabel
This largely duplicates the logic in `StatusPollView`.
* Improve accessibility of media attachments
Previously, the media attachments without alt text would not show up in the consolidated `StatusRowView`, nor would they be meaningfully explained on the status detail screen.
Now, they are presented with their attachment type.
* Change accessibilityRepresentation of AppAcountsSelectorView
* Change Notifications tab title view accessibility representation to Menu
Previously it would present as a button
* Hide layout `Rectangle`s from accessibility
* Consolidate `StatusRowDetailView` accessibility representation
* Improve readability of Poll accessibility label
* Ensure poll options don’t present as interactive when the poll is finished
* Improve accessibility of StatusRowCardView
Previously, it would present as four separate elements, including an image without a description, all interactive, none with an interactive trait.
Now, it presents as a single element with the `.link` trait
* Improve accessibility of StatusRowHeaderView
Previously, it had no traits and no actions except inherited ones.
Now it presents as a button, triggering its primary action.
It also has custom actions corresponding to its context menu
* Avoid applying the StatusRowView custom actions to every view when contained
* Provide context for the application name
* Add pauses to StatusRowView combinedAccessibilityLabel
* Hide `TimelineView.scrollToTopView` from accessibility
* Set appropriate font style on Notification header
After the change the Text needed a `.headline` style to match the prior appearance.
* Fix bug in accessibilityRepresentation of TimelineView nav bar title
Previously, it would not display the proper label for .remoteLocal filter options.
* Ensure that pop-up button nav bar titles are interactive
* Ensure TextView responds to Environment.sizeCategory
This resolves #1309
* Fix button
---------
Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-28 16:48:58 +00:00
|
|
|
.accessibilityRepresentation {
|
|
|
|
Menu("accessibility.app-account.selector.accounts") {}
|
|
|
|
.accessibilityHint("accessibility.app-account.selector.accounts.hint")
|
|
|
|
.accessibilityRemoveTraits(.isButton)
|
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-16 20:15:33 +00:00
|
|
|
@ViewBuilder
|
|
|
|
private var labelView: some View {
|
2023-01-25 12:02:28 +00:00
|
|
|
Group {
|
2023-11-20 09:59:49 +00:00
|
|
|
if let account = currentAccount.account, !currentAccount.isLoadingAccount {
|
2023-11-27 08:00:52 +00:00
|
|
|
AvatarView(account.avatar, config: avatarConfig)
|
2023-01-25 12:02:28 +00:00
|
|
|
} else {
|
2023-11-27 08:00:52 +00:00
|
|
|
AvatarView(config: avatarConfig)
|
2023-11-20 17:43:16 +00:00
|
|
|
.redacted(reason: .placeholder)
|
|
|
|
.allowsHitTesting(false)
|
2023-01-25 12:02:28 +00:00
|
|
|
}
|
|
|
|
}.overlay(alignment: .topTrailing) {
|
2023-09-16 12:15:03 +00:00
|
|
|
if !currentAccount.followRequests.isEmpty || showNotificationBadge, accountCreationEnabled {
|
2023-01-25 12:02:28 +00:00
|
|
|
Circle()
|
|
|
|
.fill(Color.red)
|
|
|
|
.frame(width: 9, height: 9)
|
|
|
|
}
|
2023-01-16 20:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-03-08 18:02:31 +00:00
|
|
|
private var accountsView: some View {
|
|
|
|
NavigationStack {
|
|
|
|
List {
|
|
|
|
Section {
|
|
|
|
ForEach(accountsViewModel.sorted { $0.acct < $1.acct }, id: \.appAccount.id) { viewModel in
|
|
|
|
AppAccountView(viewModel: viewModel)
|
2023-01-16 20:15:33 +00:00
|
|
|
}
|
2023-12-28 15:03:16 +00:00
|
|
|
addAccountButton
|
2023-03-08 18:02:31 +00:00
|
|
|
}
|
2023-12-19 08:51:20 +00:00
|
|
|
#if !os(visionOS)
|
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
|
|
|
#endif
|
2023-03-13 12:38:28 +00:00
|
|
|
|
2023-03-08 18:02:31 +00:00
|
|
|
if accountCreationEnabled {
|
|
|
|
Section {
|
|
|
|
settingsButton
|
2023-12-28 15:03:16 +00:00
|
|
|
aboutButton
|
|
|
|
supportButton
|
2023-01-16 20:15:33 +00:00
|
|
|
}
|
2023-12-19 08:51:20 +00:00
|
|
|
#if !os(visionOS)
|
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
|
|
|
#endif
|
2023-01-16 20:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-08 18:02:31 +00:00
|
|
|
.listStyle(.insetGrouped)
|
|
|
|
.scrollContentBackground(.hidden)
|
2023-12-06 17:56:19 +00:00
|
|
|
.background(.clear)
|
2023-03-08 18:02:31 +00:00
|
|
|
.navigationTitle("settings.section.accounts")
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
.toolbar {
|
2023-03-14 11:17:05 +00:00
|
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
2023-03-08 18:02:31 +00:00
|
|
|
Button {
|
|
|
|
isPresented.toggle()
|
|
|
|
} label: {
|
2023-03-14 11:17:05 +00:00
|
|
|
Text("action.done").bold()
|
2023-03-08 18:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-16 20:15:33 +00:00
|
|
|
}
|
2023-09-22 06:35:21 +00:00
|
|
|
.environment(routerPath)
|
2023-01-16 20:15:33 +00:00
|
|
|
}
|
2023-03-08 18:02:31 +00:00
|
|
|
}
|
2023-12-28 15:03:16 +00:00
|
|
|
|
|
|
|
private var addAccountButton: some View {
|
|
|
|
Button {
|
|
|
|
isPresented = false
|
|
|
|
HapticManager.shared.fireHaptic(.buttonPress)
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
|
routerPath.presentedSheet = .addAccount
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("app-account.button.add", systemImage: "person.badge.plus")
|
|
|
|
}
|
|
|
|
}
|
2023-03-13 12:38:28 +00:00
|
|
|
|
2023-03-08 18:02:31 +00:00
|
|
|
private var settingsButton: some View {
|
|
|
|
Button {
|
|
|
|
isPresented = false
|
2023-11-07 10:22:36 +00:00
|
|
|
HapticManager.shared.fireHaptic(.buttonPress)
|
2023-03-08 18:02:31 +00:00
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
2023-01-26 06:34:29 +00:00
|
|
|
routerPath.presentedSheet = .settings
|
|
|
|
}
|
2023-03-08 18:02:31 +00:00
|
|
|
} label: {
|
|
|
|
Label("tab.settings", systemImage: "gear")
|
2023-01-26 06:34:29 +00:00
|
|
|
}
|
2023-01-16 20:15:33 +00:00
|
|
|
}
|
2023-12-28 15:03:16 +00:00
|
|
|
|
|
|
|
private var supportButton: some View {
|
|
|
|
Button {
|
|
|
|
isPresented = false
|
|
|
|
HapticManager.shared.fireHaptic(.buttonPress)
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
|
routerPath.presentedSheet = .support
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("settings.app.support", systemImage: "wand.and.stars")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var aboutButton: some View {
|
|
|
|
Button {
|
|
|
|
isPresented = false
|
|
|
|
HapticManager.shared.fireHaptic(.buttonPress)
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
|
routerPath.presentedSheet = .about
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("account.edit.about", systemImage: "info.circle")
|
|
|
|
}
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-06 11:14:05 +00:00
|
|
|
private func refreshAccounts() {
|
2023-03-08 18:02:31 +00:00
|
|
|
accountsViewModel = []
|
|
|
|
for account in appAccounts.availableAccounts {
|
|
|
|
let viewModel: AppAccountViewModel = .init(appAccount: account, isInNavigation: false, showBadge: true)
|
|
|
|
accountsViewModel.append(viewModel)
|
2023-01-06 11:14:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|