I'd like to use this project Toast-Swift through CocoaPods in a SwiftUI view. It's for UIView, so I tried to write a ViewController and wrap it into SwiftUI but the result is nothing on the screen.
My code:
struct ToastView: UIViewControllerRepresentable{
@State var text: String
func makeUIViewController(context: UIViewControllerRepresentableContext<ToastView>) -> UIToast {
return UIToast(text: text)
}
func updateUIViewController(_ uiViewController: UIToast, context: UIViewControllerRepresentableContext<ToastView>) {
}
}
class UIToast: UIViewController{
var text: String = ""
init(text: String) {
super.init(nibName: nil, bundle: nil)
self.text = text
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
self.view.makeToast(text)
}
}
I've found some custom implementations on SO of a Toast for SwiftUI (SO question) but their behaviour is not exactly what I was looking for.
Can someone please help me to fix this? Is there another recommendation for Toast in SwiftUI? Thanks in advance!