“when I navigate to notification view and return back to navigate to seylectedbrand , I get this error: A NavigationLink is presenting a value of type “Brand” but there is no matching navigationDestination declaration visible from the location of the link. The link cannot be activated. Note: Links search for destinations in any surrounding NavigationStack, then within the same column of a NavigationSplitView I put one navStack in home view “
struct HomeView: View {
@Binding var selectedTab: TabBarItem
@StateObject var viewModel: HomeViewModel = HomeViewModel()
var body: some View {
NavigationStack{
VStack(spacing: 0){
NavigationBarView(backgroundColor: .tshleehBlue ,isNotification: true, logo: "logo")
ScrollView {
VStack{
SearchView(searchText: $viewModel.searchText, isFilter: $viewModel.isFilter, showFilter: .constant(true))
BannerView()
BrandsSectionView(selectedTab: $selectedTab)
CarPartsSectionView()
AdsSectionView(viewModel: DependencyProvider.adsViewModel)
}
}
.scrollIndicators(.hidden)
}
.toolbar(.hidden, for: .navigationBar)
}
}
struct BrandsSectionView: View {
@Binding var selectedTab: TabBarItem
@State var openAllBrands: Bool = false
@StateObject var viewModel = HomeViewModel()
var body: some View {
VStack(spacing: 0){
if !viewModel.brands.isEmpty{
SectionHeader(title: "Brands", destination: EmptyView()) {
selectedTab = .brands
}
.padding()
}
ScrollView(.horizontal) {
LazyHStack(alignment:.top){
Button(action: {
openAllBrands = true
}, label: {
BrandCellView(brand: Brand(image: "carLogo", name: "All"), size: size)
})
ForEach(viewModel.brands, id: .self) { brand in
NavigationLink(value: brand) {
BrandCellView(brand: brand , size: size)
}
}
}
.navigationDestination(for: Brand.self) { brand in
AdsListView(viewModel: DependencyProvider.adsViewModel, selectedBrand: brand.name)
}
struct NavigationBarView: View {
var body: some View {
Button(action: {
pushToNotification = true
}, label: {
Image(systemName: "bell")
.foregroundStyle(Color.white)
.font(.system(size: 20))
.padding(10)
.background(Color.gray.opacity(0.3))
.clipShape(Circle())
})
.frame(maxWidth: .infinity, alignment: .trailing)
.navigationDestination(isPresented: $pushToNotification) {
NotificationView()
}
}
Mohamed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.