Open MadeiraAlexandre opened 5 months ago
Set to release on the App Store as version 2.7.3.
@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
@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.
Thanks @MadeiraAlexandre , that's awesome!
Yes, I saw what you've done in the SearchView
to trigger the search-on-tap with the Boolean var.
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
UIKit TabView should fix it, tap to return to root doesn't seem supported yet by SwiftUI TabView.