• Stars
    star
    1,016
  • Rank 45,279 (Top 0.9 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 1 year ago
  • Updated 5 months ago

Reviews

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

Repository Details

Add customizable swipe actions to any view.

SwipeActions

Add customizable swipe actions to any view.

  • Enable swipe actions on any view, not just Lists.
  • Customize literally everything — corner radius, color, etc...
  • Supports drag-to-delete and advanced gesture handling.
  • Fine-tune animations and styling to your taste.
  • Programmatically show/hide swipe actions.
  • Automatically close when interacting with other views.
  • Made with 100% SwiftUI. Supports iOS 14+.
  • Lightweight, no dependencies. One file.
General Basics Customization
Styles Animations Advanced

Installation

SwipeActions is available via the Swift Package Manager. Alternatively, because all of SwipeActions is contained within a single file, drag SwipeActions.swift into your project. Requires iOS 14+.

https://github.com/aheze/SwipeActions

Usage

import SwiftUI
import SwipeActions

struct ContentView: View {
    var body: some View {
        SwipeView {
            Text("Hello")
                .frame(maxWidth: .infinity)
                .padding(.vertical, 32)
                .background(Color.blue.opacity(0.1))
                .cornerRadius(32)
        } trailingActions: { _ in
            SwipeAction("World") {
                print("Tapped!")
            }
        }
        .padding()
    }
}

The result, 'World' displayed on the right.

Examples

Check out the example app for all examples and advanced usage!

2 screenshots of the example app

Customization

SwipeActions supports over 20 modifiers for customization. To use them, simply attach the modifier to SwipeAction/SwipeView.

SwipeView {
    Text("Hello")
} leadingActions: { _ in
} trailingActions: { _ in
    SwipeAction("World") {
        print("Tapped!")
    }
    .allowSwipeToTrigger() /// Modifiers for `SwipeAction` go here.
}
.swipeActionsStyle(.cascade) /// Modifiers for `SwipeView` go here.
// MARK: - Available modifiers for `SwipeAction` (the side views)

/**
 Apply this to the edge action to enable drag-to-trigger.

     SwipeView {
         Text("Swipe")
     } leadingActions: { _ in
         SwipeAction("1") {}
             .allowSwipeToTrigger()

         SwipeAction("2") {}
     } trailingActions: { _ in
         SwipeAction("3") {}

         SwipeAction("4") {}
             .allowSwipeToTrigger()
     }
 */
func allowSwipeToTrigger(_ value: Bool = true)

/// Constrain the action's content size (helpful for text).
func swipeActionLabelFixedSize(_ value: Bool = true) 

/// Additional horizontal padding.
func swipeActionLabelHorizontalPadding(_ value: Double = 16)

/// The opacity of the swipe actions, determined by `actionsVisibleStartPoint` and `actionsVisibleEndPoint`.
func swipeActionChangeLabelVisibilityOnly(_ value: Bool) 
// MARK: - Available modifiers for `SwipeView` (the main view)

/// The minimum distance needed to drag to start the gesture. Should be more than 0 for best compatibility with other gestures/buttons.
func swipeMinimumDistance(_ value: Double) 

/// The style to use (`mask`, `equalWidths`, or `cascade`).
func swipeActionsStyle(_ value: SwipeActionStyle) 

/// The corner radius that encompasses all actions.
func swipeActionsMaskCornerRadius(_ value: Double) 

/// At what point the actions start becoming visible.
func swipeActionsVisibleStartPoint(_ value: Double) 

/// At what point the actions become fully visible.
func swipeActionsVisibleEndPoint(_ value: Double)

/// The corner radius for each action.
func swipeActionCornerRadius(_ value: Double) 

/// The width for each action.
func swipeActionWidth(_ value: Double) 

/// Spacing between actions and the label view.
func swipeSpacing(_ value: Double) 

/// The point where the user must drag to expand actions.
func swipeReadyToExpandPadding(_ value: Double) 

/// The point where the user must drag to enter the `triggering` state.
func swipeReadyToTriggerPadding(_ value: Double) 

/// Ensure that the user must drag a significant amount to trigger the edge action, even if the actions' total width is small.
func swipeMinimumPointToTrigger(_ value: Double) 

/// Applies if `swipeToTriggerLeadingEdge/swipeToTriggerTrailingEdge` is true.
func swipeEnableTriggerHaptics(_ value: Bool) 

/// Applies if `swipeToTriggerLeadingEdge/swipeToTriggerTrailingEdge` is false, or when there's no actions on one side.
func swipeStretchRubberBandingPower(_ value: Double)

/// If true, you can change from the leading to the trailing actions in one single swipe.
func swipeAllowSingleSwipeAcross(_ value: Bool) 

/// The animation used for adjusting the content's view when it's triggered.
func swipeActionContentTriggerAnimation(_ value: Animation)

/// Values for controlling the close animation.
func swipeOffsetCloseAnimation(stiffness: Double, damping: Double)

/// Values for controlling the expand animation.
func swipeOffsetExpandAnimation(stiffness: Double, damping: Double)

/// Values for controlling the trigger animation.
func swipeOffsetTriggerAnimation(stiffness: Double, damping: Double)

Example usage of these modifiers is available in the example app.

Notes

  • To automatically close swipe views when another one is swiped (accordion style), use SwipeViewGroup.
SwipeViewGroup {
    SwipeView {} /// Only one of the actions will be shown.
    SwipeView {}
    SwipeView {}
}
  • To programmatically show/hide actions, use the context parameter.
import Combine
import SwiftUI
import SwipeActions

struct ProgrammaticSwipeView: View {
    @State var open = PassthroughSubject<Void, Never>()

    var body: some View {
        SwipeView {
            Button {
                open.send() /// Fire the `PassthroughSubject`.
            } label: {
                Text("Tap to Open")
                    .frame(maxWidth: .infinity)
                    .padding(.vertical, 32)
                    .background(Color.blue.opacity(0.1))
                    .cornerRadius(32)
            }
        } trailingActions: { context in
            SwipeAction("Tap to Close") {
                context.state.wrappedValue = .closed
            }
            .onReceive(open) { _ in /// Receive the `PassthroughSubject`.
                context.state.wrappedValue = .expanded
            }
        }
    }
}
  • To enable swiping on transparent areas, add .contentShape(Rectangle()).
SwipeView {
    Text("Lots of empty space here.")
        .frame(maxWidth: .infinity)
        .padding(.vertical, 32)
        .contentShape(Rectangle()) /// Enable swiping on the empty space.
} trailingActions: { _ in
    SwipeAction("Hello!") { }
}
  • Everything in the example app is swipeable — even the gray-capsule headers!

The 'Styles' header swiped to the left and the 'Open' action shown on the right.

Community

Author Contributing Need Help?
SwipeActions is made by aheze. All contributions are welcome. Just fork the repo, then make a pull request. Open an issue or join the Discord server. You can also ping me on Twitter.

License

MIT License

Copyright (c) 2023 A. Zheng

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

SwipeActions.mp4

More Repositories

1

Popovers

A library to present popovers. Simple, modern, and highly customizable. Not boring!
Swift
1,944
star
2

Setting

Compose beautiful preference panels.
Swift
1,429
star
3

OpenFind

An app to find text in real life.
Swift
983
star
4

Prism

A lightweight 3D renderer for SwiftUI.
Swift
923
star
5

Multiliner

An Xcode source extension to expand lengthy lines.
Swift
829
star
6

Squirrel

Enable scrolling in the Xcode Simulator!
Swift
620
star
7

VariableBlurView

A one-file, App Store upload-safe version of Janum Trivedi's variable blur effect.
Swift
372
star
8

SwiftUICraft

Minecraft but made with SwiftUI.
Swift
303
star
9

RealityKitLaunchScreen

A launch screen made with SwiftUI and RealityKit. Used in the Find app.
Swift
239
star
10

SplitSheet

A lightweight, fully interactive split-screen sheet.
Swift
188
star
11

SupportDocs

Generate help centers for your iOS apps. Hosted by GitHub and always up-to-date.
Swift
161
star
12

ProgressGif

Add progress bars to gifs!
Swift
105
star
13

AppClipQuickStart

Make an app clip.
Swift
50
star
14

implicit-curves

Graph implicit curves in Swift
Swift
30
star
15

AccessibleReality

[Accepted] My WWDC21 Swift Student Challenge submission.
Swift
26
star
16

AlternativeARKit

A custom alternative to ARKit
Swift
22
star
17

PathMapper

Find the shortest distance between 2 points on a map!
Swift
19
star
18

StitchCounter

An app to count stitches in crochet patterns. Multiplatform.
Swift
19
star
19

MarkdownTextEditor

Markdown editor in SwiftUI 3
Swift
18
star
20

CustomSCNGeometry

How to make a custom SCNGeometry
Swift
17
star
21

ClassX

Swift
15
star
22

Missions

Missions for Midnight
Swift
13
star
23

QuickOCR

Drag-and-drop to find text. A work in progress.
Swift
12
star
24

ConnectFour

Literally just Connect 4 in SwiftUI
Swift
10
star
25

AnimateBetweenCollectionLayouts

Animate from "horizontal film strip" to "Vertical/expanded stack"
Swift
10
star
26

aheze

8
star
27

SixDegrees

Swift
8
star
28

MetalGradient

Swift
8
star
29

Projector

Forget the Simulator — swap your aspect ratio instead!
Swift
7
star
30

Buildings

Building block app made with SwiftUI
Swift
6
star
31

CalHacks

Swift
5
star
32

AcuteCalculator

Support files for Acute Calculator
5
star
33

ARKitCube

Demo app to render a cube with ARKit and SceneKit.
Swift
5
star
34

BarcodeScanner

Swift
3
star
35

ProjectorExample

Test out your app on different device sizes
Swift
3
star
36

VidQuery

CodeDay - Most Likely to Use winner
Swift
3
star
37

OpenFind-SupportDocs

Help center and other resources for Find app
Swift
3
star
38

TableViewReverseAnimation

Swift
3
star
39

PhotoLoadingTest

Swift
3
star
40

FastAssets

Testing to get photo assets quickly
Swift
2
star
41

SampleApp

A sample app for all purposes. Tap the squircle to spin it.
Swift
2
star
42

Find-Lists

Website for lists sharing in Find (getfind.app)
JavaScript
2
star
43

MyAppClipWebsite

Swift
2
star
44

StatusBarHide

Swift
2
star
45

Findbot

A Python bot. Check it out at https://getfind.app/discord
Python
2
star
46

DeveloperAssets

Just some images. Feel free to store yours here if you want.
Rich Text Format
2
star
47

FindHelp

Short tutorials/help docs for Find app. This is outdated, but I haven't gotten around to updating it
HTML
2
star
48

MyHelpCenter

Swift
2
star
49

FindAppSupport

Useful files that may be used in Find app
HTML
2
star
50

CardScanner

Swift
2
star
51

tdee-calculator

TypeScript
2
star
52

PlaygroundSync

Git for swift playgrounds, under development
Swift
1
star
53

Licenses

For hosting the licenses I use
1
star
54

schedules-ios

The iOS companion for Schedules
Swift
1
star
55

Assets

Just some file storage.
1
star
56

ReadmeTables

Tables don't need to be boring
1
star
57

LearningWebDev

Just learning web development, and following some tutorials! Testing on GitHub Pages.
HTML
1
star
58

SwiftUIImageTransitionTest

Swift
1
star
59

PhotoLoading

Memory issue
Swift
1
star
60

SwiftUISearchBar

Swift
1
star
61

SwiftUICamera

Swift
1
star
62

Find-Assets

Screenshots and other stuff for Find (getfind.app)
1
star
63

Medium

Support files for my Medium articles, but larger projects may have their own repository.
HTML
1
star
64

Find-Issues

Bug tracker for Find
1
star
65

TwoSetTableView

Swift
1
star
66

TargetContentOffsetTest

Demo repo for my question "UICollectionViewFlowLayout `targetContentOffset` - how to keep cells centered after orientation change?"
Swift
1
star
67

Find-Website-Old

Official website of Find app
CSS
1
star
68

TextFieldConstraintDemo

Demo repo for https://stackoverflow.com/questions/65928019/how-to-reduce-width-between-ui-components-in-my-case-uilabel-and-uitextfield
Swift
1
star