I'm finding that when using a variable within an .actionSheet
the variables are not updating after the initial engagement. I've tried using this in the main view and the extracted view and the behavior is exactly the same. In the picture below I tapped Tuesday, but I'm showing Monday's data. This is also making it difficult to run a function where I need to pass data.
Here's a sample of code that reproduces the issue.
var body: some View {
VStack {
ForEach(sampleSourceData) { link in
VStack {
SampleView(day: link.day, distance: link.distance, exercise: link.exercise, showActionSheet: $showActionSheet)
}
.actionSheet(isPresented: $showActionSheet) {
ActionSheet(title: Text("\(link.day): \(link.distance) \(link.exercise)"),
message: Text("Stay Golden"),
buttons: [
.cancel(),
.default(
Text("Action 1")
),
.default(
Text("Action 2")
)
]
)
}
}
}
}
Sample data and extracted view:
struct RunSourceSample: Identifiable {
var id = UUID()
var day: String
var exercise: String
var distance: String
}
var sampleSourceData = [
RunSourceSample(day: "Monday", exercise: "Long run", distance: "6 Miles"),
RunSourceSample(day: "Tuesday", exercise: "Tempo", distance: "9 Miles"),
RunSourceSample(day: "Wednesday", exercise: "Rest", distance: ""),
RunSourceSample(day: "Thursday", exercise: "Easy Run", distance: "4 Miles")
]
struct SampleView: View {
var day: String
var distance: String
var exercise: String
@Binding var showActionSheet: Bool
var body: some View {
HStack {
Text(day)
Text(distance)
Text(exercise)
Spacer()
Button(action: {
self.showActionSheet = true
}) {
Image(systemName: "ellipsis")
}
}
.padding()
.background(Color("BlueGray"))
.cornerRadius(13)
}
}