DropView icon indicating copy to clipboard operation
DropView copied to clipboard

A SwiftUI library to display Apple Pencil and Pasteboard-like alerts on iOS.

Notification

DropView is a SwiftUI-based library to display alerts inspired by the Apple Pencil and pasteboard stock ones.


What are some features I can expect from this library?

  • [x] Dark mode
  • [x] Interactive dismissal
  • [x] Dynamic font sizing
  • [x] Accessibility support
  • [x] Custom positioning (.top, .bottom and .center)

Status

Swift iOS macOS tvOS watchOS
checks GitHub release (latest by date)

You can find all changelogs directly under every release.

What's next?

Milestones and issues are the best way to keep updated with active developement.

Feel free to contribute by sending a pull request. Just remember to refer to our guidelines and Code of Conduct beforehand.

Installation

Swift Package Manager (Xcode 11 and above)

  1. Select File/Swift Packages/Add Package Dependency… from the menu.
  2. Paste https://github.com/sbertix/DropView.git.
  3. Follow the steps.
  4. Add DropView.

Why not CocoaPods, or Carthage, or ~blank~?

Supporting multiple dependency managers makes maintaining a library exponentially more complicated and time consuming.
Furthermore, with the integration of the Swift Package Manager in Xcode 11 and greater, we expect the need for alternative solutions to fade quickly.

Usage

DropView allows you to present alerts just like sheets and fullScreenCovers.

Just call .drop($drop) on any View.

Example

import SwiftUI

import DropView

struct YourView: View {
    /// An optional `Drop` binding.
    @State var drop: Drop?
    /// The current posiiton.
    @State var alignmentValue: Int = 0
    /// Autohides after a given amount of seconds.
    @State var seconds: TimeInterval = 2

    /// The vertical alignment.
    private var alignment: VerticalAlignment {
        switch alignmentValue {
        case 1: return .center
        case 2: return .bottom
        default: return .top
        }
    }

    /// The underlying view.
    var body: some View {
        VStack(spacing: 8) {
            Slider(value: $seconds, in: 2...10)
                .padding(.horizontal)
            Picker("Alignment", selection: $alignmentValue) {
                Text("Top").tag(0)
                Text("Center").tag(1)
                Text("Bottom").tag(2)
            }
            Button(action: {
                drop = .init(title: "DropView",
                             subtitle: "github.com/sbertix/DropView",
                             icon: Image(systemName: "hand.wave.fill").resizable(),
                             action: Image(systemName: "star.circle.fill").resizable())
            }) {
                Text("Present").bold()
            }
            Button(action: {
                drop = nil
            }) {
                Text("Hide").foregroundColor(.red)
            }
        }
        .drop($drop, hidingAfter: seconds, alignment: alignment)
    }
}

Special thanks

Massive thanks to anyone contributing to omaralbeik/Drops for the inspiration.