Skip to content

Tab bar tap to return to main page #38

Closed

Description

UIKit TabView should fix it, tap to return to root doesn't seem supported yet by SwiftUI TabView.

Activity

  1. converted this from a draft issue on May 20, 2024
  2. MadeiraAlexandre commented on May 20, 2024

    @MadeiraAlexandre
    ContributorAuthor

    Set to release on the App Store as version 2.7.3.

  3. moved this from In progress to Done in Roadmapon May 20, 2024
  4. kevinm6 commented on Jun 2, 2024

    @kevinm6
    Contributor

    Alexandre Madeira (@MadeiraAlexandre) Do you think that's fine to add a scrollToTop if a tap in the TabBarItem is performed and the TabPage is the same (as the item)?

    I checked but I’m not really into SwiftUI and I can’t find an easy implementation of that feature.

    The idea is common to other apps that uses a TabBar: when you are already on the main page (popToRoot alike) and you tap again the current TabBarItem, the UI scroll to the top

  5. MadeiraAlexandre commented on Jun 2, 2024

    @MadeiraAlexandre
    ContributorAuthor

    Alexandre Madeira (@MadeiraAlexandre) Do you think is fine to add a scrollToTop if a tap in the TabBarItem is performed and the TabPage is the same (as the item).

    I checked but I’m not really into SwiftUI and I can’t find an easy implementation of that feature.

    Yes, it is fine. I've done it for Kitsune for MyAnimeList (on the Season and Profile page, on the others tabs I'll do it in a future update).
    You can control it by using a ScrollViewReader and use a binding to trigger the scroll to the top.
    I've done something like this on the computed property:
    if seasonPath.isEmpty { scrollSeasonToTop.toggle() } else { seasonPath = .init() }
    I pass this bool binding to the SeasonView and it can trigger the scrolling to the top, usually using a hidden circle on the top of the view like this one:
    Circle().fill(.clear).frame(width: 0, height: 0).hidden().id("top_view").onChange(of: scrollToTop) { withAnimation { proxy.scrollTo("top_view", anchor: .top) } }
    On tabs with search field, you could even scroll to the top and then trigger the search field (like Apple does on Apple Music app).
    On Cronica I've set it to open the search field only on the Search page, but you could adapt it to make it work with scrolling too and even bring the same behavior to Watchlist tab. (The file used is TabBarView.swift).
    I'll reopen this issue as a reminder to do it in a future update.

  6. kevinm6 commented on Jun 2, 2024

    @kevinm6
    Contributor

    Thanks Alexandre Madeira (@MadeiraAlexandre) , that's awesome!

    Yes, I saw what you've done in the SearchView to trigger the search-on-tap with the Boolean var.

  7. MadeiraAlexandre commented on Jul 3, 2024

    @MadeiraAlexandre
    ContributorAuthor

    There's some big changes to how TabView operates on iOS and iPadOS 18. Some of this changes could also reduce code for the macOS side.
    Some changes will be likely require on the iPadOS side.
    New documentation:
    https://developer.apple.com/wwdc24/10147
    https://developer.apple.com/documentation/SwiftUI/Enhancing-your-app-content-with-tab-navigation

  8. tomegger commented on Aug 24, 2026

    @tomegger
    Member

    Closing as implemented.

    Tab re-tap behavior is handled in TabBarView via per-tab NavigationPath state: re-selecting the active tab clears the stack (homePath, explorePath, watchlistPath, searchPath) and returns to the root screen. On Search, a re-tap while already at root also focuses the search field.

    This covers the original “tap tab bar item to return to main page” request. Scroll-to-top while already at root (discussed later in the thread) can be tracked separately if still desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions