Skip to content

Comic-Star-55/DeleteGesture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DeleteGesture

A SwiftUI package that provides a flexible delete gesture you can use anywhere in your app — not limited to List or Form.

Overview

DeleteGesture brings the familiar swipe-to-delete interaction to any SwiftUI view. Unlike the built-in .onDelete modifier, which only works within List or Form, this package lets you add delete gestures to any custom view hierarchy.

Key Features

  • 🔓 Use Anywhere — Not bound to List or Form. Add delete gestures to any view.
  • 📱 Cross-Platform — Supports iOS (18+) and macOS (15+).
  • 🎯 Haptic Feedback — Provides tactile feedback when crossing the delete threshold.
  • 📖 Fully Documented — Includes comprehensive DocC documentation.

Installation

Add DeleteGesture to your project using Xcode by adding https://github.com/Comic-Star-55/DeleteGesture.git under File -> Add Package Dependencies...

Quick Start

Use onDelete(perform:) to make any view deletable:

import SwiftUI
import DeleteGesture

struct ContentView: View {
    @State private var items = ["Item 1", "Item 2", "Item 3"]

    var body: some View {
        VStack {
            ForEach(items, id: \.self) { item in
                Text(item)
                    .padding()
                    .frame(maxWidth: .infinity)
                    .background(Color.gray.opacity(0.2))
                    .cornerRadius(8)
                    .onDelete{
                        items.removeAll { $0 == item }
                    }
            }
        }
        .padding()
    }
}

Documentation

This package includes comprehensive DocC documentation covering:

  • DGDeletableItem — The main view wrapper for adding delete gestures
  • onDelete(perform:) — The shared store for coordinating delete gestures
  • Example Usage — Complete code examples showing integration patterns

To build the documentation locally, use in Xcode Command + Control + Shift + D

Use Case

Traditional SwiftUI delete gestures using .onDelete are restricted to List and Form views. This limitation makes it difficult to implement swipe-to-delete in:

  • Custom card layouts
  • Grid views
  • Stacked views
  • Any non-list UI patterns

DeleteGesture removes this restriction, allowing you to add intuitive delete interactions to any part of your SwiftUI interface.

Requirements

  • iOS 18.0+ / macOS 15.0+

License

See the repository for license information.

About

A View to access a delete-gesture from anywhere

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages