I have a list of expandable items, which I made following along this post: https://www.hackingwithswift.com/quick-start/swiftui/how-to-create-expanding-lists
Here is the code:
struct Examples: View {
private struct Example: Identifiable {
let id = UUID()
let string: String
var items: [Example]?
}
private let exampleItems: [Example] = [
Example(string: "One",
items: [Example(string: "1")]),
Example(string: "Two",
items: [Example(string: "2")]),
Example(string: "Three",
items: [Example(string: "3")]),
]
@Environment(\.presentationMode) var presentationMode
var body: some View {
NavigationView {
List(exampleItems, children: \.items) { row in
Text(row.string)
}
}
}
}
And I'd like to add a bit of haptic feedback each time a row is expanded or minimised. In UIKit you'd just pop this in tableView(_:didSelectRowAt:)
, and that would be that.
However I can't figure out the SwiftUI equivalent, and all my attempts to make things tappable or add buttons etc. break the main action of expanding the list row.
How does one perform an action upon a row being expanded/minimised in SwiftUI?