Skip to content

Latest commit

History

107 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

ConfettiSwiftUI

GitHub LicenseCocoapods platforms

Customize confetti animations.

  • All elements are built with pure SwiftUI.
  • Select from default confetti shapes, emojis, SF Symbols or text.
  • Trigger the animation with one state change multiple times with a haptic feed back on each explosion.

🌄 Examples

💻 Installation

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate ConfettiSwiftUI into your Xcode project using Xcode 12, specify it in File > Swift Packages > Add Package Dependency...:

https://github.com/simibac/ConfettiSwiftUI.git, :branch="master"

Manually

If you prefer not to use any of dependency managers, you can integrate ConfettiSwiftUI into your project manually. Put Sources/ConfettiSwiftUI folder in your Xcode project. Make sure to enable Copy items if needed and Create groups.

🧳 Requirements

  • iOS 14.0+ | macOS 11+
  • Swift 5+

🛠 Usage

First, add import ConfettiSwiftUI on every swift file you would like to use ConfettiSwiftUI. Define a integer as a state varable which is responsible for triggering the animation. Any change to that variable will span a new animation (increment and decrement).

import ConfettiSwiftUI
import SwiftUI
structContentView:View{@Stateprivatevartrigger:Int=0varbody:someView{Button("🎉"){
trigger +=1}.confettiCannon(trigger: $trigger)}}

Parameters

parametertypedescriptiondefault
triggerBindingon any change of this variable triggers the animation0
numIntamount of confettis20
confettis[ConfettiType]list of shapes and text[.shape(.circle), .shape(.triangle), .shape(.square), .shape(.slimRectangle), .shape(.roundedCross)]
colors[Color]list of colors applied to the default shapes[.blue, .red, .green, .yellow, .pink, .purple, .orange]
confettiSizeCGFloatsize that confettis and emojis are scaled to10.0
rainHeightCGFloatvertical distance that confettis pass600.0
fadesOutBoolsize that confettis and emojis are scaled totrue
opacityDoublemaximum opacity during the animation1.0
openingAngleAngleboundary that defines the opening angle in degreesAngle.degrees(60)
closingAngleAngleboundary that defines the closing angle in degreesAngle.degrees(120)
radiusCGFloatexplosion radius300.0
repetitionsIntnumber of repetitions for the explosion1
repetitionIntervalDoubleduration between the repetitions1.0
hapticFeedbackBoolhaptic feedback on each confetti explosiontrue

Configurator Application With Live Preview

You can use the configurator app in demo project here to configure your desired animation or get inspired by one of the many examples.

Configuration Examples

Color and Size

.confettiCannon(trigger: $trigger, colors:[.red,.black], confettiSize:20)

Repeat

.confettiCannon(trigger: $trigger, repetitions:3, repetitionInterval:0.7)

Firework

.confettiCannon(trigger: $trigger, num:50, openingAngle:Angle(degrees:0), closingAngle:Angle(degrees:360), radius:200)

Emoji

.confettiCannon(trigger: $trigger, confettis:[.text("❤️"),.text("💙"),.text("💚"),.text("🧡")])

Endless

.confettiCannon(trigger: $trigger, num:1, confettis:[.text("💩")], confettiSize:20, repetitions:100, repetitionInterval:0.1)

Make-it-Rain

.confettiCannon(trigger: $trigger, num:1, confettis:[.text("💵"),.text("💶"),.text("💷"),.text("💴")], confettiSize:30, repetitions:50, repetitionInterval:0.1)

.confettiCannon(trigger: $trigger8, confettis:[.image("arb"),.image("eth"),.image("btc"),.image("op"),.image("link"),.image("doge")], confettiSize:20)

👨‍💻 Contributors

All issue reports, feature requests, pull requests and GitHub stars are welcomed and much appreciated.

🔨Support

If you like the project, don't forget to put star 🌟.

Buy Me A Coffee

📃 License

ConfettiSwiftUI is available under the MIT license. See the LICENSE file for more info.

📦 Projects

The following projects have integrated ConfettiSwiftUI in their App.


About

SwiftUI Package for Configurable Confetti Animation 🎉

Topics

Resources

Stars

2.4k stars

Watchers

14 watching

Forks

Releases

Packages

Contributors

Languages