I have 5 screens with Tab bar here is code:
struct BaseTabViewUI: View {
@StateObject var routerTask = RouterTask()
var body: some View {
TabView {
FeedUI()
.tabItem {
Label("Feed", systemImage: "house.fill")
}
HistoryUI()
.tabItem {
Label("History", systemImage: "clock.fill")
}
TaskListContainerUI()
.tabItem {
Label("Task", systemImage: "checkmark.circle.fill")
}.environmentObject(routerTask)
TreeUI()
.tabItem {
Label("Tree", systemImage: "leaf.fill")
}
UserUI()
.tabItem {
Label("User", systemImage: "person.fill")
}
}
.accentColor(.blue)
}
}
The problem is in TaskListContainerUI I have 4 UI and when I do navigation, my TabBar gone, I want to show TabBar but can't figure it out. I will create other Containers and want to know how can I do that wiht Scalable and Modular way.
Here is TaskListContainerUI:
struct TaskListContainerUI: View {
@EnvironmentObject var routerTask: RouterTask
var body: some View {
NavigationStack(path: $routerTask.navPath) {
TaskGroupListUI()
.navigationDestination(for: RouterTask.Destination.self) { destination in
switch destination {
case .taskGroupList:
TaskGroupListUI().environmentObject(routerTask)
case .addGroupTask:
AddGroupUI().environmentObject(routerTask)
case .taskDetailList:
TaskDetailListUI().environmentObject(routerTask)
case .taskDetail:
TaskDetailUI().environmentObject(routerTask)
case .addTaskDetail:
AddTaskUI().environmentObject(routerTask)
}
}.environmentObject(routerTask)
}
}
}
Here is my RouterTask:
final class RouterTask: ObservableObject {
public enum Destination: Codable, Hashable {
case taskGroupList
case addGroupTask
case taskDetailList
case taskDetail
case addTaskDetail
}
@Published var navPath = NavigationPath()
func navigate(to destination: Destination) {
navPath.append(destination)
}
func navigateBack() {
navPath.removeLast()
}
func navigateToRoot() {
navPath.removeLast(navPath.count)
}
}
I can see Tab Bar in the TaskGroupListUI() but when I'm navigating to AddGroupUI I can't see TabBar. TaskGroupListUI:
struct TaskGroupListUI: View {
@EnvironmentObject var routerTask: RouterTask
var body: some View {
ZStack { // List ve butonu üst üste koyuyoruz
VStack {
Spacer()
HStack {
Spacer()
btnAddIcon(iconName: "plus") {
routerTask.navigate(to: .addGroupTask)
}.padding()
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity,
alignment: .bottomTrailing)
}
}
}
and that is the AddTaskGroup where I can't see TabBar:
struct AddGroupUI: View {
@EnvironmentObject var routerTask: RouterTask
var body: some View {
Text("add group")
}
}
Here is the parent of BaseTabViewUI :
@main
struct TendriaApp: App {
init() {
FirebaseApp.configure()
}
@StateObject var authManager = AuthManager()
@StateObject var router = RouterSign()
let persistenceController = PersistenceController.shared
var body: some Scene {
WindowGroup {
NavigationStack(path: $router.navPath) {
Group{
if authManager.checkUserSession() {
BaseTabViewUI()
} else {
SignInUI(authManager: authManager)
}
}.navigationDestination(for: RouterSign.Destination.self) { destination in
switch destination {
case .signIn:
SignInUI(authManager: authManager)
case .signUp:
SignUpUI(authManager: authManager)
case .forgotPassword:
ForgotPasswordUI(authManager: authManager)
case .mainScreen:
BaseTabViewUI()
}
}
}
.environmentObject(router)
.environmentObject(authManager).onAppear {
UIApplication.shared.addTapGestureRecognizer()
}
}
}
}
Thanks