• Stars
    star
    1,067
  • Rank 43,306 (Top 0.9 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 4 years ago
  • Updated 8 months ago

Reviews

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

Repository Details

A SwiftUI card view, made great for setup interactions.

SlideOverCard Project logo

Twitter: @joogps

A SwiftUI card design, similar to the one used by Apple in HomeKit, AirPods, Apple Card and AirTag setup, NFC scanning, Wi-Fi password sharing and more. It is specially great for setup interactions.

Clear Spaces demo QR code scanner demo Example preview demo

From left to right: SlideOverCard being used in Clear Spaces, a QR code scanner prompt (made with CodeScanner) and a demo of the project's Xcode preview

Installation

This repository is a Swift package, so all you gotta do is paste the repository link and include it in your project under File > Add packages. Then, just add import SlideOverCard to the files where this package will be referenced and you're good to go!

If your app runs on iOS 13, you might find a problem with keyboard responsiveness in your layout. That's caused by a SwiftUI limitation, unfortunately, since the ignoresSafeArea modifier was only introduced for the SwiftUI framework in the iOS 14 update.

Usage

You can add a card to your app in two different ways. The first one is by adding a .slideOverCard() modifier, which works similarly to a .sheet():

.slideOverCard(isPresented: $isPresented) {
  // Here goes your awesome content
}

Here, $isPresented is a boolean binding. This way you can dismiss the view anytime by setting it to false.

Customization

This view will have a transition, drag controls and a dismiss button set by default. You can override this by setting the dragEnabled, dragToDismiss and displayExitButton boolean parameters:

// This creates a card that can be dragged, but not dismissed by dragging
.slideOverCard(isPresented: $isPresented, options: [.disableDragToDismiss]) {
}

// This creates a card that can't be dragged or dismissed by dragging
.slideOverCard(isPresented: $isPresented, options: [.disableDrag, .disableDragToDismiss]) {
}

// This creates a card with no exit button
.slideOverCard(isPresented: $isPresented, options: [.hideDismissButton]) {
}

If you want to change styling attributes of the card, such as the corner size, the corner style, the inner and outer paddings, the dimming opacity and the shape fill style, such as a gradient, just specify a custom SOCStyle struct.

.slideOverCard(isPresented: $isPresented, style: SOCStyle(corners: 24.0,
                                                        continuous: false,
                                                        innerPadding: 16.0, outerPadding: 4.0,
                                                        dimmingOpacity: 0.1,
                                                        style: .black)) {
}

In case you want to execute code when the view is dismissed (either by the exit button or drag controls), you can also set an optional onDismiss closure parameter:

// This card will print some text when dismissed
.slideOverCard(isPresented: $isPresented, onDismiss: {
    print("I was dismissed.")
}) {
    // Here goes your amazing layout
}

Alternatively, you can add the card using a binding to an optional identifiable object. That will automatically animate the card between screen changes.

// This uses a binding to an optional object in a switch statement
.slideOverCard(item: $activeCard) { item in
    switch item {
        case .welcomeView:
            WelcomeView()
        case .loginView:
            LoginView()
        default:
            ..........
    }
}

You can even instantiate a card by your own by adding a SlideOverCard view to a ZStack.

// Using the standalone view
ZStack {
    Color.white
    
    SlideOverCard(isPresented: $isPresented) {
        // Here goes your super-duper cool screen
    }
}

Accessory views

This package also includes a few accessory views to enhance your card layout. The first one is the SOCActionButton() button style, which can be applied to any button to give it a default "primary action" look, based on the app's accent color. The SOCAlternativeButton() style will reproduce the same design, but with gray. And SOCEmptyButton() will create an all-text "last option" kind of button. You can use them like this:

Button("Do something", action: {
  ...
}).buttonStyle(SOCActionButton())

There's also the SOCDismissButton() view. This view will create the default dismiss button icon used for the card (based on https://github.com/joogps/ExitButton).

Manager

If you want to show a card as an overlay to all content in the screen, including the tab and navigation bars, you should use the SOCManager. The manager helps you display a card as a transparent view controller that covers the screen, therefore going past your SwiftUI content. To present this overlay, use:

SOCManager.present(isPresented: $isPresented) {
    // Here goes your design masterpiece
}

And to dismiss, just call:

SOCManager.dismiss(isPresented: $isPresented)

Example

The SwiftUI code for a demo view can be found here. It's an Xcode preview, and you can experience it right within the package, under Swift Package Dependencies, in your project.

More Repositories

1

Glur

A library for progressive blurs in SwiftUI.
Swift
1,325
star
2

IrregularGradient

Create animated irregular gradients in SwiftUI.
Swift
215
star
3

ExitButton

A native, colored and all-SwiftUI exit button icon.
Swift
45
star
4

Corona-Widget

A simple iOS and macOS widget for checking data about COVID-19.
Swift
25
star
5

Storees

Because everything has stories these days.
Swift
24
star
6

WWDC-2020

My submission for the WWDC20 Swift Student Challenge. (Accepted)
Swift
8
star
7

WWDC-2021

My submission for the WWDC21 Swift Student Challenge. (Accepted)
Swift
7
star
8

MQTT-Climate-Sync

A Home Assistant component for syncing MQTT IR transmitters/receivers with climate entities.
Python
7
star
9

WWDC21-Community-Hackathon

The 2 and ½ team's project for the WWDC Community Hackathon.
Swift
6
star
10

Processing-Sketchbook

Some of the sketches I made in the Processing IDE.
Processing
6
star
11

PeelKit

A manual implementation of a peel effect in SwiftUI using trigonometry.
Swift
6
star
12

joogps.com

My personal website and blog.
TypeScript
3
star
13

Vincent-Van-Proc

Trying to create an animated version of The Starry Night using Processing.
Processing
2
star
14

Wii-Menu

The Wii Menu, but in SwiftUI.
Swift
2
star
15

Under-Construction-Website

My website when it was... under construction.
CSS
1
star
16

StaticNoise

Quick static noise experimentations in SwiftUI with Canvas and TimelineView
Swift
1
star
17

Time-Tracker

A simple stopwatch and timer iOS app.
Swift
1
star
18

Metal-Experiments

A collection of my experiments with Metal.
Swift
1
star
19

Sphere

Little experiment with SwiftUI and Canvas
Swift
1
star
20

Basic-Text-Widget

A basic text widget with irregular gradients.
Swift
1
star
21

WWDC22-Community-Hackathon

Play hide and seek worldwide.
Swift
1
star
22

Metaballs

Recreating the Dynamic Island metaballs using Canvas in SwiftUI
Swift
1
star
23

SmartEdit

A proof-of concept of a smarted message editing system in SwiftUI.
Swift
1
star
24

muv

Repositório do nosso projeto de Programação III no semestre 2022.2
Java
1
star