damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 5e3afd0b1641787a68c6ea43016f71a46fca6761
parent b1c7ef9bd9033c0da2ad2d27e2e34abbd4fdc160
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Fri,  6 Oct 2023 18:35:47 +0000

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>

Diffstat:
Mdamus/ContentView.swift | 7++++++-
Mdamus/Util/Router.swift | 4++++
2 files changed, 10 insertions(+), 1 deletion(-)

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