From 7c2e8d6e80abe1386aae5163d838588ed9fe990a Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Tue, 9 Jul 2024 15:53:59 +0200 Subject: [PATCH] Remove popToRoot --- IceCubesApp/App/AppRegistry.swift | 2 +- IceCubesApp/App/Main/AppView.swift | 19 +++++----------- IceCubesApp/App/SideBarView.swift | 8 ------- IceCubesApp/App/Tabs/ExploreTab.swift | 10 --------- IceCubesApp/App/Tabs/MessagesTab.swift | 10 --------- IceCubesApp/App/Tabs/NotificationTab.swift | 10 --------- IceCubesApp/App/Tabs/ProfileTab.swift | 10 --------- .../App/Tabs/Settings/SettingsTab.swift | 7 ------ IceCubesApp/App/Tabs/Tabs.swift | 22 +++++++++---------- .../App/Tabs/Timeline/TimelineTab.swift | 13 +---------- 10 files changed, 18 insertions(+), 93 deletions(-) diff --git a/IceCubesApp/App/AppRegistry.swift b/IceCubesApp/App/AppRegistry.swift index 9a6eb754..398d35a7 100644 --- a/IceCubesApp/App/AppRegistry.swift +++ b/IceCubesApp/App/AppRegistry.swift @@ -133,7 +133,7 @@ extension View { StatusEditHistoryView(statusId: status) .withEnvironments() case .settings: - SettingsTabs(popToRootTab: .constant(.settings), isModal: true) + SettingsTabs(isModal: true) .withEnvironments() .preferredColorScheme(Theme.shared.selectedScheme == .dark ? .dark : .light) case .accountPushNotficationsSettings: diff --git a/IceCubesApp/App/Main/AppView.swift b/IceCubesApp/App/Main/AppView.swift index f7ed8f42..ad12a41c 100644 --- a/IceCubesApp/App/Main/AppView.swift +++ b/IceCubesApp/App/Main/AppView.swift @@ -24,7 +24,6 @@ struct AppView: View { @Binding var selectedTab: AppTab @Binding var appRouterPath: RouterPath - @State var popToRootTab: AppTab = .other @State var iosTabs = iOSTabs.shared @State var sidebarTabs = SidebarTabs.shared @@ -64,21 +63,14 @@ struct AppView: View { #endif return } - if newTab == selectedTab { - /// Stupid hack to trigger onChange binding in tab views. - popToRootTab = .other - DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { - popToRootTab = selectedTab - } - } - + HapticManager.shared.fireHaptic(.tabSelection) SoundEffectManager.shared.playSound(.tabSelection) selectedTab = newTab })) { ForEach(availableTabs) { tab in - tab.makeContentView(selectedTab: $selectedTab, popToRootTab: $popToRootTab) + tab.makeContentView(selectedTab: $selectedTab) .tabItem { if userPreferences.showiPhoneTabLabel { tab.label @@ -108,14 +100,13 @@ struct AppView: View { #if !os(visionOS) var sidebarView: some View { SideBarView(selectedTab: $selectedTab, - popToRootTab: $popToRootTab, tabs: availableTabs) { HStack(spacing: 0) { TabView(selection: $selectedTab) { ForEach(availableTabs) { tab in Tab(value: tab) { - tab.makeContentView(selectedTab: $selectedTab, popToRootTab: $popToRootTab) + tab.makeContentView(selectedTab: $selectedTab) } label: { tab.label } @@ -142,8 +133,8 @@ struct AppView: View { #endif var notificationsSecondaryColumn: some View { - NotificationsTab(selectedTab: .constant(.notifications), - popToRootTab: $popToRootTab, lockedType: nil) + NotificationsTab(selectedTab: .constant(.notifications) + , lockedType: nil) .environment(\.isSecondaryColumn, true) .frame(maxWidth: .secondaryColumnWidth) .id(appAccountsManager.currentAccount.id) diff --git a/IceCubesApp/App/SideBarView.swift b/IceCubesApp/App/SideBarView.swift index e6e96097..fbfbf394 100644 --- a/IceCubesApp/App/SideBarView.swift +++ b/IceCubesApp/App/SideBarView.swift @@ -19,7 +19,6 @@ struct SideBarView: View { @Environment(RouterPath.self) private var routerPath @Binding var selectedTab: AppTab - @Binding var popToRootTab: AppTab var tabs: [AppTab] @ViewBuilder var content: () -> Content @@ -143,13 +142,6 @@ struct SideBarView: View { Button { // ensure keyboard is always dismissed when selecting a tab hideKeyboard() - - if tab == selectedTab { - popToRootTab = .other - DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { - popToRootTab = tab - } - } selectedTab = tab SoundEffectManager.shared.playSound(.tabSelection) if tab == .notifications { diff --git a/IceCubesApp/App/Tabs/ExploreTab.swift b/IceCubesApp/App/Tabs/ExploreTab.swift index 20e49918..e36234d5 100644 --- a/IceCubesApp/App/Tabs/ExploreTab.swift +++ b/IceCubesApp/App/Tabs/ExploreTab.swift @@ -14,7 +14,6 @@ struct ExploreTab: View { @Environment(Client.self) private var client @State private var routerPath = RouterPath() @State private var scrollToTopSignal: Int = 0 - @Binding var popToRootTab: AppTab var body: some View { NavigationStack(path: $routerPath.path) { @@ -28,15 +27,6 @@ struct ExploreTab: View { } .withSafariRouter() .environment(routerPath) - .onChange(of: $popToRootTab.wrappedValue) { _, newValue in - if newValue == .explore { - if routerPath.path.isEmpty { - scrollToTopSignal += 1 - } else { - routerPath.path = [] - } - } - } .onChange(of: client.id) { routerPath.path = [] } diff --git a/IceCubesApp/App/Tabs/MessagesTab.swift b/IceCubesApp/App/Tabs/MessagesTab.swift index 8fba5f2e..76e73e61 100644 --- a/IceCubesApp/App/Tabs/MessagesTab.swift +++ b/IceCubesApp/App/Tabs/MessagesTab.swift @@ -16,7 +16,6 @@ struct MessagesTab: View { @Environment(AppAccountsManager.self) private var appAccount @State private var routerPath = RouterPath() @State private var scrollToTopSignal: Int = 0 - @Binding var popToRootTab: AppTab var body: some View { NavigationStack(path: $routerPath.path) { @@ -29,15 +28,6 @@ struct MessagesTab: View { .toolbarBackground(theme.primaryBackgroundColor.opacity(0.30), for: .navigationBar) .id(client.id) } - .onChange(of: $popToRootTab.wrappedValue) { _, newValue in - if newValue == .messages { - if routerPath.path.isEmpty { - scrollToTopSignal += 1 - } else { - routerPath.path = [] - } - } - } .onChange(of: client.id) { routerPath.path = [] } diff --git a/IceCubesApp/App/Tabs/NotificationTab.swift b/IceCubesApp/App/Tabs/NotificationTab.swift index 7ed40796..2ab6f805 100644 --- a/IceCubesApp/App/Tabs/NotificationTab.swift +++ b/IceCubesApp/App/Tabs/NotificationTab.swift @@ -23,7 +23,6 @@ struct NotificationsTab: View { @State private var scrollToTopSignal: Int = 0 @Binding var selectedTab: AppTab - @Binding var popToRootTab: AppTab let lockedType: Models.Notification.NotificationType? @@ -51,15 +50,6 @@ struct NotificationsTab: View { } .withSafariRouter() .environment(routerPath) - .onChange(of: $popToRootTab.wrappedValue) { _, newValue in - if newValue == .notifications { - if routerPath.path.isEmpty { - scrollToTopSignal += 1 - } else { - routerPath.path = [] - } - } - } .onChange(of: selectedTab) { _, _ in clearNotifications() } diff --git a/IceCubesApp/App/Tabs/ProfileTab.swift b/IceCubesApp/App/Tabs/ProfileTab.swift index ed8324af..12670823 100644 --- a/IceCubesApp/App/Tabs/ProfileTab.swift +++ b/IceCubesApp/App/Tabs/ProfileTab.swift @@ -15,7 +15,6 @@ struct ProfileTab: View { @Environment(CurrentAccount.self) private var currentAccount @State private var routerPath = RouterPath() @State private var scrollToTopSignal: Int = 0 - @Binding var popToRootTab: AppTab var body: some View { NavigationStack(path: $routerPath.path) { @@ -31,15 +30,6 @@ struct ProfileTab: View { .allowsHitTesting(false) } } - .onChange(of: $popToRootTab.wrappedValue) { _, newValue in - if newValue == .profile { - if routerPath.path.isEmpty { - scrollToTopSignal += 1 - } else { - routerPath.path = [] - } - } - } .onChange(of: client.id) { routerPath.path = [] } diff --git a/IceCubesApp/App/Tabs/Settings/SettingsTab.swift b/IceCubesApp/App/Tabs/Settings/SettingsTab.swift index d86f56a4..e9ff43e6 100644 --- a/IceCubesApp/App/Tabs/Settings/SettingsTab.swift +++ b/IceCubesApp/App/Tabs/Settings/SettingsTab.swift @@ -28,8 +28,6 @@ struct SettingsTabs: View { @State private var cachedRemoved = false @State private var timelineCache = TimelineCache() - @Binding var popToRootTab: AppTab - let isModal: Bool @State private var startingPoint: SettingsStartingPoint? = nil @@ -103,11 +101,6 @@ struct SettingsTabs: View { } .withSafariRouter() .environment(routerPath) - .onChange(of: $popToRootTab.wrappedValue) { _, newValue in - if newValue == .notifications { - routerPath.path = [] - } - } } private var accountsSection: some View { diff --git a/IceCubesApp/App/Tabs/Tabs.swift b/IceCubesApp/App/Tabs/Tabs.swift index c5c56fad..ec41be53 100644 --- a/IceCubesApp/App/Tabs/Tabs.swift +++ b/IceCubesApp/App/Tabs/Tabs.swift @@ -31,28 +31,28 @@ enum AppTab: Int, Identifiable, Hashable, CaseIterable, Codable { } @ViewBuilder - func makeContentView(selectedTab: Binding, popToRootTab: Binding) -> some View { + func makeContentView(selectedTab: Binding) -> some View { switch self { case .timeline: - TimelineTab(popToRootTab: popToRootTab) + TimelineTab() case .trending: - TimelineTab(popToRootTab: popToRootTab, timeline: .trending) + TimelineTab(timeline: .trending) case .local: - TimelineTab(popToRootTab: popToRootTab, timeline: .local) + TimelineTab(timeline: .local) case .federated: - TimelineTab(popToRootTab: popToRootTab, timeline: .federated) + TimelineTab(timeline: .federated) case .notifications: - NotificationsTab(selectedTab: selectedTab, popToRootTab: popToRootTab, lockedType: nil) + NotificationsTab(selectedTab: selectedTab, lockedType: nil) case .mentions: - NotificationsTab(selectedTab: selectedTab, popToRootTab: popToRootTab, lockedType: .mention) + NotificationsTab(selectedTab: selectedTab, lockedType: .mention) case .explore: - ExploreTab(popToRootTab: popToRootTab) + ExploreTab() case .messages: - MessagesTab(popToRootTab: popToRootTab) + MessagesTab() case .settings: - SettingsTabs(popToRootTab: popToRootTab, isModal: false) + SettingsTabs(isModal: false) case .profile: - ProfileTab(popToRootTab: popToRootTab) + ProfileTab() case .bookmarks: NavigationTab { AccountStatusesListView(mode: .bookmarks) diff --git a/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift b/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift index 7c4469ed..172ed8ba 100644 --- a/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift +++ b/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift @@ -18,7 +18,6 @@ struct TimelineTab: View { @Environment(UserPreferences.self) private var preferences @Environment(Client.self) private var client @State private var routerPath = RouterPath() - @Binding var popToRootTab: AppTab @State private var didAppear: Bool = false @State private var timeline: TimelineFilter = .home @@ -33,9 +32,8 @@ struct TimelineTab: View { private let canFilterTimeline: Bool - init(popToRootTab: Binding, timeline: TimelineFilter? = nil) { + init(timeline: TimelineFilter? = nil) { canFilterTimeline = timeline == nil - _popToRootTab = popToRootTab _timeline = .init(initialValue: timeline ?? .home) } @@ -77,15 +75,6 @@ struct TimelineTab: View { .onChange(of: currentAccount.account?.id) { resetTimelineFilter() } - .onChange(of: $popToRootTab.wrappedValue) { _, newValue in - if newValue == .timeline { - if routerPath.path.isEmpty { - scrollToTopSignal += 1 - } else { - routerPath.path = [] - } - } - } .onChange(of: client.id) { routerPath.path = [] }