Confetti

0.1.0

Confetti view for SwiftUI
ottijp/confetti-swiftui

What's New

0.1.0

2024-04-05T14:21:12Z

Confetti

This is a SwiftUI view that displays confetti. You can use this package via SPM (Swift Package Manager).

This is beta release. Some of implementation might be changed incompatibly.

confetti.mov

Confetto are generated with random shape/scale/angle every time.

Requirement (tested on)

  • Xcode 15.0
  • iOS 15+

How to use

Add this SPM package to your Xcode project.

  1. File > Add Package Dependencies...
  2. Input https://github.com/ottijp/confetti-swiftui in search box.
  3. Select Confetti.
  4. Select Dependency Rule to Up to Next Major Version. (optional, recommended)

add-package

Import Confetti module and add ConfettiView on your view stack with ZStack.

import SwiftUI
import Confetti

struct SampleView1: View {
  var body: some View {
    ZStack {
      Text("Confetti")
      ConfettiView()
    }
  }
}

Configuration

Display timing

You can controll display timing like bellow.

import SwiftUI
import Confetti

struct SampleView2: View {
  @State private var isConffetiActive = false

  var body: some View {
    ZStack {
      VStack {
        Spacer()
        HStack {
          Toggle(isOn: $isConffetiActive) {
            Text("confetti")
          }
          .frame(width: 150)
        }
      }

      if isConffetiActive {
        ConfettiView()
      }
    }
  }
}

Emission duration

You can set the emission duration with emissionDuration property. Default duration is 2 seconds.

// emit for 5 seconds
ConfettiView(emissionDuration: 5.0)

License

MIT

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 15:55:42 GMT-0900 (Hawaii-Aleutian Daylight Time)