1
0
mirror of git://jb55.com/damus synced 2024-09-16 02:03:45 +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:
Daniel D’Aquino 2023-10-06 18:35:47 +00:00 committed by William Casarin
parent b1c7ef9bd9
commit 5e3afd0b16
2 changed files with 10 additions and 1 deletions

View File

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

View File

@ -220,6 +220,10 @@ class NavigationCoordinator: ObservableObject {
func push(route: Route) {
path.append(route)
}
func isAtRoot() -> Bool {
return path.count == 0
}
func popToRoot() {
path = []