diff --git a/Sources/Showcase/ListPlayground.swift b/Sources/Showcase/ListPlayground.swift index ac97545..fd352f3 100644 --- a/Sources/Showcase/ListPlayground.swift +++ b/Sources/Showcase/ListPlayground.swift @@ -20,6 +20,7 @@ enum ListPlaygroundType: String, CaseIterable { case sectionedEditActions case plainStyleSectionedEditActions case onMoveDelete + case swipeActions case positioned var title: String { @@ -60,6 +61,8 @@ enum ListPlaygroundType: String, CaseIterable { return "Plain Style Sectioned EditActions" case .onMoveDelete: return ".onMove, .onDelete" + case .swipeActions: + return ".swipeActions" case .positioned: return "Positioned" } @@ -132,6 +135,9 @@ struct ListPlayground: View { case .onMoveDelete: OnMoveDeleteListPlayground() .navigationTitle($0.title) + case .swipeActions: + SwipeActionsListPlayground() + .navigationTitle($0.title) case .positioned: PositionedListPlayground() .navigationTitle($0.title) @@ -693,3 +699,41 @@ struct PositionedListPlayground: View { } } } + +struct SwipeActionsListPlayground: View { + @State var rows: [Int] = Array(0..<12) + @State var lastAction = "" + + var body: some View { + VStack(spacing: 0) { + Text(lastAction.isEmpty ? "Swipe a row" : lastAction) + .font(.footnote) + .foregroundStyle(.secondary) + .padding(8) + List { + ForEach(rows, id: \.self) { i in + Text("Row \(i) — Add to favorites") + .swipeActions(edge: .trailing) { + Button("Pin") { + lastAction = "Pinned row \(i)" + } + .tint(.purple) + + Button("Delete", role: .destructive) { + lastAction = "Deleted row \(i)" + } + } + .swipeActions(edge: .leading) { + Button("Flag") { + lastAction = "Flagged row \(i)" + } + .tint(.orange) + } + } + .onDelete { offsets in + rows.remove(atOffsets: offsets) + } + } + } + } +} diff --git a/Sources/Showcase/Resources/Localizable.xcstrings b/Sources/Showcase/Resources/Localizable.xcstrings index 2c093fd..ab4835e 100644 --- a/Sources/Showcase/Resources/Localizable.xcstrings +++ b/Sources/Showcase/Resources/Localizable.xcstrings @@ -2477,6 +2477,9 @@ }, "Picker .tint(.red)" : { + }, + "Pin" : { + }, "Pink" : { @@ -2712,6 +2715,9 @@ }, "Row %lld" : { + }, + "Row %lld — Add to favorites" : { + }, "Row %lld.1" : { @@ -3309,6 +3315,9 @@ }, "State: %@" : { + }, + "Status bar hidden" : { + }, "Stop" : {