All Projects → sanzaru → SimpleToast

sanzaru / SimpleToast

Licence: Apache-2.0 license
SimpleToast is a simple, lightweight, flexible and easy to use library to show toasts / popup notifications inside iOS or MacOS applications in SwiftUI. Because of the flexibility to show any content it is also possible to use the library for showing simple modals.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to SimpleToast

Anylayer
Android稳定高效的浮层创建管理框架
Stars: ✭ 745 (+468.7%)
Mutual labels:  popup, toast, notification
neodigm55
An eclectic low-code vanilla JavaScript UX micro-library for those that defiantly think for themselves.
Stars: ✭ 14 (-89.31%)
Mutual labels:  popup, toast, toast-notifications
JewelCase
This is the source code for JewelCase, a sample app demonstrating how to use SwiftUI and Firebase together. This slide deck discusses the architecture of the app: https://www.slideshare.net/peterfriese/building-swiftui-apps-with-firebase
Stars: ✭ 42 (-67.94%)
Mutual labels:  swiftui, swift5
QuoteKit
A framework to use the free APIs provided by https://quotable.io
Stars: ✭ 17 (-87.02%)
Mutual labels:  swiftui, swift5
MaterialToast
A fully and highly customizable material designed Toast for Android.
Stars: ✭ 31 (-76.34%)
Mutual labels:  toast, notification
iOSUtilitiesSource
IOS Utilities Library for Swift
Stars: ✭ 46 (-64.89%)
Mutual labels:  toast, swift5
prophetjs
Vanilla JS library to display toast messages.
Stars: ✭ 31 (-76.34%)
Mutual labels:  popup, notification
MaterialDesign-Toast
Custom android Toast with Material Design
Stars: ✭ 70 (-46.56%)
Mutual labels:  popup, toast
toaststrap
A simple, lightweight JavaScript library for showing Bootstrap 5 toast popups.
Stars: ✭ 16 (-87.79%)
Mutual labels:  toast, toast-notifications
LongWeekend-iOS
🏖📱 LongWeekend is iOS Application that supports checking long weekends when taking a vacation in Japan
Stars: ✭ 19 (-85.5%)
Mutual labels:  swiftui, swift5
stinsen
Coordinators in SwiftUI. Simple, powerful and elegant.
Stars: ✭ 563 (+329.77%)
Mutual labels:  swiftui, swift5
Harbour
Docker/Portainer management app for iOS
Stars: ✭ 210 (+60.31%)
Mutual labels:  swiftui, swift5
Windows11
💻 Windows 11 in SwiftUI.
Stars: ✭ 177 (+35.11%)
Mutual labels:  swiftui, swift5
vercel-toast
💬 Framework-agnostic vercel design's toast component (≈1KB Gzipped)
Stars: ✭ 67 (-48.85%)
Mutual labels:  popup, toast
mosha-vue-toastify
A light weight and fun Vue 3 toast or notification or snack bar or however you wanna call it library.
Stars: ✭ 185 (+41.22%)
Mutual labels:  toast, notification
SwiftUIDemo
A demo app showing you how to build a table view and navigation interface with SwiftUI
Stars: ✭ 26 (-80.15%)
Mutual labels:  swiftui, swift5
bs5-utils
A JavaScript utility package for Bootstrap 5 components.
Stars: ✭ 26 (-80.15%)
Mutual labels:  toast, toast-notifications
StoreHelper
Implementing and testing In-App Purchases with StoreKit2 and StoreHelper in Xcode 13, Swift 5.5, SwiftUI, iOS 15 and macOS 12.
Stars: ✭ 158 (+20.61%)
Mutual labels:  swiftui, swift5
Sweetalert2
A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies.
Stars: ✭ 13,929 (+10532.82%)
Mutual labels:  popup, toast
simple-notify
Pure javascript toast notifications.
Stars: ✭ 108 (-17.56%)
Mutual labels:  toast, toast-notifications

SimpleToast for SwiftUI

Build Status

SimpleToast is a simple, lightweight, flexible and easy to use library to show toasts / popup notifications inside iOS or MacOS applications in SwiftUI. Because of the flexibility to show any content it is also possible to use the library for showing simple modals.

You decide the content, the library takes care about the rest.

⚠️ Note: The current version is still in development. There can and will be breaking changes in version updates until version 1.0.

Features:

  • Custom toast content support: You can show whatever you want inside the toast.
  • Custom positioning: Place the toast where you want it to be.
  • Timeout functionality: You decide if and when the toast should disappear.
  • Callback functionality: Run code when the toast disappeared.
  • Multiple, customizable animations

🚨 Breaking changes:

0.6.0:

  • The options struct is modified and the parameters showBackdrop and backdropColor are replaced by a single optional Color definition backdrop. See Options for more information

Demo

Modifier Demo
.slide
.fade
.scale
.skew

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/sanzaru/SimpleToast.git", from: "0.0.1")
]

Usage:

There are different ways of attaching a toast notification to your view. The usage is very similar to well know SwiftUI view modifiers (e.g. alert or sheet). If you are familiar with these, using SimpleToast should be quiet easy.

Note: The toast always appears at the edges to the view it is attached to. Make sure the view has enough space to render the toast. Preferably the toast should be attached to the most outer view or the navigation view, if available.

Attach via boolean

You can attach the toast to a view and show it via binding to a boolean:

import SwiftUI
import SimpleToast

struct ToastTestView: View {
    @State var showToast: Bool = false

    private let toastOptions = SimpleToastOptions(
        hideAfter: 5
    )

    VStack(spacing: 20) {
        Button("Show toast") {
            withAnimation {
                showToast.toggle()
            }
        }
    }
    .simpleToast(isShowing: $showToast, options: toastOptions) {
        HStack {
            Image(systemName: "exclamationmark.triangle")
            Text("This is some simple toast message.")
        }
        .padding()
        .background(Color.red.opacity(0.8))
        .foregroundColor(Color.white)
        .cornerRadius(10)
    }
}

Attach via optional object

You can trigger the toast via an instance to an optional object, which conforms to the protocol Identifiable. If the value is not nil the toast will be shown.

The following example is based on the previous one and also shows the toast, but this time based on a value on an item.

import SwiftUI
import SimpleToast

struct ToastTestView: View {
    @State var showToast: DummyItem? = nil

    private struct DummyItem: Identifiable {
        var foo: String = "Bar"
    }

    private let toastOptions = SimpleToastOptions(
        hideAfter: 5
    )

    VStack(spacing: 20) {
        Button("Show toast") {
            withAnimation {
                // Toggle the item
                showToast = showToast == nil ? DummyItem() : nil
            }
        }
    }
    .simpleToast(item: $showToast, options: toastOptions) {
        HStack {
            Image(systemName: "exclamationmark.triangle")
            Text("This is some simple toast message.")
        }
        .padding()
        .background(Color.red.opacity(0.8))
        .foregroundColor(Color.white)
        .cornerRadius(10)
    }
}

 
ℹ️ This functionality is similar to the one of the SwiftUI sheet(item:onDismiss:content:)
 

Run code after dismissal

To run custom code after the toast disappeared you just have to pass a function to the onDismiss parameter:

import SwiftUI
import SimpleToast

struct ToastTestView: View {
    @State var showToast: Bool = false

    private let toastOptions = SimpleToastOptions(
        hideAfter: 5
    )

    VStack(spacing: 20) {
        Button("Show toast") {
            withAnimation {
                showToast.toggle()
            }
        }
    }
    .simpleToast(isShowing: $showToast, options: toastOptions, onDismiss: onToastComplete) {
        HStack {
            Image(systemName: "exclamationmark.triangle")
            Text("This is some simple toast message.")
        }
        .padding()
        .background(Color.red.opacity(0.8))
        .foregroundColor(Color.white)
        .cornerRadius(10)
    }

    // This will be called on toast completion
    func onToastComplete() -> Void {
        print("The toast did disappear")
    }
}

Options

The toast can be configured via an optional SimpleToastOptions object. You can simply pass an empty object to configure the toast with default values.

 
📌 All parameters inside the options are optional. If not set, the default value will be taken.
 

Option Type Description Default
alignment Alignment Defines the alignment of the toast. .top
hideAfter TimeInterval? Defines when the toast disappears. If nil is given the toast won't disappear. nil
backdrop Color? Defines the backdrop color nil
animation Animation Defines the animation type. .linear
modifierType ModifierType Defines the type of toast animation. Possible values(.slide, .fade) .fade
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].