1.5.2 • Published 3 years ago

react-native-confetti-cannon v1.5.2

Weekly downloads
4,213
License
MIT
Repository
-
Last release
3 years ago

CircleCI NPM PLATFORMS GITHUB

Live demo

:rocket: Try yourself on Storybook web version

Installation

npm install react-native-confetti-cannon
# or
yarn add react-native-confetti-cannon

Usage

import ConfettiCannon from 'react-native-confetti-cannon';

const MyComponent = () => (
  <ConfettiCannon count={200} origin={{x: -10, y: 0}} />
);

Props

NameTypeDescriptionRequiredDefault
countnumberitems count to displayrequired
origin{x: number, y: number}animation position originrequired
explosionSpeednumberexplosion duration (ms) from origin to top350
fallSpeednumberfall duration (ms) from top to bottom3000
fadeOutbooleanmake the confettis disappear at the endfalse
colorsstring[]give your own colors to the confettisdefault colors
autoStartbooleanauto start the animationtrue
autoStartDelaynumberdelay to wait before triggering animation0

Events

NameReturnsDescriptionRequired
onAnimationStartvoidcallback triggered at animation start
onAnimationResumevoidcallback triggered at animation resume
onAnimationStopvoidcallback triggered at animation stop
onAnimationEndvoidcallback triggered at animation end

Methods

NameReturnsDescriptionRequired
startvoidstart the animation programmatically
resumevoidresume the animation programmatically
stopvoidstop the animation programmatically

For example:

import ConfettiCannon from 'react-native-confetti-cannon';

class MyComponent extends React.PureComponent {
  explosion;

  handleSomeKindOfEvent = () => {
    this.explosion && this.explosion.start();
  };

  render() {
    return (
      <ConfettiCannon
        count={200}
        origin={{x: -10, y: 0}}
        autoStart={false}
        ref={ref => (this.explosion = ref)}
      />
    );
  }
}

Examples

Deep into the example folder to see the stories and run:

npm install && npm start

And choose one of the following Expo commands:

  • i: open in iOS simulator
  • a: open in Android emulator
  • w: open in web browser

:warning: Warning

It is strongly recommended to use 1.2.0 or higher to avoid this warning introduced in React-Native 0.62:

Animated: useNativeDriver was not specified. This is a required option and must be explicitly set to true or false