I am drawing boxes and I would like to tap on them. However, Tap gesture does not work if I put code inside ScrollView. If I remove GeometryReaer the code works, however I need it (although I do not use it in this simple example). Any ideas how to make code work with ScrollView and GeometryReader?

struct ContentView: View {
var body: some View {
// REMOVING ScrollView makes TapGesture WORK
ScrollView {
WorksGridView()
}
}
}
struct WorksGridView: View {
private var items = 5
var body: some View {
GeometryReader { geometry in
VStack(spacing: 0) {
ForEach(0..<self.items) { index in
GridInventoryItem()
.onTapGesture {
print("I'm not appearing!!!")
}
}
}
}
}
}
struct GridInventoryItem: View {
var body: some View {
Rectangle()
.padding()
.frame(width: 150, height: 150)
}
}
Move the ScrollView inside of the Geometry Reader and it works: Tested on iOS 13.5
struct ContentView: View {
var body: some View {
// REMOVING ScrollView makes TapGesture WORK
WorksGridView()
}
}
struct WorksGridView: View {
private var items = 5
var body: some View {
GeometryReader { geometry in
ScrollView{
VStack(spacing: 0) {
ForEach(0..<self.items) { index in
GridInventoryItem()
.onTapGesture {
print("I'm not appearing!!!")
}
}
}
}
}
}
}
struct GridInventoryItem: View {
var body: some View {
Rectangle()
.padding()
.frame(width: 150, height: 150)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With