Skip to content

OozoraHaruto/SwiftToast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftToast

A Toast View for SwiftUI

Disclaimer: Most of the codes aren't written by me I found it on a medium post as I was reseaching how to write a toast for Swift.

Overview

In addition to the toast, I have added an ObservableObject which can will help to coordinate all the toast. You can call showToast to add it to the list. I would advice you to add it to your root view controller

Installation

Swift Package Manager

Got to File | Swift Packages | Add Package Dependency... and paste the github link. Choose main branch.

Screenshots

Type Dark Light
boot boot_dark boot_light
fancy fancy_dark fancy_light
top middle bottom
position pos_top pos_mid pos_bot

Usage

Import

import SwiftToast

Root View

import SwiftToast

struct MenuView: View {
  @ObservedObject var toastCoordinator = ToastCoordinator()
  
  var body: some View {
    VStack {
      Text("Hello World")
    }
    .modifier(ToastModifier())
    .environmentObject(toastCoordinator)
  }
}

Showing Toasts

import SwiftToast

struct MenuViewTest: View {
  @EnvironmentObject var toastCoordinator: ToastCoordinator
  
  var body: some View {
    VStack {
      Button("no icon, no button") {
        toastCoordinator.showToast(Toast(type: .boot,
                                         title: "test",
                                         message: "test",
                                         duration: 1))
      }
    }
  }
}

License

SwiftToast is distributed under the MIT license. See LICENSE for details.

About

A Toast View for SwiftUI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages