UNPKG

react-native-fiesta

Version:

A set of celebration animations powered by Skia. Engage more with your users by celebrating in your React Native application.

88 lines 3.12 kB
import React, { createContext, useContext, useRef } from 'react'; import { Balloons as _Balloons, Hearts as _Hearts, Stars as _Stars, EmojiPopper as _EmojiPopper } from '../components'; export let FiestaAnimations = /*#__PURE__*/function (FiestaAnimations) { FiestaAnimations["Hearts"] = "Hearts"; FiestaAnimations["Balloons"] = "Balloons"; FiestaAnimations["Stars"] = "Stars"; FiestaAnimations["EmojiPopper"] = "EmojiPopper"; FiestaAnimations["Fireworks"] = "Fireworks"; return FiestaAnimations; }({}); export const FiestaContext = /*#__PURE__*/createContext({ runFiestaAnimation: () => {} }); export const FiestaProvider = ({ children, font }) => { const balloonsRef = useRef(null); const heartsRef = useRef(null); const emojiPopperRef = useRef(null); const starsRef = useRef(null); const runFiestaAnimation = ({ animation, ...options }) => { var _balloonsRef$current, _heartsRef$current, _starsRef$current, _balloonsRef$current2; switch (animation) { case FiestaAnimations.Balloons: (_balloonsRef$current = balloonsRef.current) === null || _balloonsRef$current === void 0 || _balloonsRef$current.start({ ...options }); break; case FiestaAnimations.Hearts: (_heartsRef$current = heartsRef.current) === null || _heartsRef$current === void 0 || _heartsRef$current.start({ ...options }); break; case FiestaAnimations.Stars: (_starsRef$current = starsRef.current) === null || _starsRef$current === void 0 || _starsRef$current.start({ ...options }); break; case FiestaAnimations.Fireworks: throw new Error('Fireworks are not supported yet in the Fiesta context, please use them as a component.'); case FiestaAnimations.EmojiPopper: if (font) { var _emojiPopperRef$curre; (_emojiPopperRef$curre = emojiPopperRef.current) === null || _emojiPopperRef$curre === void 0 || _emojiPopperRef$curre.start({ ...options }); } else { throw new Error('This animation cannot be executed without a font, please set a font in the Fiesta provider.'); } break; default: (_balloonsRef$current2 = balloonsRef.current) === null || _balloonsRef$current2 === void 0 || _balloonsRef$current2.start({ ...options }); } }; return /*#__PURE__*/React.createElement(FiestaContext.Provider, { value: { runFiestaAnimation } }, /*#__PURE__*/React.createElement(_Balloons, { autoPlay: false, ref: balloonsRef }), /*#__PURE__*/React.createElement(_Hearts, { autoPlay: false, ref: heartsRef }), /*#__PURE__*/React.createElement(_Stars, { autoPlay: false, ref: starsRef }), font ? /*#__PURE__*/React.createElement(_EmojiPopper, { autoPlay: false, ref: emojiPopperRef, font: font }) : null, children); }; export const useFiesta = () => { const { runFiestaAnimation } = useContext(FiestaContext); return { runFiestaAnimation }; }; //# sourceMappingURL=FiestaContext.js.map