GithubHelp home page GithubHelp logo

ulitcos / react-canvas-confetti Goto Github PK

View Code? Open in Web Editor NEW
197.0 197.0 15.0 11.71 MB

React component for canvas-confetti library

Home Page: https://ulitcos.github.io/react-canvas-confetti/

License: MIT License

JavaScript 16.18% TypeScript 81.69% Shell 0.15% CSS 1.98%
canvas confetti react

react-canvas-confetti's People

Contributors

dtau9 avatar matyus avatar ulitcos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-canvas-confetti's Issues

Poor performance on Firefox for Android

The performance is very bad on Firefox for android, It's rendering at about 25fps.
Running smoothly on Firefox for desktop, not sure what the proper fix would be.

Types of parameters 'confetti' and 'confetti' are incompatible.

Hello, I suddenly got this error when I run build. I use the ff:

"react-canvas-confetti": "^1.4.0",
"@types/canvas-confetti": "^1.6.0",

Type error: Type '(confetti: confetti.CreateTypes | null) => void' is not assignable to type '(confetti: import("/Users/francis/web/sample/node_modules/react-canvas-confetti/node_modules/@types/canvas-confetti/index").CreateTypes | null) => void'.

This is the component

import { CreateTypes } from 'canvas-confetti'
import { useCallback, useEffect, useRef } from 'react'
import ReactCanvasConfetti from 'react-canvas-confetti'

interface ConfettiProps {}

const Confetti: React.FC<ConfettiProps> = () => {
  const refAnimationInstance = useRef<CreateTypes | null>(null)

  const getInstance = useCallback((confetti: CreateTypes | null) => {
    refAnimationInstance.current = confetti
  }, [])

  const makeShot = useCallback((particleRatio: number, opts: any) => {
    refAnimationInstance.current &&
      refAnimationInstance.current({
        ...opts,
        origin: { y: 0.7 },
        particleCount: Math.floor(200 * particleRatio),
      })
  }, [])

  useEffect(() => {
    const fire = () => {
      makeShot(0.25, {
        spread: 26,
        startVelocity: 55,
      })

      makeShot(0.2, {
        spread: 60,
      })

      makeShot(0.35, {
        spread: 100,
        decay: 0.91,
        scalar: 0.8,
      })

      makeShot(0.1, {
        spread: 120,
        startVelocity: 25,
        decay: 0.92,
        scalar: 1.2,
      })

      makeShot(0.1, {
        spread: 120,
        startVelocity: 45,
      })
    }

    fire()
  }, [makeShot])

  return (
    <ReactCanvasConfetti
      refConfetti={getInstance}
      style={{
        position: 'fixed',
        pointerEvents: 'none',
        width: '100%',
        height: '100%',
        top: 0,
        left: 0,
      }}
    />
  )
}

export default Confetti

Changelog Support

Hey there,

I love this package, but I noticed while trying to upgrade to v2 that this package does not publish any changelog. I'm wondering if this is something that could be achieved? It helps making upgrading between versions much easier.

I was able to figure this out by manually inspecting the examples but a migration guide would have sped things up a lot.

Appreciate your efforts on this project! Keep up the great work! ๐Ÿ™

Release notes?

Hi @ulitcos!

Thanks for the project. Great work ๐Ÿ˜ƒ

I've updated from 1.4.0 to 2.0.7 and found our confetti animation broken.

I didn't see any release notes to what happened from v1 to v2 to help debug the issue.

Is it possible to maintain release notes with new tags?

Also any hints what you think may have caused the issue would be of great help!

Thanks!

Preset style throw errors on compilation time

Hi, I'm trying to use your package and component like:
const canvasStyles = {
position: "fixed",
pointerEvents: "none",
width: "100%",
height: "100%",
top: 0,
left: 0,
};
<Pride autorun={{ speed: 30, duration:3000 }} style={canvasStyles} />

But compiler get's the error:

Type error: Type '{ position: string; pointerEvents: string; width: string; height: string; top: number; left: number; }' is not assignable to type 'Properties<string | number, string & {}>'.
  Types of property 'pointerEvents' are incompatible.
    Type 'string' is not assignable to type 'PointerEvents | undefined'.

How can I fix it?

Snow effect does not take into account array of confetti colours

I recently tried out your Functional Component example of the Snow effect (ref) and saw that only the first colour in the array is accepted. I tried this in my solution first, but then went back to your CodeSandbox and saw this was also true there. If you try to add more colours to the array, only #ffffff is picked up.

Is this a known limitation?

Customize explosion count

I want to have multiple explosions at once.
For example, in Fireworks example, has 2 explosions, and other examples have 1 explosion at once.
Can we customize the number of explosions for each example?

  • have multiple explosions at a time
  • each explosion position would be randomized

Set the confetti work on timer

I made an array of Date's and when someone opens the app on one of said dates I want the confetti to run for 5 seconds. I'm using the realistic confetti.

    componentDidMount() {
        const snapshots = [ 
...
]
        if (snapshots.includes(getTimestamp())) {
            this.startAnimation()
            setTimeout(this.pauseAnimation, 2000)
        }

My issue is that the animations works, but never stops. I've tried the code above and to set the timeout in pauseAnimation() directly but didn't work. Is there a workaround for this?

Can't use useEffect because it's a class component.


SOLVED

Made a countdown timer so that pauseAnimation runs after 5 seconds.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.