Closed wyk111wyk closed 4 years ago
Yes, you can. As demonstrated in CustomizedToastWithoutToastViewExample
, you just need to provide your SwiftUI views directly without using ToastView
. Here's a snippet from that example using Swift 5.3+.
struct CustomizedToastWithoutToastViewExample: View {
@State private var presentingToast: Bool = false
var body: some View {
Button {
presentingToast = true
} label: {
Text("Tap me")
}
.toast(isPresented: $presentingToast, dismissAfter: 2.0) {
print("Toast dismissed")
} content: {
// your SwiftUI views here
VStack {
Spacer()
Text("You can put any SwiftUI views here without the need of ToastView")
.bold()
.foregroundColor(.white)
.padding()
.background(Color.green)
.cornerRadius(8.0)
.shadow(radius: 4)
.padding()
}
}
}
}
But this is for pure Text, can't remove the blur background of success or progress view(ToastView)
ToastView
hasn't supported styles without background yet. Thank you for the suggestion and I will push an update in the near future.
Sorry for the late update but ToastUI
has just been updated and you can now use ToastView
with custom background (#11). Here's an example of using ToastView
with IndefiniteProgressToastViewStyle
but without blur background.
.toast(isPresented: $presentingToast) {
ToastView("Loading...") {
// EmptyView()
} background: {
// EmptyView()
}
.toastViewStyle(IndefiniteProgressToastViewStyle())
}
Passing EmptyView
is optional so you can reduce it to be one-liner.
.toast(isPresented: $presentingToast, dismissAfter: 2.0) {
ToastView("Loading...") {} background: {}
.toastViewStyle(IndefiniteProgressToastViewStyle())
}
The first closure is to provide your custom content view just like before and the second closure is for custom background view. For more information, check out the new ToastViewWithCustomBackgroundExample
in ToastUISample
.
Pre-requisites:
Feature Suggestion
Possible Implementation
Context