Remove popToRoot

This commit is contained in:
Thomas Ricouard 2024-07-09 15:53:59 +02:00
parent 3ec5c8c676
commit 7c2e8d6e80
10 changed files with 18 additions and 93 deletions

View file

@ -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:

View file

@ -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)

View file

@ -19,7 +19,6 @@ struct SideBarView<Content: View>: 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<Content: View>: 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 {

View file

@ -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 = []
}

View file

@ -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 = []
}

View file

@ -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()
}

View file

@ -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 = []
}

View file

@ -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 {

View file

@ -31,28 +31,28 @@ enum AppTab: Int, Identifiable, Hashable, CaseIterable, Codable {
}
@ViewBuilder
func makeContentView(selectedTab: Binding<AppTab>, popToRootTab: Binding<AppTab>) -> some View {
func makeContentView(selectedTab: Binding<AppTab>) -> 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)

View file

@ -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<AppTab>, 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 = []
}