I tried to add NavigationStack
and also NavigationView
into this view but I cannot get the navigation bar. What prevents this view from creating a navigation bar at the top?
Below is the code I tried.
var body: some View {
NavigationStack {
GeometryReader { proxy in
VStack {
selectedView
Spacer()
HStack(alignment: .bottom) {
TabBarItem(label: "Listings", iconName: "house.fill", action: {
selectedTab = 0
selectedView = AnyView(homeView)
})
TabBarItem(label: "Favorites", iconName: "heart.fill", action: {
selectedTab = 1
selectedView = AnyView(FavoritesView(userId: $userId, firestoreService: firestoreService, storageService: storageService, messagingService: messagingService))
})
Text("Create")
TabBarItem(label: "Messages", iconName: "message.fill", action: {
selectedTab = 2
selectedView = AnyView(ConversationsView(messagingService: messagingService, storageService: storageService, userId: $userId))
})
TabBarItem(label: "Profile", iconName: "person.fill", action: {
selectedTab = 3
selectedView = AnyView(ProfileView(role: role ?? "Sitter"))
})
}
.font(.footnote)
.padding(.top, 42)
.overlay(alignment: .top) {
Button {
selectedView = AnyView(CreateListingView(role: role))
} label: {
Image(systemName: "plus") // "plus_icon"
.resizable()
.scaledToFit()
.padding()
.frame(width: 50, height: 50)
.foregroundStyle(.white)
.background {
Circle()
.fill(.green) // custom64B054Color
.shadow(radius: 3)
}
}
.padding(9)
}
.padding(.bottom, max(8, proxy.safeAreaInsets.bottom))
.background {
TabBarShape()
.fill(.white)
.shadow(radius: 3)
}
}
.ignoresSafeArea(edges: .bottom)
.onReceive(firestoreService.$listings, perform: { _ in
selectedView = AnyView(homeView)
})
}
}
}
tabBar
8