mirror of
git://jb55.com/damus
synced 2024-09-18 19:23:49 +00:00
ui: keep location in timeline when returning from a thread
Stop tab buttons from causing the root view to scroll to the top unless user is coming from another tab or already at the root view This fixes an issue where if you navigated within a tab and then clicked the tab button, it would scroll to the top. Users want to be able to navigate back to the root of a given tab without losing the scroll position. Now tab buttons only scroll to the top if: - User is coming from a different tab - User is already at the root view of the tab, and they click on the tab button again. Issue repro ---------- 1. Scroll down the home feed a bit 2. Click on one of the posts 3. Click on the home tab button at the bottom left. **Desired behavior:** 1. First click on home button should go to home view but not scroll to top 2. Clicking on home button should only scroll to top when user is already at the root home feed view **Current behavior:** Clicking on home button scrolls to top on step 3 (shouldn't have) Fix testing ----------- Steps: 1. Scroll down the home feed a bit 2. Click on one of the posts. 3. Click on the home tab button. Should go back to home view but keep scroll position. PASS 4. Click on the home tab button again. Should scroll to the top. PASS 5. Scroll down on the home tab. 6. Switch to another tab, then switch back to the home tab. Should scroll to the top of the home view. PASS 7. Scroll down on the home tab 8. Click on the home tab button. Should scroll to the top. PASS 9. Repeat steps 1–8 for DMs, Universe view, and notifications. PASS Closes: https://github.com/damus-io/damus/issues/1580 Changelog-Fixed: Stop tab buttons from causing the root view to scroll to the top unless user is coming from another tab or already at the root view Signed-off-by: Daniel D’Aquino <daniel@daquino.me> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
b1c7ef9bd9
commit
5e3afd0b16
@ -137,6 +137,10 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func navIsAtRoot() -> Bool {
|
||||||
|
return navigationCoordinator.isAtRoot()
|
||||||
|
}
|
||||||
|
|
||||||
func popToRoot() {
|
func popToRoot() {
|
||||||
navigationCoordinator.popToRoot()
|
navigationCoordinator.popToRoot()
|
||||||
isSideBarOpened = false
|
isSideBarOpened = false
|
||||||
@ -581,11 +585,12 @@ struct ContentView: View {
|
|||||||
|
|
||||||
func switch_timeline(_ timeline: Timeline) {
|
func switch_timeline(_ timeline: Timeline) {
|
||||||
self.isSideBarOpened = false
|
self.isSideBarOpened = false
|
||||||
|
let navWasAtRoot = self.navIsAtRoot()
|
||||||
self.popToRoot()
|
self.popToRoot()
|
||||||
|
|
||||||
notify(.switched_timeline(timeline))
|
notify(.switched_timeline(timeline))
|
||||||
|
|
||||||
if timeline == self.selected_timeline {
|
if timeline == self.selected_timeline && navWasAtRoot {
|
||||||
notify(.scroll_to_top)
|
notify(.scroll_to_top)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -220,6 +220,10 @@ class NavigationCoordinator: ObservableObject {
|
|||||||
func push(route: Route) {
|
func push(route: Route) {
|
||||||
path.append(route)
|
path.append(route)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isAtRoot() -> Bool {
|
||||||
|
return path.count == 0
|
||||||
|
}
|
||||||
|
|
||||||
func popToRoot() {
|
func popToRoot() {
|
||||||
path = []
|
path = []
|
||||||
|
Loading…
Reference in New Issue
Block a user