Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A simple Snackbar view extension for your SwiftUI application

License

NotificationsYou must be signed in to change notification settings

zaniluca/SwiftUISnackbar

Repository files navigation

A simple and ready to use Snackbar for your SwiftUI Application

SWIFTUISPM

Screenshots

cover

Installation (SPM)

  1. Open Xcode
  2. Go toFile > Swift Packages > Add package dependency
  3. Add it by pasting this linkhttps://github.com/zaniluca/SwiftUISnackbar
  4. Select theVersion you want to add, theBranch or even the singleCommit

Docs

To add aSnackbar to yourSwiftUI 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 theSnackbar you can either define them individually like so

import SwiftUIimport SwiftUISnackbarstructYourView:View{vartitle:String="Snackbar Title"vartext:String="Hi I'm the Snackbar's text"@Statevarshow:Bool=truevarbody:someView{Text("Hello, World!").snackbar(isShowing: $show, title: title, text: text, style:.custom(.blue))}}

SnackbarStore

Or by using the WrapperSnackbarStore that you can use to interact with theSnackbar

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

Via@StateObject

structMyView:View{@StateObjectvarstore=SnackbarStore()varbody:someView{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 theView Hierarchy like so

MyView().environmentObject(SnackbarStore())

And the you can use it normally

structMyView:View{@EnvironmentObjectvarstore:SnackbarStorevarbody:someView{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_zani.luca@icloud.com

Distributed under the MIT license. SeeLICENSE for more information.

https://github.com/zaniluca


[8]ページ先頭

©2009-2025 Movatter.jp