When I call NavigationImageView in my View , I want to send different View in every call , so I can navigate different views.But the problem is how can I send View parameter in NavigationLink. I tried View and UIView but it gives me error.
struct NavigationImageView: View {
var item : Store
var destinationView: View
var body: some View {
NavigationLink(destination:destinationView ) {
Image(uiImage: (item.banner?.url)!.load())
.resizable()
.aspectRatio(CGFloat((item.banner?.ratio)!), contentMode: .fit)
.cornerRadius(12)
.shadow(radius: 4)
.frame(width: CGFloat(UIScreen.main.bounds.width * 0.9), height: CGFloat((UIScreen.main.bounds.width / CGFloat((item.banner?.ratio) ?? 1))))
}
}
}
You need to use generics here, because type of destination view is not known in advance:
struct NavigationImageView<DestinationType: View>: View {
var item : Store
var destinationView: DestinationType
// ... other code
}