Невозможно получить root-доступ при работе с NavigationStack в SwiftUI при нажатии значка на панели вкладок. ⇐ IOS
Невозможно получить root-доступ при работе с NavigationStack в SwiftUI при нажатии значка на панели вкладок.
I'm working on implementing a pop-to-root view for my tab bar views in SwiftUI. With my current code, I can print the newValue on every tap after the first. The code works as expected but does not reset the NavigationStack for the given tab. Is there something I'm missing here?
Here is the code, it's based on a video I found for more context. Video
import SwiftUI struct TabViews: View { enum Tab { case friends, home, profile } @State private var activeTab: Tab = .home @State private var friendsStack: NavigationPath = .init() @State private var homeStack: NavigationPath = .init() @State private var profileStack: NavigationPath = .init() var body: some View { TabView(selection: tabSelection) { Group { NavigationStack(path: $friendsStack) { Text("Friends") } .tabItem { Image("FriendsTabIcon") } .tag(Tab.friends) NavigationStack(path: $homeStack) { Text("Home") } .tabItem { Image("HomeTabIcon") } .tag(Tab.home) NavigationStack(path: $profileStack) { Text("Profile") } .tabItem { Image("ProfileTabIcon") } .tag(Tab.profile) } .toolbarBackground(.visible, for: .tabBar) .toolbarBackground(.brandBackground, for: .tabBar) } } var tabSelection: Binding { return .init { return activeTab } set: { newValue in if newValue == activeTab { print(newValue) switch newValue { case .friends: friendsStack = .init() case .home: homeStack = .init() case .profile: profileStack = .init() } } activeTab = newValue } } } #Preview { TabViews() }
Источник: https://stackoverflow.com/questions/781 ... n-pressing
I'm working on implementing a pop-to-root view for my tab bar views in SwiftUI. With my current code, I can print the newValue on every tap after the first. The code works as expected but does not reset the NavigationStack for the given tab. Is there something I'm missing here?
Here is the code, it's based on a video I found for more context. Video
import SwiftUI struct TabViews: View { enum Tab { case friends, home, profile } @State private var activeTab: Tab = .home @State private var friendsStack: NavigationPath = .init() @State private var homeStack: NavigationPath = .init() @State private var profileStack: NavigationPath = .init() var body: some View { TabView(selection: tabSelection) { Group { NavigationStack(path: $friendsStack) { Text("Friends") } .tabItem { Image("FriendsTabIcon") } .tag(Tab.friends) NavigationStack(path: $homeStack) { Text("Home") } .tabItem { Image("HomeTabIcon") } .tag(Tab.home) NavigationStack(path: $profileStack) { Text("Profile") } .tabItem { Image("ProfileTabIcon") } .tag(Tab.profile) } .toolbarBackground(.visible, for: .tabBar) .toolbarBackground(.brandBackground, for: .tabBar) } } var tabSelection: Binding { return .init { return activeTab } set: { newValue in if newValue == activeTab { print(newValue) switch newValue { case .friends: friendsStack = .init() case .home: homeStack = .init() case .profile: profileStack = .init() } } activeTab = newValue } } } #Preview { TabViews() }
Источник: https://stackoverflow.com/questions/781 ... n-pressing
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как изменить размеры панели вкладок в контроллере контроллера стержня вкладок.
Anonymous » » в форуме IOS - 0 Ответы
- 8 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Есть ли какое -либо преимущество использования NavigationStack при работе с навигацией.
Anonymous » » в форуме IOS - 0 Ответы
- 6 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Есть ли какое -либо преимущество использования NavigationStack при работе с навигацией.
Anonymous » » в форуме IOS - 0 Ответы
- 7 Просмотры
-
Последнее сообщение Anonymous
-