I'm working on something similar to the "Subscribed" notice that appears within the Podcast app.
struct FloatingNotice: View {
var body: some View {
VStack (alignment: .center, spacing: 8) {
Image(systemName: "checkmark")
.foregroundColor(.white)
.font(.system(size: 48, weight: .regular))
.padding(EdgeInsets(top: 20, leading: 5, bottom: 5, trailing: 5))
Text("Review added")
.foregroundColor(.white)
.font(.callout)
.padding(EdgeInsets(top: 0, leading: 10, bottom: 5, trailing: 10))
}
.background(Color.snackbar.opacity(0.75))
.cornerRadius(5)
.transition(.scale)
.onAppear {
withAnimation {
return self.hidden() // tried self.opacity but that doesn't seem to work either
}
}
}
}
and I'm presenting my notice from UIKit here
let floatingNotice = UIHostingController(rootView: FloatingNotice())
addChild(floatingNotice)
floatingNotice.view.frame = view.frame
view.addSubview(floatingNotice.view)
floatingNotice.didMove(toParent: self)
I found a pretty simple UIKit way of doing this, but it'd be nice to do this completely from SwiftUI
UIView.animate(withDuration: 3.0, animations: {
floatingNotice.view.alpha = 0.0
}, completion: { success in
floatingNotice.removeFromParent()
})