Home

Awesome

<!-- LOGO --> <br /> <h1> <p align="center"> <img src="https://user-images.githubusercontent.com/1636897/147644327-112cc446-75ea-4477-80ac-1d0cd60fc45e.png" alt="Logo"> </h1> <p align="center"> Easily celebrate little and big moments in your app with this lightweight confetti library! <br /> </p> <p align="center"> <a href="https://opensource.org/licenses/ISC"><img alt="License" src="https://img.shields.io/badge/License-ISC-yellow.svg"/></a> <a href="https://android-arsenal.com/api?level=16s"><img alt="API level 16" src="https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat"/></a> <a href="http://twitter.com/dionsegijn"><img alt="API level 16" src="https://img.shields.io/badge/Twitter-@dionsegijn-blue.svg?style=flat"/></a> <a href="https://github.com/DanielMartinus/Konfetti/actions"><img alt="Build Status" src="https://github.com/DanielMartinus/Konfetti/workflows/CI/badge.svg"/></a> </p> <p align="center"> <a href="#getting-started">Getting started</a> • <a href="#usage">How To Use</a> • <a href="#community">Community</a> • <a href="#contribute">Contribute</a> • <a href="#report-an-issue">Report issue</a> • <a href="#license">License</a> </p> <p align="center"> <strong>New version: 2.0.0 is now released! Jetpack compose support - improved animations and API - <a href="https://dionsegijn.dev/konfetti-migration-guide-v2.x.x">see migration guide here</a></strong> </p>

Getting started

Compose project:

dependencies {
    implementation 'nl.dionsegijn:konfetti-compose:2.0.4'
}

View based (XML) project:

dependencies {
    implementation 'nl.dionsegijn:konfetti-xml:2.0.4'
}

Find latest version and release notes here

Usage

<p align="center"> <strong>Samples:</strong></br> <a href="/samples/compose-kotlin/src/main">compose</a> • <a href="/samples/xml-kotlin/src/main">xml-kotlin</a> • <a href="/samples/xml-java/src/main">xml-java</a> • <a href="/samples/shared/src/main/java/nl/dionsegijn/samples/shared/Presets.kt">presets</a> </p> <p align="center"> <img width=300 src="https://user-images.githubusercontent.com/1636897/147699597-2d177073-a2f8-4f49-ad7e-c390dd374557.gif"/> </p>

Configure your confetti using the Party configuration object. This holds all the information on how the confetti will be generated. Almost all properties of a Party object have a default configuration! This makes it super easy to create beautiful and natural looking confetti.

The bare minimum you need is an Emitter to tell how often and how many confetti should spawn, like this:

Party(
    emitter = Emitter(duration = 5, TimeUnit.SECONDS).perSecond(30)
)

But the possibilities are endless! You can fully control how the confetti will be generated and behave by customizing the values of the Party object. An example of a customized Party configuration is this:

Party(
    speed = 0f,
    maxSpeed = 30f,
    damping = 0.9f,
    spread = 360,
    colors = listOf(0xfce18a, 0xff726d, 0xf4306d, 0xb48def),
    position = Position.Relative(0.5, 0.3),
    emitter = Emitter(duration = 100, TimeUnit.MILLISECONDS).max(100)
)

To learn more, see more samples linked at the top of this section

Party options

See Party implementation here

KonfettiView

Create a KonfettiView in your compose UI or add one to your xml layout depending on your setup.

Compose

KonfettiView(
    modifier = Modifier.fillMaxSize(),
    parties = state.party,
)

View-based (xml)

<nl.dionsegijn.konfetti.xml.KonfettiView
    android:id="@+id/konfettiView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
Party(
    speed = 0f,
    maxSpeed = 30f,
    damping = 0.9f,
    spread = 360,
    colors = listOf(0xfce18a, 0xff726d, 0xf4306d, 0xb48def),
    emitter = Emitter(duration = 100, TimeUnit.MILLISECONDS).max(100),
    position = Position.Relative(0.5, 0.3)
)
viewKonfetti.start(party)

And that's it! There are endless possibilities to configure the confetti. If you want to learn more on how to implement Konfetti in a java, xml or compose project then see the samples linked at the top of this section

Community

Contribute

Do you see any improvements or want to implement a missing feature? Contributions are very welcome!

Take into account that changes and requests can be rejected if they don't align with the purpose of the library. To not waste any time you can always open an issue here to talk before you start making any changes.

What is the purpose of this library?

To have a lightweight particle system to easily generate confetti particles to celebrate little and big moments. Even though this is a particle system the purpose is not to be a fully fledged particle system. Changes and features are meant to be in line with being a confetti library. A great example is the implementation of custom shapes by @mattprecious here.

Report an issue

License

Konfetti is released under the ISC license. See LICENSE for details.