Swipe Left2Right & Right2Left, pure SwiftUI implementation

Overview

SwipeCell

Preview

Features

  • Swipe cell from Left2Right & Right2Left.
  • Destructive swipe

Usage

  • Simply add onSwipe(leading, trailing) method to your list item
List {
    HStack {
        Text("Enes Karaosman")
        Spacer()
    }
    .listRowInsets(EdgeInsets())
    .onSwipe(leading: [
      .. // here add slots
    ])
    
}

But what is Slot?
It's just a container that wraps your elements

public struct Slot: Identifiable {
    
    /// The Icon will be displayed.
    public let image: () -> Image
    
    /// To allow modification on Text, wrap it with AnyView.
    public let title: () -> AnyView
    
    /// Tap Action
    public let action: () -> Void
    
    /// Style
    public let style: SlotStyle
}

public struct SlotStyle {
    
    /// Background color of slot.
    public let background: Color
    
    /// Image tint color
    public let imageColor: Color // default = .white
    
    /// Individual slot width
    public let slotWidth: CGFloat // default = 60
}

That's it, here is full working example

struct SwipeCellDemoView: View {
    
    var slidableContent: some View {
        HStack(spacing: 16) {
            Image(systemName: "person.crop.circle.fill")
            .resizable()
            .scaledToFit()
            .foregroundColor(.secondary)
            .frame(height: 60)
            
            VStack(alignment: .leading) {
                Text("Enes Karaosman")
                .fontWeight(.semibold)
            
                Text("[email protected]")
                .foregroundColor(.secondary)
            }
        }.padding()
    }
    
    var slots = [
        // First item
        Slot(
            image: {
                Image(systemName: "envelope.open.fill")
            },
            title: {
                Text("Read")
                .foregroundColor(.white)
                .font(.footnote)
                .fontWeight(.semibold)
                .embedInAnyView()
            },
            action: { print("Read Slot tapped") },
            style: .init(background: .orange)
        ),
        // Second item
        Slot(
            image: {
                Image(systemName: "hand.raised.fill")
            },
            title: {
                Text("Block")
                .foregroundColor(.white)
                .font(.footnote)
                .fontWeight(.semibold)
                .embedInAnyView()
            },
            action: { print("Block Slot Tapped") },
            style: .init(background: .blue, imageColor: .red)
        )
    ]
    
    var left2Right: some View {
        slidableContent
        .frame(height: 60)
        .padding()
        .onSwipe(leading: slots)
    }
    
    var right2Left: some View {
        slidableContent
        .frame(height: 60)
        .padding()
        .onSwipe(trailing: slots)
    }
    
    var leftAndRight: some View {
        slidableContent
        .frame(height: 60)
        .padding()
        .onSwipe(leading: slots, trailing: slots)
    }
    
    var items: [AnyView] {
        [
            left2Right.embedInAnyView(),
            right2Left.embedInAnyView(),
            leftAndRight.embedInAnyView()
        ]
    }
    
    var body: some View {
        NavigationView {
            List {
                ForEach(items.indices, id: \.self) { idx in
                    self.items[idx]
                }.listRowInsets(EdgeInsets())
            }.navigationBarTitle("Messages")
        }
    }
    
}

Custom

In demo I used system images, but using local image is allowed as well.

ListItem
    .onSwipe(leading: [
        Slot(
            image: {
                Image("localImageName")
                    // To allow colorifying
                    .renderingMode(.template)
            },
            title: {
                Text("Title").embedInAnyView()
            },
            action: { print("Slot tapped") },
            style: .init(background: .orange)
        )
    ])
You might also like...
A better way to present a SFSafariViewController or start a ASWebAuthenticationSession in SwiftUI.
A better way to present a SFSafariViewController or start a ASWebAuthenticationSession in SwiftUI.

BetterSafariView A better way to present a SFSafariViewController or start a ASWebAuthenticationSession in SwiftUI. Contents Motivation Requirements U

A SwiftUI Library for creating resizable partitions for View Content.
A SwiftUI Library for creating resizable partitions for View Content.

Partition Kit Recently Featured In Top 10 Trending Android and iOS Libraries in October and in 5 iOS libraries to enhance your app! What is PartitionK

A micro UIStackView convenience API inspired by SwiftUI
A micro UIStackView convenience API inspired by SwiftUI

Stacks A micro UIStackView convenience API inspired by SwiftUI. let stack: UIView = .hStack(alignment: .center, margins: .all(16), [ .vStack(spaci

SwiftUI: Components Library Inspired by Twitter's Bootstrap
SwiftUI: Components Library Inspired by Twitter's Bootstrap

bootswiftui SwiftUI: Components Library Inspired by Twitter's Bootstrap Warning This is just SwiftUI exercise. Please do not consider using this repo

Zeplin component preview for your SwiftUI views
Zeplin component preview for your SwiftUI views

A Zeplin component preview for your SwiftUI views. You can use Zeplin components instead of real views within your app until you implement them.

A SwiftUI Views for wrapping HStack elements into multiple lines
A SwiftUI Views for wrapping HStack elements into multiple lines

SwiftUI WrappingStack A SwiftUI Views for wrapping HStack elements into multiple lines. List of supported views WrappingHStack - provides HStack that

Blobmorphism is a brand new design language I've created to break free of the material overload in iOS, built in SwiftUI. Everything feels smooth and fluid.
Blobmorphism is a brand new design language I've created to break free of the material overload in iOS, built in SwiftUI. Everything feels smooth and fluid.

Blobmorphism is a brand new design language I've created to break free of the material overload in iOS, built in SwiftUI. Everything feels smooth and fluid.

Create SwiftUI Views with any data

Create SwiftUI Views with any data

Advanced List View for SwiftUI with pagination & different states

AdvancedList This package provides a wrapper view around the SwiftUI List view which adds pagination (through my ListPagination package) and an empty,

Comments
  • App Crashes when using onSwipe viewModifier using iphone8/8plus & iphone11 on iOS 13.0-13.1.3

    App Crashes when using onSwipe viewModifier using iphone8/8plus & iphone11 on iOS 13.0-13.1.3

    Hey!

    Love the package, talked to you briefly on slack a while back.

    Unfortunately I had a couple users hard crash my application on their iphone 11 with iOS 13.0-13.1.3

    I don't even think this is a problem with your package but all custom view modifiers on that device with that os version. Here's an image of a super basic use case in a fresh application to prove.

    import SwiftUI
    import SwipeCell
    
    struct ContentView: View {
        @State var test = [1,2,3,4,5]
        var body: some View {
            List(test, id: \.self) { num in
                Text(num.description)
                    .onSwipe()
            }
        }
    }
    

    I've tried a bunch of variations of the above code and it always crashes 😭

    Screen Shot 2020-11-11 at 7 04 55 PM

    opened by MichaelNeas 4
  • How can I get access to data of List item?

    How can I get access to data of List item?

    Thank you for creating such a great package here.

    I have a question, could I can access the data of list item in action callback? in some cases, we need to use the data of item to act different actions.

    For example,

    List {
        ForEach(list, id: \.self) { content in
               SomeCell(content)
         }
          .onSwipe(trailing: [
                                    Slot(
                                                image: {
                                                    Image(systemName: "ellipsis")
                                                },
                                                title: {
                                                    EmptyView()
                                                        .eraseToAnyView()
                                                },
                                                action: {
                                                    // How can I get access to content of every item here?
                                                },
                                                style: .init(background: .clear)
                                            )
                                ])
                            }
    
    opened by metrue 1
  • Cannot find 'Slot' in scope

    Cannot find 'Slot' in scope

    Hello,

    Thanks for your code.

    After installing the project in xcode (12.5), I copied your example but got an error. Xcode cannot find "Slot"

    DJIBS 2021-06-16 à 09 08 04

    opened by Djibs 1
  • Tap to collapse gesture interferes with navlink tap gesture

    Tap to collapse gesture interferes with navlink tap gesture

    Thanks for creating this library! I am using it with NavLinks and am having the problem of the tap gesture (used to dismiss the actions) causing navlink taps to stop working.

    I've found a solution by having the tap to close gesture be included on a conditional rectangle. Will open a PR

    opened by jjkaufman 1
Releases(0.1.3)
Owner
Enes Karaosman
Enes Karaosman
🚀 Elegant Pager View fully written in pure SwiftUI.

PagerTabStripView Made with ❤️ by Xmartlabs team. XLPagerTabStrip for SwiftUI! Introduction PagerTabStripView is the first pager view built in pure Sw

xmartlabs 482 Jan 9, 2023
A Powerful , Extensible CSS Parser written in pure Swift.

A Powerful , Extensible CSS Parser written in pure Swift. Basic Usage From CSS: #View { "width" : 118; "height" : 120.5; "color1" : "#888888"; "co

null 273 Sep 9, 2022
MUDownloadButton - a Progressive Download button written in pure swift and inspired by AppStore download button

MUDownloadButton is a Progressive Download button written in pure swift and inspired by AppStore download button . feel free to contribute and pull requests

Mohammad ShahibZadeh 2 Feb 20, 2022
A token field implementation for iOS

ResizingTokenField A token field implementation written in Swift 5. Features Can be used in Interface Builder or created programmatically Uses a UICol

Tadej Razboršek 100 Sep 19, 2022
Swift programming language hackathon. Implementation of the main logic of working with an ATM in the Playground environment.

Hackaton-ATM-PJ04 Swift programming language hackathon. Implementation of the main logic of working with an ATM in the Playground environment. The tas

Raman Kozar 2 Oct 4, 2022
A paging scroll view for SwiftUI, using internal SwiftUI components

PagingView A paging scroll view for SwiftUI, using internal SwiftUI components. This is basically the same as TabView in the paging mode with the inde

Eric Lewis 18 Dec 25, 2022
SwiftUI-Drawer - A bottom-up drawer in swiftUI

SwiftUI-Drawer A bottom-up drawer view. Contents Installation Examples Installat

Bruno Wide 9 Dec 29, 2022
SwiftUI-Margin adds a margin() viewModifier to a SwiftUI view.

SwiftUI-Margin adds a margin() viewModifier to a SwiftUI view. You will be able to layout the margins in a CSS/Flutter-like.

Masaaki Kakimoto(柿本匡章) 2 Jul 14, 2022
A number of preset loading indicators created with SwiftUI

ActivityIndicatorView A number of preset loading indicators created with SwiftUI We are a development agency building phenomenal apps. Usage Create an

Exyte 956 Dec 26, 2022