Swiftpack.co - zaniluca/SwiftUISnackbar as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by zaniluca.
zaniluca/SwiftUISnackbar v1.0.0
A simple Snackbar view extension for your SwiftUI application
⭐️ 26
🕓 2 years ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/zaniluca/SwiftUISnackbar.git", from: "v1.0.0")

SwiftUISnackbar

A simple and ready to use Snackbar for your SwiftUI Application

SWIFTUI SPM

Screenshots

cover

Installation (SPM)

  1. Open Xcode
  2. Go to File > Swift Packages > Add package dependency
  3. Add it by pasting this link https://github.com/zaniluca/SwiftUISnackbar
  4. Select the Version you want to add, the Branch or even the single Commit

Docs

To add a Snackbar to your SwiftUI View you must first import the package

import SwiftUISnackbar

Then to use it just add to your view the custom View's method .snackbar

Text("Hello, World!")
   .snackbar(...)
}

View props

To set the values on the Snackbar you can either define them individually like so

import SwiftUI
import SwiftUISnackbar

struct YourView: View {

    var title: String = "Snackbar Title"
    var text: String = "Hi I'm the Snackbar's text"
    @State var show: Bool = true

    var body: some View {
        Text("Hello, World!")
            .snackbar(isShowing: $show, title: title, text: text, style: .custom(.blue))
    }
}

SnackbarStore

Or by using the Wrapper SnackbarStore that you can use to interact with the Snackbar

You can use it as a @StateObject or as an @EnvironmentObject so that you can use it by injecting it in the View Hierarchy making it accessible from any children view

Via @StateObject

struct MyView: View {

    @StateObject var store = SnackbarStore()

    var body: some View {
        Text("Hello, World!")
            .snackbar(isShowing: $store.show, title: store.title, text: store.text, style: store.style, actionText: store.actionText, action: store.action)
    }
}

Via @EnvironmentObject

Remember to inject it in the View Hierarchy like so

MyView()
    .environmentObject(SnackbarStore())

And the you can use it normally

struct MyView: View {

    @EnvironmentObject var store: SnackbarStore

    var body: some View {
        Text("Hello, World!")
            .snackbar(isShowing: $store.show, title: store.title, text: store.text, style: store.style, actionText: store.actionText, action: store.action)
    }
}

Result Screenshot

Schermata 2021-03-19 alle 12 04 50

Release History

  • 1.0.0 - 01/10/2021
    • First release 🎉
    • Support for markdown inside Text (only iOS15)

Pre-releases:

  • 0.0.2 - 18/03/2021
    • Dismiss on tap
    • Set dismiss timer
  • 0.0.1 - 15/03/2021
    • First relase

Meta

Luca Zani – @zaniluca_[email protected]

Distributed under the MIT license. See LICENSE for more information.

https://github.com/zaniluca

GitHub

link
Stars: 26
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v.1.0.0
2 years ago

First fully working release of SwiftUISnackbar (for iOS, iPadOS 14/15; Xcode 12/13)

  • Support for Markdown when using Text (Introduced with iOS15)
  • Use your app's accent color as the default color of the snackbar (along with 2 other default colors for warning and error)
  • Text automatically changes from white to black to accomodate the snackbar background for better contrast
  • Custom actions buttons with custom actions on the right of the snackbar for user interactions
  • Dismiss on tap feature
  • Customize the dismiss after feature

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics