I am developing an app in SwiftUI and I currently have a chart with vertically stacked bars on it. When the user clicks on a bar a subview pops up where they can alter some values of the bar. To accomplish this I have been using GeometryReader to detect where the user clicks.
```
.chartOverlay { proxy in
GeometryReader { geometry in
Rectangle().fill(.clear).contentShape(Rectangle())
.onTapGesture { location in
// Get the x and y value from the location.
let (min, name) = proxy.value(at: location, as: (Int, String).self) ?? (0, "")
print("Location: \(min), \(name)")
}
}
}
```
However the user can also add bars and when they add enough the chart becomes scrollable and GeometryReader no longer seems to work because it assumes that the position of the bars never changes. Is there a way that I can make the bars tappable and act in the same way as they would with GeometryReader while being in a scrollable chart. Thanks.
I tried making it so that it generated new GeometryReaders for each individual bar, however that would just go out of the bounds of the chart and did not work. I also tried putting those GeometryReaders in a scrollview but then the chart could no longer be scrolled itself.
Instead of using geometry readers and invisible rectangles to implement the gesture, just use
chartGesture.Here is a complete example, where selecting a bar would cause a
Stepperto show up that allows you to change the bar's height.