Skip to content

Commit 5295843

Browse files
authored
swipeActions: add showcase of swipe actions (#101)
1 parent eec5857 commit 5295843

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

Sources/Showcase/ListPlayground.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum ListPlaygroundType: String, CaseIterable {
2020
case sectionedEditActions
2121
case plainStyleSectionedEditActions
2222
case onMoveDelete
23+
case swipeActions
2324
case positioned
2425
case badges
2526

@@ -61,6 +62,8 @@ enum ListPlaygroundType: String, CaseIterable {
6162
return "Plain Style Sectioned EditActions"
6263
case .onMoveDelete:
6364
return ".onMove, .onDelete"
65+
case .swipeActions:
66+
return ".swipeActions"
6467
case .positioned:
6568
return "Positioned"
6669
case .badges:
@@ -137,6 +140,9 @@ struct ListPlayground: View {
137140
case .onMoveDelete:
138141
OnMoveDeleteListPlayground()
139142
.navigationTitle($0.title)
143+
case .swipeActions:
144+
SwipeActionsListPlayground()
145+
.navigationTitle($0.title)
140146
case .positioned:
141147
PositionedListPlayground()
142148
.navigationTitle($0.title)
@@ -803,3 +809,41 @@ struct BadgeListPlayground: View {
803809
}
804810
}
805811
}
812+
813+
struct SwipeActionsListPlayground: View {
814+
@State var rows: [Int] = Array(0..<12)
815+
@State var lastAction = ""
816+
817+
var body: some View {
818+
VStack(spacing: 0) {
819+
Text(lastAction.isEmpty ? "Swipe a row" : lastAction)
820+
.font(.footnote)
821+
.foregroundStyle(.secondary)
822+
.padding(8)
823+
List {
824+
ForEach(rows, id: \.self) { i in
825+
Text("Row \(i) — Add to favorites")
826+
.swipeActions(edge: .trailing) {
827+
Button("Pin") {
828+
lastAction = "Pinned row \(i)"
829+
}
830+
.tint(.purple)
831+
832+
Button("Delete", role: .destructive) {
833+
lastAction = "Deleted row \(i)"
834+
}
835+
}
836+
.swipeActions(edge: .leading) {
837+
Button("Flag") {
838+
lastAction = "Flagged row \(i)"
839+
}
840+
.tint(.orange)
841+
}
842+
}
843+
.onDelete { offsets in
844+
rows.remove(atOffsets: offsets)
845+
}
846+
}
847+
}
848+
}
849+
}

Sources/Showcase/Resources/Localizable.xcstrings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,6 +2857,9 @@
28572857
},
28582858
"Picker .tint(.red)" : {
28592859

2860+
},
2861+
"Pin" : {
2862+
28602863
},
28612864
"Pink" : {
28622865

@@ -3132,6 +3135,9 @@
31323135
},
31333136
"Row %lld" : {
31343137

3138+
},
3139+
"Row %lld — Add to favorites" : {
3140+
31353141
},
31363142
"Row %lld.1" : {
31373143

0 commit comments

Comments
 (0)