• Stars
    star
    271
  • Rank 151,717 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Swipe Left2Right & Right2Left, pure SwiftUI implementation

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)
        )
    ])

More Repositories

1

SwiftyChat

SwiftUI Chat UI (Client) Framework & Documentation to get started!
Swift
252
star
2

JSONDrivenUI

JSON into native SwiftUI View to build UI for iOS.
Swift
81
star
3

DesignDetective

Compare your implementation and design, see how much they match!
Swift
44
star
4

SwiftUIEKtensions

Extensions for SwiftUI
Swift
22
star
5

swifty_chat

A Chat package for flutter
Dart
21
star
6

SwiftProgress

Progress Bars for SwiftUI
Swift
19
star
7

StarView

SwiftUI StarView Shape, usable for displaying ratings
Swift
16
star
8

LoremSwiftify

LoremSwiftify is a Macro that creates lorem ipsum data for your models
Swift
14
star
9

SwiftEmptyState

Displaying Empty state of a page. (UIKit)
Swift
11
star
10

SocialLogins

Makes social logins easier for iOS
Swift
7
star
11

Swinjector

Simple dependency injection package inspired by get_it Flutter package
Swift
5
star
12

dart_kotlin_swift_comparison

This repo contains some kind of cheatsheet to quickly compare the basics of `Dart` `Kotlin` and `Swift`.
5
star
13

swifty_chat_data

Data package for the swifty_chat package.
Dart
4
star
14

iOSBaseProject

You're gonna start to a new project and fed up doing same initialization every time.
Swift
4
star
15

SettingsBundleDemo

Swift
3
star
16

CollapsibleCollectionView

Collapse CollectionView
Swift
2
star
17

efficient_indexed_stack

C++
2
star
18

bottom_sheet_routing

This repository demonstrates the usage of bottom sheet and inner routing. Represents the usage with core Navigator & auto_route
C++
1
star
19

EKNetworkModule

A generic, helper, util implementation of Network (Alamofire+SwiftyJSON)
Swift
1
star
20

iOS-Development-Resources

1
star
21

UI

Swift
1
star