I have custom ActionView with two buttons: Car and Bike. When these buttons tapped I need that in the MainView modifiers onCarTap/onBikeTap will be triggered.
With my current implementation here is error:
- Argument passed to call that takes no arguments
- Value of tuple type 'Void' has no member 'onBikeTap'
Source code:
struct ActionView: View {
// Callback for button taps
var onCarTap: (() -> Void)?
var onBikeTap: (() -> Void)?
var body: some View {
HStack {
Button(action: {
onCarTap?()
}, label: {
Text("Car")
})
Button(action: {
onBikeTap?()
}, label: {
Text("Bike")
})
}
}
}
I am looking for solution like this:
struct MainView: View {
var body: some View {
ActionView()
.onCarTap({})
.onBikeTap({ })
}
}
It is possible to implement in this way:
ActionView(onCarTap: {
print("on car tap")
}, onBikeTap: {
print("on bike tap")
})