Skip to content

Commit

Permalink
ui: keep location in timeline when returning from a thread
Browse files Browse the repository at this point in the history
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: #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 <[email protected]>
Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
danieldaquino authored and jb55 committed Oct 6, 2023
1 parent b1c7ef9 commit 5e3afd0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion damus/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ struct ContentView: View {
}
}

func navIsAtRoot() -> Bool {
return navigationCoordinator.isAtRoot()
}

func popToRoot() {
navigationCoordinator.popToRoot()
isSideBarOpened = false
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions damus/Util/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ class NavigationCoordinator: ObservableObject {
func push(route: Route) {
path.append(route)
}

func isAtRoot() -> Bool {
return path.count == 0
}

func popToRoot() {
path = []
Expand Down

0 comments on commit 5e3afd0

Please sign in to comment.