AlertToast icon indicating copy to clipboard operation
AlertToast copied to clipboard

Create Example Project

Open Yurssoft opened this issue 2 years ago • 1 comments

I checked both article and project. No example project. I would recommend adding project used to create demo screens.

Yurssoft avatar Mar 25 '23 09:03 Yurssoft

You don't really need examples, this is extremely simple, creating one works like popovers, but I'm going to show you an example:

// Init state variable that tracks if toast is shown
@State var toastShown: Bool = false

// Create a button somewhere in view that will show that toast when clicked
Button("Show toast") {
    toastShown = true
}

// Create that toast somewhere in view like you would create a popover
.toast(isPresenting: $toastShown) {
    AlertToast(
        displayMode: .hud, type: .regular, title: "Toast title")
}

Don't just ctrl + c ctrl + v this code, you need to place that button and that toast inside view. If you want to modify how it looks, then change arguments inside AlertToast.

Adamekka avatar Aug 16 '23 23:08 Adamekka