Hi
My objective is like this:
I created a view called “ShortcutIconView”
struct ShortcutIconView: View {
@State var color : Color
@State var label : String
var destination : View //
var body: some View {
VStack {
NavigationLink {
destination
} label: {
RoundedRectangle(cornerRadius: 10)
.fill(color)
.frame(width: 60.0, height: 60.0, alignment: .center)
.shadow(color: .gray, radius: 8.0, x: 10.0, y: 10.0)
.padding(10)
Text(label)
}
}
}
}
each of the square in the list represents a ShortcutIconView, but I like to indicate where to go if the square icon is clicked
the parent view looks something like this
struct Shortcuts : Identifiable {
var id: UUID = UUID()
var color : Color
var label : String
}
struct HScrollListLink: View {
let shortcuts : [Shortcuts] = [ Shortcuts(color: .indigo, label: "Collection"),
Shortcuts(color: .blue, label: "Words"),
Shortcuts(color: .pink, label: "Properties"),
Shortcuts(color: .green, label: "Tags")
] // TODO: Add destination view as property
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(shortcuts) { shortcut in
ShortcutIconView(color: shortcut.color, label: shortcut.label)
}
}
}
}
}
As of now I could not figure out how to implement it…
I tried to use AnyView, any View, @ViewBuilder but with no luck yet