elai950 / AlertToast

Create Apple-like alerts & toasts using SwiftUI
https://elai950.github.io/AlertToast/
MIT License
2.07k stars 187 forks source link

Make it easier to support multiple messages and message types #12

Closed svenoaks closed 1 year ago

svenoaks commented 3 years ago

Is your feature request related to a problem? Please describe. There is only atoast(isPresenting: Binding<Bool>...) function. It is cumbersome to add multiple messages and/or multiple message types.

Describe the solution you'd like There should be a toast<Item>(item: Binding<Item?>...) function that allows defining the message in the item. This would be similar to several SwiftUI apis like alert(item:..). When the item changes the alert is displayed.

Describe alternatives you've considered If we want to add multiple messages and/or have multiple message type, we must have multiple calls of toast(), or some other redundancy to allow this.

heecheon92 commented 1 year ago

I just added view extension and seems to work with single ".toast" modifier `

@ViewBuilder func toast(isPresenting: Binding<Bool>,
           duration: Double = 2,
           tapToDismiss: Bool = true,
           offsetY: CGFloat = 0,
           displayMode: AlertToast.DisplayMode,
           alertType: AlertToast.AlertType,
           title: String? = nil,
           subtitle: String? = nil,
           alertStyle: AlertToast.AlertStyle? = nil,
           onTap: (() -> ())? = nil, completion: (() -> ())? = nil) -> some View {

    modifier(AlertToastModifier(isPresenting: isPresenting,
                                duration: duration,
                                tapToDismiss: tapToDismiss,
                                offsetY: offsetY,
                                alert: { AlertToast(displayMode: displayMode,
                                                    type: alertType,
                                                    title: title,
                                                    subTitle: subtitle,
                                                    style: alertStyle) },
                                onTap: onTap,
                                completion: completion))
}

`