I want to implement a feature where a view "reverts to default" if its corresponding tab item in the tab bar is tapped while the view is currently active. How can I achieve this? My TabBar is implemented like this:
VStack(spacing: 0) {
TabView(selection: $currentTab) {
HomeView()
.tag(TabBarItem.Home)
UserAnalyticsView()
.tag(TabBarItem.Analytics)
UserProfileView()
.tag(TabBarItem.Profile)
}
Divider()
HStack(spacing: 0) {
ForEach(TabBarItem.allCases, id: \.self) { item in
TabBarButton(item: item, currentTab: $currentTab)
}
}
.padding(.horizontal, 15)
.padding(.top, 10)
.padding(.bottom)
}
For example, if a user is inside a NavigationLink on the homepage, and they were to click the home button on the tabview, it would revert out of the NavigationLink and back to the top of the homepage