diff --git a/damus/ContentView.swift b/damus/ContentView.swift index c52b7cec..bf616659 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -137,6 +137,10 @@ struct ContentView: View { } } + func navIsAtRoot() -> Bool { + return navigationCoordinator.isAtRoot() + } + func popToRoot() { navigationCoordinator.popToRoot() isSideBarOpened = false @@ -581,11 +585,12 @@ struct ContentView: View { func switch_timeline(_ timeline: Timeline) { self.isSideBarOpened = false + let navWasAtRoot = self.navIsAtRoot() self.popToRoot() notify(.switched_timeline(timeline)) - if timeline == self.selected_timeline { + if timeline == self.selected_timeline && navWasAtRoot { notify(.scroll_to_top) return } diff --git a/damus/Util/Router.swift b/damus/Util/Router.swift index 407f549b..d7d72d25 100644 --- a/damus/Util/Router.swift +++ b/damus/Util/Router.swift @@ -220,6 +220,10 @@ class NavigationCoordinator: ObservableObject { func push(route: Route) { path.append(route) } + + func isAtRoot() -> Bool { + return path.count == 0 + } func popToRoot() { path = []