Giter Club home page Giter Club logo

toastui's Introduction

ToastUI logo

A simple way to show toast in SwiftUI

Getting StartedDocumentationChange Log

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

For details on usage and documentation, please see here.

Contributing

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

Author

Quan Tran (@quanshousio)

Acknowledgements

  • Label – informative article about Label and style erasers in SwiftUI by Five Stars.
  • SVProgressHUD – original design of the circular progress HUD by Sam Vermette and Tobias Tiemerding.
  • SwiftUI Custom Styling – 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.

toastui's People

Contributors

lucascarioca avatar quanshousio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

toastui's Issues

Compiler Warning since ios15

Hi,

I get a warning since i updated to iOS 15:
.../ToastUI/ToastViewEnvironmentKey.swift:13:16:
Expected member name or constructor call after type name

I use ToastUI version 2.0.0

Beste regards

ios15toastui1

ToastUI Warning attempt to dismiss from view controller (thousands) on 1.3.x

Pre-requisites:

  • Yes, I looked through both open and closed issues looking for what I needed.
  • No, I did not find what I was looking for.

Expected Behavior

With ToastUI 1.3.2 whenever my toasts appear, I get thousands of errors that look like this:

2021-02-25 13:48:22.726 iosApp[93595:9719510] Warning: Attempt to dismiss from view controller <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentGS1_GS1_GS1_GS1_V6iosApp8MainViewGVS_30_EnvironmentKeyWritingModifierGSqCS2_8AppState___GS4_GSqCS2_4User___GS4_GSqCS2_7Checkin___GS4_GSqCS2_4Team___GS4_GSqCS2_5Score____: 0x7faf04419390> while a presentation or dismiss is in progress!

I don't know if this is something I'm doing wrong with how I'm using ToastUI or a bug in ToastUI 1.x, BUT if I upgrade to ToastUI 2.0.0, the issue goes away with my code remaining the same, so I suspect this is a bug in 1.x.

However, I see that 2.0.0 no longer supports ios 13. We don't want to raise the minimum compat level for our app.

Current Behavior

Thousands of Warning messages when attempting to use ToastUI 1.3.0.

Possible Solution

We could have upgraded to 2.0.0 which fixes the issue, but can't right away since the minimum iOS version has been bumped.

Your Environment

  • Swift Version: 5
  • Xcode Version: 12
  • Operating System Version: 11.2.1
  • Device or Simulator: iPhone 11 13.5

Improve compile time

Currently, I can see it takes >2 seconds to get compiled. Is there any way to improve?

image

Attempt to present toast whose view is not in the window hierarchy

Pre-requisites:

  • [*] Yes, I looked through both open and closed issues looking for what I needed.
  • [*] No, I did not find what I was looking for.

When attempting to trigger a toast to appear programmatically, I get the following error:

[Presentation] Attempt to present <_TtGC7ToastUI26ToastViewHostingControllerGV7SwiftUI15ModifiedContentGVS_9ToastViewVS1_9EmptyViewVS1_4TextS4__GVS1_30_EnvironmentKeyWritingModifierVS_17AnyToastViewStyle___: 0x10193f040> on <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x104f11380> (from <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x104f11380>) whose view is not in the window hierarchy.

The relevant section of my code looks like this:

@State private var presentingToast = false
@State private var uploadProgress = 0.0
var body: some View {
    VStack {
        Button(action: {
            print("Show toast")
        }, label: {
            Text("")
        })
        .toast(isPresented: $presentingToast) {
            ToastView("Uploading...")
                .toastViewStyle(DefiniteProgressToastViewStyle(value: $uploadProgress))
        }
        .hidden()
   

When I set presentingToast to true, it gives me the aforementioned error. I've also tried removing the hidden modifier and putting in some words in the Text, but that doesn't make a difference.

Your Environment

  • Swift Version: 5
  • Xcode Version: 12.3
  • Operating System Version: macOS Big Sur 11.1
  • Device or Simulator: iPhone 8 Plus

A ToastUI triggering while a SwiftUI Menu is active can sometimes later cause sheets to fail to open.

Pre-requisites:

  • Yes, I looked through both open and closed issues looking for what I needed.
  • No, I did not find what I was looking for.

Expected Behavior

Current Behavior

Possible Solution

A workaround is to use .contextMenu instead of Menu.

Steps to Reproduce

With this activated:
Menu {
Button() {
UIPasteboard.general.string = selectedText
} label: {
Image(systemName: "doc.on.doc")
Text("Copy")
}
}
label:
{
Image(systemName: "ellipsis")
.imageScale(.large)
.padding()
}

And concurrently triggering a Toast:
.toast(isPresented: $isLocked) {
LockScreen()
}

And then later calling sheet(), for instance:
.sheet(isPresented: $showQRCode) {
QRCode(showQRCode: self.$showQRCode)
}
Will generate the following error:

2021-07-09 23:21:11.290959+0200 AppName[10762:4800555] [Presentation] Attempt to present <TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView: 0x113507a20> on <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x111d08800> (from <TtGC7SwiftUI19UIHostingControllerVS_14_ViewList_View: 0x111d2ca80>) which is already presenting <_UIContextMenuActionsOnlyViewController: 0x1137095f0>.

Context

I am using Toast to present a LockScreen that triggers when moving an app to the background.
It works great with all other kinds of dialogs, like sheets or contextMenus, but using Menu causes the above issue.

I am using XCode 12.5.1
iOS 14.6,
iPhone 12 Pro Max

Hide toast when system alert occurs

Pre-requisites:

  • No, I did not find what I was looking for

Feature Suggestion

If a toast is currently shown and a system alert appears (e.g. contacts permission request), add a possibility to hide the toast so they do not overlap.

Context

  1. Start a new iOS Project with Lifecycle Storyboard
  2. In the ViewController.swift replace the code with the code below.
  3. Add NSContactsUsageDescription key in info.plist.
  4. Build the project
  5. Tap "show toast" button. After 5 seconds from start, a system alert will appear above the toast so that they are overlapping.

Is there a way to automatically hide toast when a system alert appears ? This is obviously just a minimum working example, at the end this can be any system alert. Another thing is, sometimes alerts will come from external libs making it even harder to manage.

import UIKit
import SwiftUI
import Contacts
import ToastUI

struct ContentView: View {
    @State var showToast = false
    
    var body: some View {
        VStack {
            Button {
                showToast = true
            } label: {
                Text("show toast")
            }
            .toast(isPresented: $showToast) {
                ZStack {
                    Color.black
                        .frame(width: 300, height: 300)
                    ProgressView()
                        .tint(.white)
                        .scaleEffect(4)
                   
                }
            }
        }
    }
}

class ViewController: UIViewController {
    var contactStore = CNContactStore()
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
//
        let hostingController = UIHostingController(rootView: ContentView())
        DispatchQueue.main.asyncAfter(deadline: .now() + 5) { [self] in
           
            requestForAccess { val in
                print(val.description)
            }
        }

        self.navigationController?.pushViewController(hostingController, animated: false)
    }
                                   
    fileprivate func requestForAccess(completionHandler: @escaping (_ accessGranted: Bool) -> Void) {
            let authorizationStatus = CNContactStore.authorizationStatus(for: CNEntityType.contacts)
            
            switch authorizationStatus {
            case .authorized:
                completionHandler(true)
                
            case .notDetermined:
                self.contactStore.requestAccess(for: CNEntityType.contacts, completionHandler: { (access, accessError) -> Void in
                    if access {
                        completionHandler(access)
                    }
                    else {
                        completionHandler(false)
                    }
                })
                
            default:
                completionHandler(false)
            }
        }

}

After Toast dismiss and auto push to next View , NavigationBar height not correct

Pre-requisites:

  • Yes, I looked through both open and closed issues looking for what I needed.
  • No, I did not find what I was looking for.

Expected Behavior

when toast dismiss and auto push to next view , NavigationBar height should be correct
image

Current Behavior

when toast dismiss and auto push to next view , NavigationBar height isn't correct
image

Possible Solution

maybe code implement leads the bug

Steps to Reproduce

  • toast loading
  • dismiss toast and auto push to next view in swiftUI
  • NavigationBar height of next view height isn't correct

Context

Your Environment

  • Swift Version: 5.6
  • Xcode Version: 13.3
  • Operating System Version: macOS 12.4
  • Device or Simulator: iOS 15 iPad mini 6

IndefiniteProgressToastViewStyle has spinner constantly moving from top left to the toast

Before I start, great repository here. It's been great to work with.

I've encountered a weird issue when implementing toast using IndefiniteProgressToastViewStyle() with a network request. For the duration of the request, the spinner will repeatedly move from the top left of the screen into the center of the toast. Once the request is complete, the toast disappears as expected.

Here's a gif of the issue: https://giphy.com/gifs/VgHGygxhGNeB3zIhS2

This is happening on iPhone 11 Pro Max simulator, Xcode 12 beta 4, iOS 14 beta 4.

Code example:

var body: some View {
        TabView(selection: $selection) {
            NavigationView {
                Text("my view")
            }
            .tabItem {
                Label("Test", systemImage: "book")
                    .imageScale(.large)
                    .accessibility(label: Text("Test"))
            }
        }
        .toast(isPresented: $showLoadingView) {
          ToastView("Loading...")
            .toastViewStyle(IndefiniteProgressToastViewStyle())
        }
        .onAppear {
            showLoadingView = true
            model.loadAllData { result in
                switch result {
                    case .success:
                        showLoadingView = false
                    case .failure(let error):
                        // show error stuff
                }
            }
        }
    }

Failing to compile when added as a swift package

I wanted to try the package out a bit and I added it to a brand new project and it fails to compile.

There is nothing else in the project and it is showing a failure when compiling ToastUI.

Here is the error

loading unsized types is not allowed
  load void, void* %53, align 8, !dbg !316
Function return type does not match operand type of return inst!
  ret void <badref>, !dbg !316
 doublein function $s7ToastUI07DefaultA9ViewStyleV0caD0V11_cornerSize33_E64FDF835852504B4904DF0A39BD1713LLAA20ScaledMetricPropertyVy12CoreGraphics7CGFloatVGvpfi
<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: Broken function found, compilation aborted!

Not able to compile

After pod install, xcode not able to find the ".toast" modifier

"Value of type 'Button' has no member 'toast'"

change Toast position

Pre-requisites:

  • No, I did not find what I was looking for

Feature Suggestion

Is there any Idee how we change the position of Toast
toast was always displayed in the middle and we do not want that
best if you can change the position of the toast, would it be possible to do it?

Add `isUserInteractionEnabled`

Pre-requisites:

  • No, I did not find what I was looking for

Feature Suggestion

After having implemented the toast library I have found myself with the need for the user to be able to click inside the view in which it is presented so that he can perform certain actions while the Toast view is present.

Possible Implementation

I add a link to my repository so you can make a merge to yours.(main...olegtverdyy:ToastUI:feature/add-isUserInteractionEnabled)

Context

  • I present a toast at the bottom of the screen.
  • The user tries to click on another option on the screen to perform a navigation.
  • As the toast is displayed, he is not allowed to do so.

For it I have enabled the isUserInteractionEnabled option, to allow the user to make this action.

Is there any way to custom the animation duration?

Pre-requisites:

  • Yes, I looked through both open and closed issues looking for what I needed
  • No, I did not find what I was looking for

Feature Suggestion

Is there any way to specify the animation duration? It seems that current duration is 0.4 and cannot be modified by caller.

Possible Implementation

Context

[Security] Workflow swiftlint.yml is using vulnerable action actions/checkout

The workflow swiftlint.yml is referencing action actions/checkout using references v1. However this reference is missing the commit a6747255bd19d7a757dbdda8c654a9f84db19839 which may contain fix to the some vulnerability.
The vulnerability fix that is missing by actions version could be related to:
(1) CVE fix
(2) upgrade of vulnerable dependency
(3) fix to secret leak and others.
Please consider to update the reference to the action.

dismissAfter not dismissing on iOS13

Pre-requisites:

  • Yes, I looked through both open and closed issues looking for what I needed
  • No, I did not find what I was looking for

I am trying to switch from my basic alerts to using ToastUI but I'm running into an issue. For some reason my toast won't dismiss even after the set dismissAfter time. Funny enough this is only an issue when running on a device with iOS <14. Seems like the dismissAfter functionality only works with the beta.

Expected Behavior

Should dismiss after the pre-defined time.

Current Behavior

Toast stays on the screen and dismiss is never called.

Possible Solution

Steps to Reproduce (for bugs)

    @State var showWarning = false // this is set to true when a warning is triggered
    var body: some View {
        VStack {
             ...
        }.toast(isPresented: $showWarning, dismissAfter: 5.0, onDismiss: {
            print("Dismissing") // this never prints and the toast never goes away.
        }) {
            ToastView(self.messageContent).toastViewStyle(WarningToastViewStyle())
        }
    }

Context

Your Environment

  • Swift Version: 5.3 & 5.1
  • Xcode Version: 12.0 Beta 4 & 11.4
  • Operating System and Version: macOS Big Sur 11 and macOS Catalina 10.15
  • Device or Simulator: Device - iPhone 7 Plus iOS 13.6.1

Showing ToastUI on app load

Pre-requisites:

  • Yes, I looked through both open and closed issues looking for what I needed.
  • No, I did not find what I was looking for.

Expected Behavior

Be able to show the ToastUI at app load. Useful when doing initial network requests like auth or other early tasks

Current Behavior

Currently the ToastUI does not appear

Steps to Reproduce

struct TestView: View {
    @State private var isLoading: Bool = false
	
    var body: some View {
        VStack {
            Text(isLoading ? "Please wait..." : "Got auth token")
                .padding()
            Spacer()
        }
        .toast(isPresented: $isLoading) {
            ToastView("Loading").toastViewStyle(.indeterminate)
        }
        .onAppear {
            self.isLoading = true
        }
    }
}

Context

I basically want to open the app and the ToastUI to be visible until some network requests are done in the background
Disclaimer: I'm still new to SwiftUI so i might try to achieve this the wrong way

Your Environment

  • Swift Version: 5.5
  • Xcode Version: 13.4
  • Operating System Version: macOS Monteray 12.4
  • Device or Simulator: Irrelevant

more docs on calendar-popup-shiny.R

The calendar-popup-shiny is referred to in some of the GitHub issues, but there's not much documentation on the example, either via comments in the code, or via a README (or similar). At least when I run calendar-popup-shiny.R with toastui_0.3.0, clicking on an event does nothing, and I cannot create a new event. For troubleshooting, it would be helpful to know what the code is supposed to do.

sessionInfo()

R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.3

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Los_Angeles
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] shinycssloaders_1.0.0 tidyr_1.3.1           dplyr_1.1.4           httr2_1.0.0           shinyBS_0.61.1       
[6] shiny_1.8.0           toastui_0.3.0        

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.7      crayon_1.5.2        compiler_4.3.1      renv_1.0.2          promises_1.2.1     
 [6] tidyselect_1.2.0    Rcpp_1.0.11         later_1.3.1         jquerylib_0.1.4     yaml_2.3.8         
[11] fastmap_1.1.1       mime_0.12           R6_2.5.1            generics_0.1.3      curl_5.2.0         
[16] htmlwidgets_1.6.4   tibble_3.2.1        openssl_2.1.1       bslib_0.5.1         pillar_1.9.0       
[21] rlang_1.1.1         utf8_1.2.4          cachem_1.0.8        httpuv_1.6.11       fs_1.6.3           
[26] config_0.3.2        sass_0.4.7          memoise_2.0.1       cli_3.6.1           withr_2.5.0        
[31] magrittr_2.0.3      phosphoricons_0.2.0 shinyWidgets_0.8.1  digest_0.6.33       xtable_1.8-4       
[36] rappdirs_0.3.3      askpass_1.2.0       lifecycle_1.0.3     vctrs_0.6.5         gargle_1.5.2       
[41] glue_1.6.2          fansi_1.0.6         purrr_1.0.2         httr_1.4.7          pkgconfig_2.0.3    
[46] tools_4.3.1         ellipsis_0.3.2      htmltools_0.5.7  

Can't present subsequent toast without using onDismiss on the first toast

Pre-requisites:

  • [] Yes, I looked through both open and closed issues looking for what I needed
  • No, I did not find what I was looking for

I want to be able to display either a SuccessToastViewStyle or an ErrorToastViewStyle once my network request has finished.

The ShowSuccessToastAfterCompletedExample in the example project works great, however my case is a little bit different. I make a network call which shows an indefinite alert. At the end of the request, it calls my completion handler and passes a Result. If there is a .success, I want to display a success alert, and if there is a .failure, I'll display an error alert.

Example code:

CustomButton("Tap me") {
    savingViewShowing = true

    model.makeNetworkRequest() { result in
        switch result {
            case .success:
                savingViewShowing = false
                showSuccessAlert = true
            case .failure:
                savingViewShowing = false
                showErrorAlert = true
        }
    }
}
.toast(isPresented: $savingViewShowing) {
    ToastView("Saving...")
        .toastViewStyle(IndefiniteProgressToastViewStyle())
}
.toast(isPresented: $showSuccessAlert, dismissAfter: 1.0, onDismiss: { resetForm() }) {
    ToastView("Success!")
        .toastViewStyle(SuccessToastViewStyle())
}
.toast(isPresented: $showErrorAlert, dismissAfter: 1.0) {
    ToastView("Error!")
        .toastViewStyle(ErrorToastViewStyle())
}

However, the above doesn't work. The "Saving" alert will show fine, but nothing will show after that.

Changing my "Saving" alert's onDismiss to set showSuccessAlert to true does work:

.toast(isPresented: $savingViewShowing, onDismiss: { showSuccessAlert = true }) {
    ToastView("Saving...")
        .toastViewStyle(IndefiniteProgressToastViewStyle())
}

This isn't great when I don't know at build time which alert to show in my completion handler. I could create a lot of extra @States that hold success/fail, but that isn't ideal.

Is there something I'm doing wrong, or is there something that can be fixed?

Your Environment

  • Swift Version: 5
  • Xcode Version: 12 beta 4
  • Operating System and Version: iOS 14 beta 4
  • Device or Simulator: Simulator and device

Custom toast question

Pre-requisites:

  • [ *] Yes, I looked through both open and closed issues looking for what I needed
  • [ *] No, I did not find what I was looking for

Nice work guys - question how did you pull off the green bottom aligned toast in the animated gif example exactly? Would love to see an example.

Screen Shot 2020-12-23 at 2 18 42 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.