All Projects → quanshousio → Toastui

quanshousio / Toastui

Licence: mit
A simple way to show toast in SwiftUI.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Toastui

neodigm55
An eclectic low-code vanilla JavaScript UX micro-library for those that defiantly think for themselves.
Stars: ✭ 14 (-89.86%)
Mutual labels:  popup, toast
Popupwindow
PopupWindow is a simple Popup using another UIWindow in Swift
Stars: ✭ 401 (+190.58%)
Mutual labels:  toast, popup
BalloonPopup
Forget Android Toast! BalloonPopup displays a round or squared popup and attaches it to a View, like a callout. Uses the Builder pattern for maximum ease. The popup can automatically hide and can persist when the value is updated.
Stars: ✭ 32 (-76.81%)
Mutual labels:  popup, toast
SKChoosePopView
SKChoosePopView是一个HUD风格的可定制化选项弹窗的快速解决方案,集成了上、下、左、右、中5个进场方向的6种动画效果,如果不能满足你对酷炫效果的需要,SKChoosePopView同样支持自定义动画,以及选择记录、动画的开闭、点击特效、行列数量控制等
Stars: ✭ 70 (-49.28%)
Mutual labels:  popup, hud
Sweet Alert
A BEAUTIFUL, RESPONSIVE, CUSTOMIZABLE, ACCESSIBLE (WAI-ARIA) REPLACEMENT FOR JAVASCRIPT'S POPUP BOXES FOR LARAVEL
Stars: ✭ 696 (+404.35%)
Mutual labels:  toast, popup
MaterialDesign-Toast
Custom android Toast with Material Design
Stars: ✭ 70 (-49.28%)
Mutual labels:  popup, toast
Ftindicator
A light wight UI package contains local notification, progress HUD, toast, with blur effect, elegant API and themes support.
Stars: ✭ 292 (+111.59%)
Mutual labels:  toast, hud
Alerttoast
Create Apple-like alerts & toasts using SwiftUI
Stars: ✭ 151 (+9.42%)
Mutual labels:  toast, popup
Popupview
Toasts and popups library written with SwiftUI
Stars: ✭ 581 (+321.01%)
Mutual labels:  toast, popup
Xtoast
Android 悬浮窗框架,好用不解释
Stars: ✭ 493 (+257.25%)
Mutual labels:  toast, popup
vercel-toast
💬 Framework-agnostic vercel design's toast component (≈1KB Gzipped)
Stars: ✭ 67 (-51.45%)
Mutual labels:  popup, toast
Jhud
A full screen of the HUD when loading the data (Objective-C).
Stars: ✭ 1,003 (+626.81%)
Mutual labels:  toast, hud
Sweetalert2
A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies.
Stars: ✭ 13,929 (+9993.48%)
Mutual labels:  toast, popup
SimpleToast
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.
Stars: ✭ 131 (-5.07%)
Mutual labels:  popup, toast
Tfpopup
🚀🚀🚀TFPopup不生产弹框,它只是弹框的弹出工🚀🚀🚀默认支持多种动画方式一行调用,支持完全自定义动画.
Stars: ✭ 182 (+31.88%)
Mutual labels:  toast, popup
Razor.SweetAlert2
A Razor class library for interacting with SweetAlert2
Stars: ✭ 98 (-28.99%)
Mutual labels:  popup, toast
Aiforms.dialogs
AiForms.Dialogs for Xamarin.Forms
Stars: ✭ 143 (+3.62%)
Mutual labels:  toast, popup
Easyshowview
一款非常简单的展示工具。提示框,加载框,空白页提示,alert弹出框。一行代码搞定所有操作。
Stars: ✭ 447 (+223.91%)
Mutual labels:  toast, hud
Anylayer
Android稳定高效的浮层创建管理框架
Stars: ✭ 745 (+439.86%)
Mutual labels:  toast, popup
Jjhud
JJHUD is an displays a translucent HUD with an indicator and/or labels .
Stars: ✭ 94 (-31.88%)
Mutual labels:  toast, hud

ToastUI logo

A simple way to show toast in SwiftUI

DocumentationExampleChange Log

Swift Package Manager CocoaPods Platform License

demo

Overview

ToastUI provides you a simple way to present toast, head-up display (HUD), custom alert, or any SwiftUI views on top of everything in SwiftUI.

Getting started

Here is an example to present an indefinite progress indicator HUD and dismiss it after 2 seconds.

struct ContentView: View {
  @State private var presentingToast: Bool = false

  var body: some View {
    Button {
      presentingToast = true
    } label: {
      Text("Tap me")
        .bold()
        .foregroundColor(.white)
        .padding()
        .background(Color.accentColor)
        .cornerRadius(8.0)
    }
    .toast(isPresented: $presentingToast, dismissAfter: 2.0) {
      print("Toast dismissed")
    } content: {
      ToastView("Loading...")
        .toastViewStyle(IndefiniteProgressToastViewStyle())
    }
  }
}

You can also present custom alerts or any SwiftUI views of your choice.

struct ContentView: View {
  @State private var presentingToast: Bool = false

  var body: some View {
    Button {
      presentingToast = true
    } label: {
      Text("Tap me")
        .bold()
        .foregroundColor(.white)
        .padding()
        .background(Color.accentColor)
        .cornerRadius(8.0)
    }
    .toast(isPresented: $presentingToast) {
      ToastView {
        VStack {
          Text("Hello from ToastUI")
            .padding(.bottom)
            .multilineTextAlignment(.center)

          Button {
            presentingToast = false
          } label: {
            Text("OK")
              .bold()
              .foregroundColor(.white)
              .padding(.horizontal)
              .padding(.vertical, 12.0)
              .background(Color.accentColor)
              .cornerRadius(8.0)
          }
        }
      }
    }
  }
}

Have a look at the ToastUISample project for more examples and also check out the Documentation below.

Requirements

  • iOS 14.0+ | tvOS 14.0+ | macOS 11.0+
  • Xcode 12.0+ | Swift 5.3+

Installation

Swift Package Manager

ToastUI is available through Swift Package Manager.

For app integration, add ToastUI to an existing Xcode project as a package dependency:

  1. From the File menu, select Swift Packages > Add Package Dependency...
  2. Enter https://github.com/quanshousio/ToastUI into the package repository URL text field.
  3. Xcode should choose updates package up to the next version option by default.

For package integration, add the following line to the dependencies parameter in your Package.swift .

dependencies: [
  .package(url: "https://github.com/quanshousio/ToastUI.git", from: "2.0.0")
]

CocoaPods

ToastUI is available through CocoaPods. To install it, add the following line to your Podfile :

pod 'ToastUI'

Documentation

For more detailed documentation, please see here.

Presenting

ToastUI supports presenting any SwiftUI views from anywhere. You just need to add toast() view modifier and provide your views, much like using alert() or sheet() .

.toast(isPresented: $presentingToast) {
  // your SwiftUI views here
}

There are two types of toast() view modifier. For more usage information, check out the examples.

  • toast(isPresented:dismissAfter:onDismiss:content:) – presents a toast when the given boolean binding is true.
  • toast(item:dismissAfter:onDismiss:content:) – presents a toast using the given item as a data source for the toast's content.

ToastView

ToastUI comes with ToastView , which visually represented as a rounded rectangle shape that contains your provided views and has a default thin blurred background.

.toast(isPresented: $presentingToast) {
  ToastView("Hello from ToastUI")
}

Layout of ToastView is demonstrated in this figure below.

+-----------------------------+
|                             |
|  <Background>               |
|                             |
|        +-----------+        |
|        |           |        |
|        | <Content> |        |
|        |           |        |
|        |           |        |
|        |  <Label>  |        |
|        +-----------+        |
|                             |
|                             |
|                             |
+-----------------------------+

ToastView(<Label>) {
  <Content>
} background: {
  <Background>
}

ToastView with custom content views and custom background views.

.toast(isPresented: $presentingToast) {
  ToastView("Saved!") {
    // custom content views
    Image(systemName: "arrow.down.doc.fill")
      .font(.system(size: 48))
      .foregroundColor(.green)
      .padding()
  } background: {
    // custom background views
    Color.green.opacity(0.1)
  }
}

ToastView using built-in styles and without background.

.toast(isPresented: $presentingToast) {
  ToastView("Loading...") {
    // EmptyView()
  } background: {
    // EmptyView()
  }
  .toastViewStyle(IndefiniteProgressToastViewStyle())
}

Styling

ToastUI supports seven different ToastViewStyle s out-of-the-box. You have to use ToastView and set the style accordingly by using toastViewStyle(_:) modifier. All styles have native support for dynamic type for accessbility.

  • DefaultProgressToastViewStyle() – shows an empty toast if user does not provide anything. ToastView uses this style by default.
  • IndefiniteProgressToastViewStyle() – shows an indefinite circular progress indicator.
  • DefiniteProgressToastViewStyle(value:total:) – shows a definite circular progress indicator from 0 to 100%.
  • SuccessToastViewStyle() – shows a success toast.
  • ErrorToastViewStyle() – shows an error toast.
  • WarningToastViewStyle() - shows a warning toast.
  • InfoToastViewStyle() – shows an information toast.

ToastUI includes a UI/NSVisualEffectView wrapper through cocoaBlur() view modifier, which is more flexible than existing blur(radius:opaque:) in SwiftUI.

  • cocoaBlur(blurStyle:vibrancyStyle:blurIntensity:) - for iOS.
  • cocoaBlur(blurStyle:blurIntensity:) - for tvOS.
  • cocoaBlur(material:blendingMode:state:) - for macOS.

Contributing

All issue reports, feature requests, pull requests and GitHub stars are welcomed and much appreciated.

Author

Quan Tran (@quanshousio)

Acknowledgements

  • Fruta - UI/NSVisualEffectView wrapper for SwiftUI by Apple.
  • Label - an informative article about SwiftUI Label and style erasers by Five Stars.
  • SVProgressHUD - original design of the circular progress HUD by Sam Vermette and Tobias Tiemerding.
  • SwiftUI Custom Styling - an informative article about SwiftUI custom styling by The SwiftUI Lab.

License

ToastUI is available under the MIT license. See the LICENSE file for more info.

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].