Sexy confetti
I always assumed Apple would hand over the confetti from iMessage as a SwiftUI component one day. They never did, and I’m not sure why.
Every other confetti library I tried looked wrong: too sparse, too neon, too obviously a physics engine. I wanted one thing — a view that rains down the exact confetti iMessage uses, with nothing to configure.
So I went looking, found an old write-up with the right idea, and discovered the code no longer compiled. I read back through the current documentation to bring it up to date, then wrapped the whole thing in a single SwiftUI view: UnionConfetti. On a real device it looks like this:
The same effect, on iOS.
How to use
One boolean, one overlay:
import SwiftUI
import UnionConfetti
struct ContentView: View {
@State var showConfetti = false
var body: some View {
Button("Rain on me") {
showConfetti = true
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.overlay(ConfettiView(isPresented: $showConfetti))
}
}That’s the whole API. Flip showConfetti to true and it rains; it resets itself when the last piece lands. Drop the overlay on top of anything worth celebrating, like a successful payment:
Confetti on a completed payment.
There’s more it could do — blur the layer behind it, expose a few knobs — but the whole point was a view that needs none of that. It rains the confetti, then gets out of the way.
UnionConfetti is on GitHub. Get the package.