Consider a List inside of a NavigationView like this:
struct ContentView: View {
var body: some View {
NavigationView {
List {
Text("Shovel")
Text("Bucket")
Text("Sieve")
}.navigationTitle("Sandbox")
}
}
}
I want to add .swipeActions
to the trailing edge of the list entries like so:
Text("Shovel")
.swipeActions(edge: .trailing) {
Button{} label: { Image(systemName: "trash.fill") }
}
But once I embed the list entry inside of a NavigationLink
, the .swipeActions
don't work anymore.
NavigationLink(destination: Text("Shovel")) {
Text("Shovel")
.swipeActions(edge: .trailing) {
Button{} label: { Image(systemName: "trash.fill") }
}
}
Now onto the question:
Thanks for your help.
You should add the SwipeAction
to the NavigationLink
like so:
NavigationLink(destination: Text("Shovel")) {
Text("Shovel")
}.swipeActions(edge: .trailing) {
Button{} label: { Image(systemName: "trash.fill") }
}
This behavior happens because the swipe action is a modifier
meant for a List Row
. When you had only Text
, it was the row.
However, When Embedding your content in any View
( VStack
, HStack
, NavigationLink
...), that parent becomes the Row
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.