React Native Fiesta
website·Indexed 30 days ago
https://mateoguzmana.github.io/react-native-fiesta/A set of animations for React Native ideal for celebrations and user engagement. Includes components for balloons, fireworks, hearts, stars, emojis, and a popper for throwing elements across the screen, all manageable via the Fiesta context.
What's inside React Native Fiesta
- react-native-fiesta provides out-of-the-box celebration animations for React Native applications, allowing developers to trigger celebratory effects (such as for first orders or birthdays) without implementing complex animation logic. The library is powered by React Native Skia, a high-performance 2D graphics library.
Render a single animated star with the Star component
The
Starcomponent allows for the placement of a single animated star.Critical Requirement: The
Starcomponent must be wrapped inside aCanvascomponent from@shopify/react-native-skia. Failure to do so will cause the application to crash because the animation requires a Skia Canvas to execute.import { StyleSheet } from 'react-native'; import { Canvas } from '@shopify/react-native-skia'; import { Star } from 'react-native-fiesta'; function App() { return ( <Canvas style={styles.canvas}> <Star x={100} // Required: Initial x position y={200} // Required: Initial y position autoplay={true} // Optional: Whether to animate automatically (default: true) color="rgba(255, 255, 0, 1)" // Optional: Star color /> </Canvas> ); } const styles = StyleSheet.create({ canvas: { flex: 1, }, });Render a single animated heart with the Heart component
The
Heartcomponent allows for the display of a single animated heart.Critical Requirement: The
Heartcomponent must be wrapped inside aCanvascomponent from@shopify/react-native-skia. Failure to do so will cause the application to crash because the animation requires a Skia Canvas context.import { StyleSheet } from 'react-native'; import { Canvas } from '@shopify/react-native-skia'; import { Heart } from 'react-native-fiesta'; function App() { return ( <Canvas style={styles.canvas}> <Heart x={100} // Required: Initial x position y={100} // Required: Initial y position autoplay={true} // Optional: Whether to animate automatically (default: true) color="rgba(238, 17, 131, 1)" // Optional: Heart color /> </Canvas> ); } const styles = StyleSheet.create({ canvas: { flex: 1, }, });Trigger animations using the useFiesta hook
Use theuseFiestahook to access therunFiestaAnimationfunction. This function accepts an object containing ananimationproperty, which should be a value from theFiestaAnimationsenum to determine which animation to execute.import React from 'react'; import { Button } from 'react-native'; import { useFiesta, FiestaAnimations } from 'react-native-fiesta'; export function Example() { const { runFiestaAnimation } = useFiesta(); const onPress = () => runFiestaAnimation({ animation: FiestaAnimations.Balloons }); return <Button onPress={onPress} title="Run Animation" />; }Install react-native-fiesta
react-native-fiesta is a library of animations for celebrations and user engagement. It is powered by@shopify/react-native-skia, which must be installed first. No additional pods or dependencies beyond the core peer dependencies are required.# Install required peer dependencies and the library yarn add @shopify/react-native-skia yarn add react-native-reanimated yarn add react-native-fiestaRender a single customizable balloon with Balloon
The
Ballooncomponent allows for the placement of a single balloon on the screen.Critical Requirement: The
Ballooncomponent must be wrapped inside aCanvascomponent from@shopify/react-native-skia. Failure to do so will cause the application to crash because the animation requires a Skia Canvas to run.Props Reference
Prop Type Default Description xnumber0X position of the balloon on the screen ynumber0Y position of the balloon on the screen colorstringblueColor of the balloon rnumber40Radius of the balloon depthnumber1Depth of the balloon (suggested range: 0 to 1; 1 means no depth) import { StyleSheet } from 'react-native'; import { Canvas } from '@shopify/react-native-skia'; import { Balloon } from 'react-native-fiesta'; function App() { return ( <Canvas style={styles.canvas}> <Balloon x={50} y={50} color={'rgba(255, 0, 255, 0.4)'} depth={0.4} /> </Canvas> ); } const styles = StyleSheet.create({ canvas: { flex: 1, }, });Configure emoji fonts for react-native-fiesta
Emoji fonts are not bundled with react-native-fiesta to keep the library size small. You must provide a font file (such as OpenMoji, NotoColorEmoji, or OpenSansEmoji) from your own application assets and pass it to the emoji components using a Skia font object.Set up the FiestaProvider for global animations
Wrap your application with theFiestaProviderto enable the use of theuseFiestahook in any child component. If you intend to use emojis, you must load a font using@shopify/react-native-skiaand pass it as thefontprop to the provider.import React from 'react'; import { SafeAreaView, StyleSheet } from 'react-native'; import { FiestaProvider } from 'react-native-fiesta'; import { useFont } from '@shopify/react-native-skia'; import { Examples } from './components/Examples'; function App() { // optional, only needed if you want to use the emojis const font = useFont(require('./fonts/OpenMoji-Color.ttf'), 30); if (!font) return null; return ( <SafeAreaView style={styles.container}> <FiestaProvider font={font}> <Examples /> </FiestaProvider> </SafeAreaView> ); } const styles = StyleSheet.create({ container: { flex: 1, }, }); export default App;Render a set of animated stars with the Stars component
TheStarscomponent renders a set of animated stars. It supports custom theming via a color array and adjustable horizontal spacing between the stars.import { StyleSheet, View } from 'react-native'; import { Stars } from 'react-native-fiesta'; function App() { return ( <View style={styles.container}> <Stars theme={['#FF0000', '#00FF00']} // Optional: Array of colors for theming spacing={40} // Optional: Horizontal space between items (default: 30) /> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, }, });Render animated elements using the Popper component
ThePoppercomponent fromreact-native-fiestaallows you to compose a set of elements that are 'thrown' across the screen. It is designed to work within a SkiaCanvas. You define the visual representation of the elements using therenderItemprop, which provides the current coordinates (x,y) and a set ofcolorsfor each item.import { StyleSheet } from 'react-native'; import { Canvas, Circle } from '@shopify/react-native-skia'; import { Popper, PopperDirection } from 'react-native-fiesta'; function App() { return ( <Canvas style={styles.canvas}> <Popper direction={PopperDirection.Ascending} spacing={10} renderItem={({ x, y, colors }, index) => ( <Circle key={`circle-${index}`} cx={x} cy={y} r={10} color={colors[index]} /> )} positionSpringConfig={{ stiffness: 100, damping: 100, mass: 11000, }} fadeSpringConfig={{ stiffness: 1, damping: 1, mass: 1000, }} /> </Canvas> ); } const styles = StyleSheet.create({ canvas: { flex: 1, }, });Prevent Fiesta Animations Canvas from blocking UI pointer events
TheCanvascomponent in Fiesta Animations has pointer events enabled by default, which can block interactions with the UI elements behind it. While some components likePopperdisable pointer events automatically, individual animations may require manual configuration. To prevent theCanvasfrom intercepting touch events, set thepointerEventsprop tonone.<Canvas pointerEvents="none"> <YourSkiaComponent /> </Canvas>Implement a balloon celebration using the Balloons component
Thereact-native-fiestalibrary provides out-of-the-box components for celebrations. To display balloons on a screen, import and render theBalloonscomponent. For a centered layout, wrap the component in a View with flexbox centering styles.import { StyleSheet, View } from 'react-native'; import { Balloons } from 'react-native-fiesta'; function App() { return ( <View style={styles.container}> <Balloons /> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, });