2023-01-17 10:36:01 +00:00
|
|
|
import AppAccount
|
2022-12-24 10:50:05 +00:00
|
|
|
import Combine
|
2023-01-01 13:02:11 +00:00
|
|
|
import DesignSystem
|
2023-01-17 10:36:01 +00:00
|
|
|
import Env
|
2023-01-02 18:23:44 +00:00
|
|
|
import Models
|
2023-01-17 10:36:01 +00:00
|
|
|
import Network
|
|
|
|
import SwiftUI
|
|
|
|
import Timeline
|
2022-11-29 10:46:02 +00:00
|
|
|
|
2023-09-19 07:18:20 +00:00
|
|
|
@MainActor
|
2023-01-22 05:38:30 +00:00
|
|
|
struct TimelineTab: View {
|
2023-09-18 05:01:23 +00:00
|
|
|
@Environment(AppAccountsManager.self) private var appAccount
|
2023-09-18 19:03:52 +00:00
|
|
|
@Environment(Theme.self) private var theme
|
2023-09-18 05:01:23 +00:00
|
|
|
@Environment(CurrentAccount.self) private var currentAccount
|
2023-09-19 07:18:20 +00:00
|
|
|
@Environment(UserPreferences.self) private var preferences
|
2023-09-18 05:01:23 +00:00
|
|
|
@Environment(Client.self) private var client
|
|
|
|
@State private var routerPath = RouterPath()
|
2022-12-27 08:25:26 +00:00
|
|
|
@Binding var popToRootTab: Tab
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-06 11:14:05 +00:00
|
|
|
@State private var didAppear: Bool = false
|
2023-01-16 13:40:23 +00:00
|
|
|
@State private var timeline: TimelineFilter
|
2022-12-31 11:28:27 +00:00
|
|
|
@State private var scrollToTopSignal: Int = 0
|
2023-02-12 15:29:41 +00:00
|
|
|
|
|
|
|
@AppStorage("last_timeline_filter") public var lastTimelineFilter: TimelineFilter = .home
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-16 13:40:23 +00:00
|
|
|
private let canFilterTimeline: Bool
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-16 13:40:23 +00:00
|
|
|
init(popToRootTab: Binding<Tab>, timeline: TimelineFilter? = nil) {
|
|
|
|
canFilterTimeline = timeline == nil
|
|
|
|
self.timeline = timeline ?? .home
|
|
|
|
_popToRootTab = popToRootTab
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2022-11-29 10:46:02 +00:00
|
|
|
var body: some View {
|
2023-01-17 14:14:50 +00:00
|
|
|
NavigationStack(path: $routerPath.path) {
|
Accessibility tweaks + Notifications and Messages tab uplift (#1292)
* Improve StatusRowView accessibility actions
Previously, there was no way to interact with links and hashtags.
Now, these are added to the Actions rotor
* Hide `topPaddingView`s from accessibility
* Fix accessible header rendering in non-filterable TimelineViews
Previously, all navigation title views were assumed to be popup buttons.
Now, we only change the representation for timelines that are filterable.
* Combine tagHeaderView text elements
Previously, these were two separate items
* Prefer shorter Quote action label
* Improve accessibility of StatusEmbeddedView
Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions.
* Add haptics to StatusRowView accessibility actions
* Improve accessibility of ConversationsListRow
This commit adds:
- A combined representation of the component views
- “Unread” as the first part of the label (if this is the case)
- All relevant actions as custom actions
- Reply as magic tap
* Remove StatusRowView accessibilityActions if viewModel.showActions is false
* Hide media attachments from accessibility if the view is not focused
* Combine NotificationRowView accessibility elements; add user actions
Previously, there was no real way to interact with these notifications.
Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile.
* Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning`
This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well.
---------
Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 06:52:29 +00:00
|
|
|
TimelineView(timeline: $timeline, scrollToTopSignal: $scrollToTopSignal, canFilterTimeline: canFilterTimeline)
|
2023-01-17 14:14:50 +00:00
|
|
|
.withAppRouter()
|
|
|
|
.withSheetDestinations(sheetDestinations: $routerPath.presentedSheet)
|
2022-12-23 09:41:55 +00:00
|
|
|
.toolbar {
|
2023-01-06 11:14:05 +00:00
|
|
|
toolbarView
|
2022-12-23 09:41:55 +00:00
|
|
|
}
|
2023-01-22 05:53:18 +00:00
|
|
|
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar)
|
2023-01-30 18:14:43 +00:00
|
|
|
.id(client.id)
|
2022-11-29 10:46:02 +00:00
|
|
|
}
|
2022-12-26 06:36:54 +00:00
|
|
|
.onAppear {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.client = client
|
2023-09-16 12:15:03 +00:00
|
|
|
if !didAppear, canFilterTimeline {
|
2023-01-06 11:14:05 +00:00
|
|
|
didAppear = true
|
2023-02-12 15:29:41 +00:00
|
|
|
if client.isAuth {
|
2023-02-09 11:27:59 +00:00
|
|
|
timeline = lastTimelineFilter
|
|
|
|
} else {
|
2023-02-12 15:29:41 +00:00
|
|
|
timeline = .federated
|
2023-02-09 11:27:59 +00:00
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
}
|
2023-01-02 18:23:44 +00:00
|
|
|
Task {
|
|
|
|
await currentAccount.fetchLists()
|
|
|
|
}
|
2023-01-26 21:07:21 +00:00
|
|
|
if !client.isAuth {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.presentedSheet = .addAccount
|
2023-01-12 05:30:43 +00:00
|
|
|
}
|
2022-12-26 06:36:54 +00:00
|
|
|
}
|
2023-09-18 05:01:23 +00:00
|
|
|
.onChange(of: client.isAuth) {
|
2023-02-12 15:29:41 +00:00
|
|
|
if client.isAuth {
|
2023-02-09 11:27:59 +00:00
|
|
|
timeline = lastTimelineFilter
|
|
|
|
} else {
|
2023-02-12 15:29:41 +00:00
|
|
|
timeline = .federated
|
2023-02-09 11:27:59 +00:00
|
|
|
}
|
2023-09-18 05:01:23 +00:00
|
|
|
}
|
|
|
|
.onChange(of: currentAccount.account?.id) {
|
2023-02-12 15:29:41 +00:00
|
|
|
if client.isAuth, canFilterTimeline {
|
2023-02-09 11:27:59 +00:00
|
|
|
timeline = lastTimelineFilter
|
|
|
|
} else {
|
2023-02-12 15:29:41 +00:00
|
|
|
timeline = .federated
|
2023-02-09 11:27:59 +00:00
|
|
|
}
|
2023-09-18 05:01:23 +00:00
|
|
|
}
|
|
|
|
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
|
|
|
|
if newValue == .timeline {
|
2023-01-17 14:14:50 +00:00
|
|
|
if routerPath.path.isEmpty {
|
2022-12-31 11:28:27 +00:00
|
|
|
scrollToTopSignal += 1
|
|
|
|
} else {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.path = []
|
2022-12-31 11:28:27 +00:00
|
|
|
}
|
2022-12-24 10:50:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-18 05:01:23 +00:00
|
|
|
.onChange(of: client.id) {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.path = []
|
2023-01-02 18:23:44 +00:00
|
|
|
}
|
2023-09-18 05:01:23 +00:00
|
|
|
.onChange(of: timeline) { _, newValue in
|
|
|
|
if client.isAuth, newValue == .home || newValue == .federated || newValue == .local {
|
|
|
|
lastTimelineFilter = newValue
|
2023-02-09 11:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 14:14:50 +00:00
|
|
|
.withSafariRouter()
|
2023-09-18 05:01:23 +00:00
|
|
|
.environment(routerPath)
|
2022-11-29 10:46:02 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-02 18:23:44 +00:00
|
|
|
@ViewBuilder
|
2022-12-26 06:36:54 +00:00
|
|
|
private var timelineFilterButton: some View {
|
2023-02-25 18:32:47 +00:00
|
|
|
if timeline.supportNewestPagination {
|
2023-02-04 20:21:36 +00:00
|
|
|
Button {
|
2023-09-16 12:15:03 +00:00
|
|
|
timeline = .latest
|
2023-02-04 20:21:36 +00:00
|
|
|
} label: {
|
|
|
|
Label(TimelineFilter.latest.localizedTitle(), systemImage: TimelineFilter.latest.iconName() ?? "")
|
|
|
|
}
|
2023-02-06 11:24:48 +00:00
|
|
|
.keyboardShortcut("r", modifiers: .command)
|
2023-02-04 20:21:36 +00:00
|
|
|
Divider()
|
|
|
|
}
|
2023-01-01 17:31:23 +00:00
|
|
|
ForEach(TimelineFilter.availableTimeline(client: client), id: \.self) { timeline in
|
|
|
|
Button {
|
|
|
|
self.timeline = timeline
|
|
|
|
} label: {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label(timeline.localizedTitle(), systemImage: timeline.iconName() ?? "")
|
2023-01-01 13:02:11 +00:00
|
|
|
}
|
2022-12-26 06:36:54 +00:00
|
|
|
}
|
2023-01-02 18:23:44 +00:00
|
|
|
if !currentAccount.lists.isEmpty {
|
2023-01-19 17:14:08 +00:00
|
|
|
Menu("timeline.filter.lists") {
|
2023-02-10 05:38:18 +00:00
|
|
|
ForEach(currentAccount.sortedLists) { list in
|
2023-01-02 18:23:44 +00:00
|
|
|
Button {
|
|
|
|
timeline = .list(list: list)
|
|
|
|
} label: {
|
|
|
|
Label(list.title, systemImage: "list.bullet")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-04 17:37:58 +00:00
|
|
|
if !currentAccount.tags.isEmpty {
|
2023-01-19 17:14:08 +00:00
|
|
|
Menu("timeline.filter.tags") {
|
2023-02-10 05:38:18 +00:00
|
|
|
ForEach(currentAccount.sortedTags) { tag in
|
2023-01-04 17:37:58 +00:00
|
|
|
Button {
|
|
|
|
timeline = .hashtag(tag: tag.name, accountId: nil)
|
|
|
|
} label: {
|
|
|
|
Label("#\(tag.name)", systemImage: "number")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-22 05:38:30 +00:00
|
|
|
|
2023-01-19 17:14:08 +00:00
|
|
|
Menu("timeline.filter.local") {
|
2023-01-06 16:14:34 +00:00
|
|
|
ForEach(preferences.remoteLocalTimelines, id: \.self) { server in
|
|
|
|
Button {
|
2023-02-06 11:24:48 +00:00
|
|
|
timeline = .remoteLocal(server: server, filter: .local)
|
2023-01-06 16:14:34 +00:00
|
|
|
} label: {
|
2023-02-06 11:24:48 +00:00
|
|
|
VStack {
|
|
|
|
Label(server, systemImage: "dot.radiowaves.right")
|
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-06 16:14:34 +00:00
|
|
|
Button {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.presentedSheet = .addRemoteLocalTimeline
|
2023-01-06 16:14:34 +00:00
|
|
|
} label: {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label("timeline.filter.add-local", systemImage: "badge.plus.radiowaves.right")
|
2023-01-06 16:14:34 +00:00
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
}
|
2023-07-19 05:46:25 +00:00
|
|
|
|
|
|
|
Menu("timeline.filter.tag-groups") {
|
|
|
|
ForEach(preferences.tagGroups, id: \.self) { group in
|
|
|
|
Button {
|
|
|
|
timeline = .tagGroup(group)
|
|
|
|
} label: {
|
|
|
|
VStack {
|
|
|
|
let icon = group.sfSymbolName.isEmpty ? "number" : group.sfSymbolName
|
|
|
|
Label(group.title, systemImage: icon)
|
2023-07-19 05:44:35 +00:00
|
|
|
}
|
2023-07-19 05:46:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
routerPath.presentedSheet = .addTagGroup
|
|
|
|
} label: {
|
|
|
|
Label("timeline.filter.add-tag-groups", systemImage: "plus")
|
2023-07-19 05:44:35 +00:00
|
|
|
}
|
2023-07-19 05:46:25 +00:00
|
|
|
}
|
2023-01-01 13:02:11 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-06 11:14:05 +00:00
|
|
|
private var addAccountButton: some View {
|
2023-01-01 13:02:11 +00:00
|
|
|
Button {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.presentedSheet = .addAccount
|
2023-01-01 13:02:11 +00:00
|
|
|
} label: {
|
2023-01-06 11:14:05 +00:00
|
|
|
Image(systemName: "person.badge.plus")
|
|
|
|
}
|
2023-02-15 17:47:42 +00:00
|
|
|
.accessibilityLabel("accessibility.tabs.timeline.add-account")
|
2023-01-06 11:14:05 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-06 11:14:05 +00:00
|
|
|
@ToolbarContentBuilder
|
|
|
|
private var toolbarView: some ToolbarContent {
|
2023-01-16 13:40:23 +00:00
|
|
|
if canFilterTimeline {
|
|
|
|
ToolbarTitleMenu {
|
|
|
|
timelineFilterButton
|
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
}
|
|
|
|
if client.isAuth {
|
2023-01-16 21:01:04 +00:00
|
|
|
if UIDevice.current.userInterfaceIdiom != .pad {
|
2023-01-16 20:15:33 +00:00
|
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
2023-01-17 14:14:50 +00:00
|
|
|
AppAccountsSelectorView(routerPath: routerPath)
|
2023-01-30 20:41:42 +00:00
|
|
|
.id(currentAccount.account?.id)
|
2023-01-16 20:15:33 +00:00
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
}
|
2023-01-17 14:14:50 +00:00
|
|
|
statusEditorToolbarItem(routerPath: routerPath,
|
2023-01-25 05:28:16 +00:00
|
|
|
visibility: preferences.postVisibility)
|
2023-09-16 12:15:03 +00:00
|
|
|
if UIDevice.current.userInterfaceIdiom == .pad, !preferences.showiPadSecondaryColumn {
|
2023-02-21 12:37:31 +00:00
|
|
|
SecondaryColumnToolbarItem()
|
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
} else {
|
|
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
|
|
addAccountButton
|
2023-01-01 13:02:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
switch timeline {
|
|
|
|
case let .list(list):
|
|
|
|
ToolbarItem {
|
|
|
|
Button {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.presentedSheet = .listEdit(list: list)
|
2023-01-06 11:14:05 +00:00
|
|
|
} label: {
|
|
|
|
Image(systemName: "list.bullet")
|
2023-01-01 13:02:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-06 11:24:48 +00:00
|
|
|
case let .remoteLocal(server, _):
|
2023-01-06 11:14:05 +00:00
|
|
|
ToolbarItem {
|
2023-02-06 11:24:48 +00:00
|
|
|
Menu {
|
|
|
|
ForEach(RemoteTimelineFilter.allCases, id: \.self) { filter in
|
|
|
|
Button {
|
|
|
|
timeline = .remoteLocal(server: server, filter: filter)
|
|
|
|
} label: {
|
|
|
|
Label(filter.localizedTitle(), systemImage: filter.iconName())
|
|
|
|
}
|
|
|
|
}
|
2023-01-01 13:02:11 +00:00
|
|
|
} label: {
|
2023-02-06 11:24:48 +00:00
|
|
|
Image(systemName: "line.3.horizontal.decrease.circle")
|
2023-01-01 13:02:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
default:
|
|
|
|
ToolbarItem {
|
|
|
|
EmptyView()
|
2023-01-01 13:02:11 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-26 06:36:54 +00:00
|
|
|
}
|
2022-11-29 10:46:02 +00:00
|
|
|
}
|