nshipster / confettiview Goto Github PK
View Code? Open in Web Editor NEWA view that emits confetti ๐
Home Page: https://nshipster.com/caemitterlayer/
License: MIT License
A view that emits confetti ๐
Home Page: https://nshipster.com/caemitterlayer/
License: MIT License
Maybe add SwiftUI wrappers? ๐
import SwiftUI
struct ConfettiOverlay: UIViewRepresentable {
typealias UIViewType = ConfettiView
@Binding var isEmitting: Bool
var particles: [ConfettiView.Content]
var interval: TimeInterval
func makeUIView(context: Context) -> UIViewType {
let view = ConfettiView()
return view
}
func updateUIView(_ view: UIViewType, context: Context) {
let coordinator = context.coordinator
if isEmitting && !coordinator.isEmitting {
coordinator.isEmitting = true
view.emit(with: particles, for: interval) { _ in
coordinator.isEmitting = false
isEmitting = false
}
}
}
func makeCoordinator() -> Coordinator {
Coordinator()
}
class Coordinator {
var isEmitting: Bool
init() {
self.isEmitting = false
}
}
}
extension View {
public func confettiOverlay(isEmitting: Binding<Bool>, particles: [ConfettiView.Content], interval: TimeInterval = 3.0) -> some View {
ZStack {
self
ConfettiOverlay(isEmitting: isEmitting, particles: particles, interval: interval)
.allowsHitTesting(false)
.accessibility(hidden: true)
}
}
}
Has anyone noticed confetti failing to emit particles in the simulator? I'm using Xcode 12.4.
I have never observed this on device however.
The behavior shown in the README doesn't appear possible in the current implementation. Most of the ability to customize has been closed off.
e.g. I cannot customize layers because because neither ConfettiLayer
nor var confettiLayers
are public/open. Was this intentionally removed or is this library simply incomplete?
In any case - is this library still "alive" enough that a PR adding the functionality would be approved?
should be nice to move to Swift Packages
When emitting the confetti, using any duration less than 5 seconds causes the fading out to be very abrupt, and does not fade out like the video in the readme.
Attached is a screen recording with duration = 3s. As you can see, there is a very small fade out animation, but it generally looks very abrupt.
Great framework, @mattt !
I maintain an Objective C project and tried to use the framework. I imported it successfully and can create an ConfettiView object, but it doesn't have an emit method. Is it possible to use this from Objective C?
Thanks!
Hello,
how can I set the font size a confetti view with only text?
Thanks
Hey,
I'm using this in a project and I'm facing an issue. I can't find the origin of the issue or a way to fix it properly.
After some time (seems to be when the app is running in the background and you come back to it after a while), the confettiView can't stop emitting confetti. It works great when you test several times but after a while, it seems like the CAKeyframeAnimation
doesn't stop, the CATransaction
completion block is never called and I'm stuck with a lot of confetti on screen ๐
The only workaround I've found so far is to launch a timer and fade out the ConfettiView
myself, but it has not the same effect.
I don't know if it's the duration of the CAKeyframeAnimation
or something else that gets messed up.
I also wrapped all my emit call in DispatchQueue.main.async
just to make sure everything is running on the main thread but nothing does the trick so far.
I'm building on iOS 13 with Xcode 11.2.1. My emit duration
is 2.0. I'm adding the ConfettiView
on a UIWindow
that's on top of everything else.
Any help would be appreciated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.