react-native-fiesta
Version:
A set of celebration animations powered by Skia. Engage more with your users by celebrating in your React Native application.
98 lines (97 loc) • 4.25 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useFiesta = exports.FiestaProvider = exports.FiestaContext = exports.FiestaAnimations = void 0;
var _react = _interopRequireWildcard(require("react"));
var _components = require("../components");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
let FiestaAnimations = exports.FiestaAnimations = /*#__PURE__*/function (FiestaAnimations) {
FiestaAnimations["Hearts"] = "Hearts";
FiestaAnimations["Balloons"] = "Balloons";
FiestaAnimations["Stars"] = "Stars";
FiestaAnimations["EmojiPopper"] = "EmojiPopper";
FiestaAnimations["Fireworks"] = "Fireworks";
return FiestaAnimations;
}({});
const FiestaContext = exports.FiestaContext = /*#__PURE__*/(0, _react.createContext)({
runFiestaAnimation: () => {}
});
const FiestaProvider = ({
children,
font
}) => {
const balloonsRef = (0, _react.useRef)(null);
const heartsRef = (0, _react.useRef)(null);
const emojiPopperRef = (0, _react.useRef)(null);
const starsRef = (0, _react.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.default.createElement(FiestaContext.Provider, {
value: {
runFiestaAnimation
}
}, /*#__PURE__*/_react.default.createElement(_components.Balloons, {
autoPlay: false,
ref: balloonsRef
}), /*#__PURE__*/_react.default.createElement(_components.Hearts, {
autoPlay: false,
ref: heartsRef
}), /*#__PURE__*/_react.default.createElement(_components.Stars, {
autoPlay: false,
ref: starsRef
}), font ? /*#__PURE__*/_react.default.createElement(_components.EmojiPopper, {
autoPlay: false,
ref: emojiPopperRef,
font: font
}) : null, children);
};
exports.FiestaProvider = FiestaProvider;
const useFiesta = () => {
const {
runFiestaAnimation
} = (0, _react.useContext)(FiestaContext);
return {
runFiestaAnimation
};
};
exports.useFiesta = useFiesta;
//# sourceMappingURL=FiestaContext.js.map