react-native-confetti-reanimated 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +277 -0
  3. package/lib/commonjs/ConfettiCanvas.js +89 -0
  4. package/lib/commonjs/ConfettiCanvas.js.map +1 -0
  5. package/lib/commonjs/ConfettiParticle.js +116 -0
  6. package/lib/commonjs/ConfettiParticle.js.map +1 -0
  7. package/lib/commonjs/index.js +27 -0
  8. package/lib/commonjs/index.js.map +1 -0
  9. package/lib/commonjs/package.json +1 -0
  10. package/lib/commonjs/presets.js +146 -0
  11. package/lib/commonjs/presets.js.map +1 -0
  12. package/lib/commonjs/types.js +2 -0
  13. package/lib/commonjs/types.js.map +1 -0
  14. package/lib/commonjs/useConfetti.js +27 -0
  15. package/lib/commonjs/useConfetti.js.map +1 -0
  16. package/lib/commonjs/utils.js +125 -0
  17. package/lib/commonjs/utils.js.map +1 -0
  18. package/lib/module/ConfettiCanvas.js +84 -0
  19. package/lib/module/ConfettiCanvas.js.map +1 -0
  20. package/lib/module/ConfettiParticle.js +110 -0
  21. package/lib/module/ConfettiParticle.js.map +1 -0
  22. package/lib/module/index.js +6 -0
  23. package/lib/module/index.js.map +1 -0
  24. package/lib/module/package.json +1 -0
  25. package/lib/module/presets.js +142 -0
  26. package/lib/module/presets.js.map +1 -0
  27. package/lib/module/types.js +2 -0
  28. package/lib/module/types.js.map +1 -0
  29. package/lib/module/useConfetti.js +22 -0
  30. package/lib/module/useConfetti.js.map +1 -0
  31. package/lib/module/utils.js +116 -0
  32. package/lib/module/utils.js.map +1 -0
  33. package/lib/typescript/ConfettiCanvas.d.ts +20 -0
  34. package/lib/typescript/ConfettiCanvas.d.ts.map +1 -0
  35. package/lib/typescript/ConfettiParticle.d.ts +10 -0
  36. package/lib/typescript/ConfettiParticle.d.ts.map +1 -0
  37. package/lib/typescript/index.d.ts +6 -0
  38. package/lib/typescript/index.d.ts.map +1 -0
  39. package/lib/typescript/presets.d.ts +52 -0
  40. package/lib/typescript/presets.d.ts.map +1 -0
  41. package/lib/typescript/types.d.ts +118 -0
  42. package/lib/typescript/types.d.ts.map +1 -0
  43. package/lib/typescript/useConfetti.d.ts +11 -0
  44. package/lib/typescript/useConfetti.d.ts.map +1 -0
  45. package/lib/typescript/utils.d.ts +24 -0
  46. package/lib/typescript/utils.d.ts.map +1 -0
  47. package/package.json +78 -0
  48. package/src/ConfettiCanvas.tsx +121 -0
  49. package/src/ConfettiParticle.tsx +141 -0
  50. package/src/index.tsx +6 -0
  51. package/src/presets.ts +126 -0
  52. package/src/types.ts +137 -0
  53. package/src/useConfetti.ts +25 -0
  54. package/src/utils.ts +135 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Andy A
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,277 @@
1
+ # 🎉 react-native-confetti-reanimated
2
+
3
+ A high-performance confetti component for React Native, powered by [Reanimated 4](https://docs.swmansion.com/react-native-reanimated/). Inspired by [canvas-confetti](https://github.com/catdad/canvas-confetti), fully compatible with Expo.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/react-native-confetti-reanimated.svg)](https://www.npmjs.com/package/react-native-confetti-reanimated)
6
+ [![license](https://img.shields.io/npm/l/react-native-confetti-reanimated.svg)](https://github.com/andydev271/react-native-confetti-reanimated/blob/main/LICENSE)
7
+
8
+ ## Preview
9
+
10
+ <!-- Add your demo GIF here after generating it -->
11
+ ![Confetti Demo](./assets/demo.gif)
12
+
13
+ > **Note**: To generate demo GIFs, run the example app and record the screen. See [example/README.md](./example/README.md) for instructions.
14
+
15
+ ## Features
16
+
17
+ - 🚀 **High Performance** - Built with Reanimated 4 for smooth 60fps animations on UI thread
18
+ - 📱 **Expo Compatible** - Works seamlessly with Expo managed workflow
19
+ - 🎨 **Fully Customizable** - Control colors, shapes, physics, and more
20
+ - 🎭 **Multiple Shapes** - Supports squares, circles, and triangles
21
+ - 🎯 **Preset Effects** - Ready-to-use effects like fireworks, snow, stars
22
+ - 🌈 **Canvas Confetti API** - Familiar API inspired by canvas-confetti
23
+ - 📦 **TypeScript** - Full TypeScript support
24
+ - 🔧 **Lightweight** - Minimal dependencies
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install react-native-confetti-reanimated react-native-reanimated react-native-worklets
30
+ ```
31
+
32
+ Or with Expo:
33
+
34
+ ```bash
35
+ npx expo install react-native-confetti-reanimated react-native-reanimated react-native-worklets
36
+ ```
37
+
38
+ ### Setup
39
+
40
+ Add the Babel plugin to your `babel.config.js`:
41
+
42
+ **For Expo projects:**
43
+
44
+ ```javascript
45
+ module.exports = function (api) {
46
+ api.cache(true);
47
+ return {
48
+ presets: ['babel-preset-expo'],
49
+ plugins: [
50
+ 'react-native-worklets/plugin',
51
+ ],
52
+ };
53
+ };
54
+ ```
55
+
56
+ **For React Native CLI projects:**
57
+
58
+ ```javascript
59
+ module.exports = {
60
+ presets: ['module:metro-react-native-babel-preset'],
61
+ plugins: [
62
+ 'react-native-worklets/plugin',
63
+ ],
64
+ };
65
+ ```
66
+
67
+ > ⚠️ **Important**: `react-native-worklets/plugin` must be listed last. Restart your app after updating Babel config.
68
+
69
+ ## Quick Start
70
+
71
+ ```tsx
72
+ import React from 'react';
73
+ import { View, Button } from 'react-native';
74
+ import { ConfettiCanvas, useConfetti } from 'react-native-confetti-reanimated';
75
+
76
+ export default function App() {
77
+ const { confettiRef, fire } = useConfetti();
78
+
79
+ return (
80
+ <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
81
+ <Button title="🎉 Celebrate!" onPress={() => fire()} />
82
+ <ConfettiCanvas ref={confettiRef} />
83
+ </View>
84
+ );
85
+ }
86
+ ```
87
+
88
+ ## Usage Examples
89
+
90
+ ### Using Presets
91
+
92
+ ```tsx
93
+ import { presets } from 'react-native-confetti-reanimated';
94
+
95
+ // Celebration burst
96
+ fire(presets.celebration);
97
+
98
+ // Fireworks effect
99
+ fire(presets.fireworks);
100
+
101
+ // Snow effect
102
+ fire(presets.snow);
103
+
104
+ // Stars
105
+ fire(presets.stars);
106
+ ```
107
+
108
+ ### Custom Configuration
109
+
110
+ ```tsx
111
+ fire({
112
+ particleCount: 100,
113
+ spread: 70,
114
+ origin: { y: 0.6 },
115
+ colors: ['#ff0000', '#00ff00', '#0000ff'],
116
+ shapes: ['square', 'circle', 'triangle'],
117
+ startVelocity: 45,
118
+ gravity: 1,
119
+ decay: 0.9,
120
+ });
121
+ ```
122
+
123
+ ### Directional Effects
124
+
125
+ ```tsx
126
+ // Left cannon
127
+ fire(presets.leftCannon);
128
+
129
+ // Right cannon
130
+ fire(presets.rightCannon);
131
+
132
+ // Bottom cannon (shoot upward)
133
+ fire(presets.bottomCannon);
134
+ ```
135
+
136
+ ### Continuous Effect
137
+
138
+ ```tsx
139
+ const startContinuous = () => {
140
+ const interval = setInterval(() => {
141
+ fire({ particleCount: 10 });
142
+ }, 200);
143
+
144
+ // Stop after 3 seconds
145
+ setTimeout(() => clearInterval(interval), 3000);
146
+ };
147
+ ```
148
+
149
+ ## API Reference
150
+
151
+ ### `ConfettiCanvas`
152
+
153
+ Main component that renders confetti particles.
154
+
155
+ **Props:**
156
+
157
+ | Prop | Type | Default | Description |
158
+ |------|------|---------|-------------|
159
+ | `containerStyle` | `StyleProp<ViewStyle>` | `undefined` | Custom style for container |
160
+ | `zIndex` | `number` | `1000` | Z-index of confetti layer |
161
+ | `fullScreen` | `boolean` | `true` | Whether to cover full screen |
162
+
163
+ ### `useConfetti()`
164
+
165
+ Hook for controlling confetti.
166
+
167
+ **Returns:**
168
+ - `confettiRef` - Ref to pass to ConfettiCanvas
169
+ - `fire(config?)` - Function to trigger confetti
170
+ - `reset()` - Clear all confetti
171
+
172
+ ### Configuration Options
173
+
174
+ ```typescript
175
+ interface ConfettiConfig {
176
+ particleCount?: number; // Default: 50
177
+ angle?: number; // Default: 90 (degrees)
178
+ spread?: number; // Default: 45 (degrees)
179
+ startVelocity?: number; // Default: 45
180
+ decay?: number; // Default: 0.9
181
+ gravity?: number; // Default: 1
182
+ drift?: number; // Default: 0
183
+ duration?: number; // Default: 3000 (ms)
184
+ colors?: string[]; // Default: vibrant colors
185
+ scalar?: number; // Default: 1
186
+ origin?: { x?: number; y?: number }; // Default: { x: 0.5, y: 0.5 }
187
+ shapes?: Array<'square' | 'circle' | 'triangle'>; // Default: ['square', 'circle']
188
+ tilt?: boolean; // Default: true
189
+ tiltAngleIncrement?: number; // Default: 10
190
+ }
191
+ ```
192
+
193
+ ### Available Presets
194
+
195
+ ```typescript
196
+ presets.celebration // 🎊 Basic celebration
197
+ presets.fireworks // 🎆 Explosive effect
198
+ presets.realistic // ✨ Realistic confetti
199
+ presets.snow // ❄️ Falling snow
200
+ presets.stars // ⭐ Twinkling stars
201
+ presets.leftCannon // ⬅️ Left side cannon
202
+ presets.rightCannon // ➡️ Right side cannon
203
+ presets.bottomCannon // ⬆️ Bottom cannon
204
+ ```
205
+
206
+ ## Example App
207
+
208
+ Check out the `example` directory for a complete demo app with all features.
209
+
210
+ ```bash
211
+ cd example
212
+ npm install
213
+ npm start
214
+ ```
215
+
216
+ Then use Expo Go to scan the QR code or press `i` for iOS / `a` for Android.
217
+
218
+ ## Platform Support
219
+
220
+ - ✅ iOS
221
+ - ✅ Android
222
+ - ✅ Expo (SDK 50+)
223
+
224
+ ## Requirements
225
+
226
+ - React Native ≥ 0.74 (New Architecture/Fabric)
227
+ - React Native Reanimated ≥ 4.0.0
228
+ - React Native Worklets ≥ 0.5.0
229
+ - Expo SDK ≥ 50 (if using Expo)
230
+
231
+ > **Note**: Reanimated 4 requires the React Native New Architecture (Fabric)
232
+
233
+ ## Troubleshooting
234
+
235
+ ### Confetti not appearing?
236
+
237
+ 1. Ensure `ConfettiCanvas` is in your component tree
238
+ 2. Verify Babel plugin is configured (`react-native-worklets/plugin`)
239
+ 3. Restart your app completely after Babel changes
240
+ 4. Clear Metro cache: `npx react-native start --reset-cache`
241
+ 5. Make sure you're using React Native New Architecture (Fabric)
242
+
243
+ ### Performance issues?
244
+
245
+ - Reduce `particleCount` (recommended: 50-100)
246
+ - Shorten `duration` (recommended: 2-3 seconds)
247
+ - Ensure you're using the latest version of Reanimated
248
+
249
+ ### TypeScript errors?
250
+
251
+ ```bash
252
+ npm install --save-dev @types/react @types/react-native
253
+ ```
254
+
255
+ ## Contributing
256
+
257
+ Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md).
258
+
259
+ ## License
260
+
261
+ MIT © [Andy A](https://github.com/andydev271)
262
+
263
+ ## Credits
264
+
265
+ - Inspired by [canvas-confetti](https://github.com/catdad/canvas-confetti) by @catdad
266
+ - Built with [react-native-reanimated](https://github.com/software-mansion/react-native-reanimated) v4
267
+ - Uses [react-native-worklets](https://github.com/software-mansion/react-native-worklets)
268
+
269
+ ## Links
270
+
271
+ - 📦 [npm](https://www.npmjs.com/package/react-native-confetti-reanimated)
272
+ - 🐛 [Issues](https://github.com/andydev271/react-native-confetti-reanimated/issues)
273
+ - 💬 [Discussions](https://github.com/andydev271/react-native-confetti-reanimated/discussions)
274
+
275
+ ---
276
+
277
+ Made with ❤️ and confetti
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ConfettiCanvas = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _utils = require("./utils");
10
+ var _ConfettiParticle = require("./ConfettiParticle");
11
+ var _jsxRuntime = require("react/jsx-runtime");
12
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
+ const ConfettiCanvas = exports.ConfettiCanvas = /*#__PURE__*/_react.default.forwardRef(({
14
+ containerStyle,
15
+ zIndex = 1000,
16
+ fullScreen = true
17
+ }, ref) => {
18
+ const [particles, setParticles] = (0, _react.useState)([]);
19
+ const [activeCount, setActiveCount] = (0, _react.useState)(0);
20
+ const {
21
+ width,
22
+ height
23
+ } = (0, _reactNative.useWindowDimensions)();
24
+ const fire = (0, _react.useCallback)((config = {}) => {
25
+ return new Promise(resolve => {
26
+ const mergedConfig = {
27
+ ..._utils.DEFAULT_CONFIG,
28
+ ...config,
29
+ origin: {
30
+ ..._utils.DEFAULT_CONFIG.origin,
31
+ ...config.origin
32
+ }
33
+ };
34
+ const newParticles = (0, _utils.createConfettiParticles)(mergedConfig, width, height);
35
+ setParticles(prev => [...prev, ...newParticles]);
36
+ setActiveCount(prev => prev + newParticles.length);
37
+
38
+ // Resolve after the duration
39
+ setTimeout(() => {
40
+ resolve(null);
41
+ }, mergedConfig.duration);
42
+ });
43
+ }, [width, height]);
44
+ const reset = (0, _react.useCallback)(() => {
45
+ setParticles([]);
46
+ setActiveCount(0);
47
+ }, []);
48
+ (0, _react.useImperativeHandle)(ref, () => {
49
+ const confetti = fire;
50
+ confetti.reset = reset;
51
+ return confetti;
52
+ }, [fire, reset]);
53
+ const handleParticleComplete = (0, _react.useCallback)(particleId => {
54
+ setActiveCount(prev => prev - 1);
55
+ setParticles(prev => {
56
+ // Clean up completed particles periodically
57
+ if (prev.length > 100) {
58
+ return prev.filter(p => p.id !== particleId).slice(-50);
59
+ }
60
+ return prev;
61
+ });
62
+ }, []);
63
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
64
+ style: [styles.container, fullScreen && styles.fullScreen, {
65
+ zIndex
66
+ }, containerStyle],
67
+ pointerEvents: "none",
68
+ children: particles.map(particle => /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConfettiParticle.ConfettiParticle, {
69
+ particle: particle,
70
+ duration: _utils.DEFAULT_CONFIG.duration,
71
+ onComplete: () => handleParticleComplete(particle.id)
72
+ }, particle.id))
73
+ });
74
+ });
75
+ ConfettiCanvas.displayName = 'ConfettiCanvas';
76
+ const styles = _reactNative.StyleSheet.create({
77
+ container: {
78
+ position: 'absolute',
79
+ width: '100%',
80
+ height: '100%'
81
+ },
82
+ fullScreen: {
83
+ top: 0,
84
+ left: 0,
85
+ right: 0,
86
+ bottom: 0
87
+ }
88
+ });
89
+ //# sourceMappingURL=ConfettiCanvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_utils","_ConfettiParticle","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ConfettiCanvas","exports","React","forwardRef","containerStyle","zIndex","fullScreen","ref","particles","setParticles","useState","activeCount","setActiveCount","width","height","useWindowDimensions","fire","useCallback","config","Promise","resolve","mergedConfig","DEFAULT_CONFIG","origin","newParticles","createConfettiParticles","prev","length","setTimeout","duration","reset","useImperativeHandle","confetti","handleParticleComplete","particleId","filter","p","id","slice","jsx","View","style","styles","container","pointerEvents","children","map","particle","ConfettiParticle","onComplete","displayName","StyleSheet","create","position","top","left","right","bottom"],"sourceRoot":"../../src","sources":["ConfettiCanvas.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAAsD,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAD,wBAAAM,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAR,uBAAA,YAAAA,CAAAM,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,M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,EAAC5D,iBAAA,CAAAqE,gBAAgB;MAEfD,QAAQ,EAAEA,QAAS;MACnBlB,QAAQ,EAAEP,qBAAc,CAACO,QAAS;MAClCoB,UAAU,EAAEA,CAAA,KAAMhB,sBAAsB,CAACc,QAAQ,CAACV,EAAE;IAAE,GAHjDU,QAAQ,CAACV,EAIf,CACF;EAAC,CACE,CAAC;AAEX,CACF,CAAC;AAEDrC,cAAc,CAACkD,WAAW,GAAG,gBAAgB;AAE7C,MAAMR,MAAM,GAAGS,uBAAU,CAACC,MAAM,CAAC;EAC/BT,SAAS,EAAE;IACTU,QAAQ,EAAE,UAAU;IACpBxC,KAAK,EAAE,MAAM;IACbC,MAAM,EAAE;EACV,CAAC;EACDR,UAAU,EAAE;IACVgD,GAAG,EAAE,CAAC;IACNC,IAAI,EAAE,CAAC;IACPC,KAAK,EAAE,CAAC;IACRC,MAAM,EAAE;EACV;AACF,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ConfettiParticle = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
+ const ConfettiParticle = ({
13
+ particle,
14
+ duration,
15
+ onComplete
16
+ }) => {
17
+ const translateX = (0, _reactNativeReanimated.useSharedValue)(0);
18
+ const translateY = (0, _reactNativeReanimated.useSharedValue)(0);
19
+ const rotation = (0, _reactNativeReanimated.useSharedValue)(particle.rotation);
20
+ const opacity = (0, _reactNativeReanimated.useSharedValue)(1);
21
+ (0, _react.useEffect)(() => {
22
+ // Animate the particle
23
+ translateX.value = (0, _reactNativeReanimated.withTiming)(particle.velocity.x * (duration / 16), {
24
+ duration,
25
+ easing: _reactNativeReanimated.Easing.linear
26
+ });
27
+ translateY.value = (0, _reactNativeReanimated.withTiming)(particle.velocity.y * (duration / 16), {
28
+ duration,
29
+ easing: _reactNativeReanimated.Easing.bezier(0.33, 1, 0.68, 1) // Custom easing for gravity effect
30
+ });
31
+ rotation.value = (0, _reactNativeReanimated.withTiming)(particle.rotation + particle.rotationVelocity * (duration / 16), {
32
+ duration,
33
+ easing: _reactNativeReanimated.Easing.linear
34
+ });
35
+ opacity.value = (0, _reactNativeReanimated.withTiming)(0, {
36
+ duration,
37
+ easing: _reactNativeReanimated.Easing.linear
38
+ }, finished => {
39
+ if (finished && onComplete) {
40
+ (0, _reactNativeReanimated.runOnJS)(onComplete)();
41
+ }
42
+ });
43
+ }, [duration, onComplete, opacity, particle, rotation, translateX, translateY]);
44
+ const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
45
+ return {
46
+ transform: [{
47
+ translateX: translateX.value
48
+ }, {
49
+ translateY: translateY.value
50
+ }, {
51
+ rotate: `${rotation.value}deg`
52
+ }],
53
+ opacity: opacity.value
54
+ };
55
+ });
56
+ const renderShape = () => {
57
+ const baseStyle = [styles.particle, {
58
+ width: particle.size,
59
+ height: particle.size,
60
+ backgroundColor: particle.color
61
+ }];
62
+ if (particle.shape === 'circle') {
63
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
64
+ style: [...baseStyle, styles.circle, animatedStyle]
65
+ });
66
+ } else if (particle.shape === 'triangle') {
67
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
68
+ style: [...baseStyle, styles.transparent, animatedStyle],
69
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
70
+ style: [styles.triangle, {
71
+ borderLeftWidth: particle.size / 2,
72
+ borderRightWidth: particle.size / 2,
73
+ borderBottomWidth: particle.size,
74
+ borderBottomColor: particle.color
75
+ }]
76
+ })
77
+ });
78
+ }
79
+
80
+ // Square (default)
81
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
82
+ style: [...baseStyle, animatedStyle]
83
+ });
84
+ };
85
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
86
+ style: [styles.container, {
87
+ left: particle.x,
88
+ top: particle.y
89
+ }],
90
+ children: renderShape()
91
+ });
92
+ };
93
+ exports.ConfettiParticle = ConfettiParticle;
94
+ const styles = _reactNative.StyleSheet.create({
95
+ container: {
96
+ position: 'absolute'
97
+ },
98
+ particle: {
99
+ position: 'absolute'
100
+ },
101
+ circle: {
102
+ borderRadius: 999
103
+ },
104
+ transparent: {
105
+ backgroundColor: 'transparent'
106
+ },
107
+ triangle: {
108
+ width: 0,
109
+ height: 0,
110
+ backgroundColor: 'transparent',
111
+ borderStyle: 'solid',
112
+ borderLeftColor: 'transparent',
113
+ borderRightColor: 'transparent'
114
+ }
115
+ });
116
+ //# sourceMappingURL=ConfettiParticle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ConfettiParticle","particle","duration","onComplete","translateX","useSharedValue","translateY","rotation","opacity","useEffect","value","withTiming","velocity","x","easing","Easing","linear","y","bezier","rotationVelocity","finished","runOnJS","animatedStyle","useAnimatedStyle","transform","rotate","renderShape","baseStyle","styles","width","size","height","backgroundColor","color","shape","jsx","View","style","circle","transparent","children","triangle","borderLeftWidth","borderRightWidth","borderBottomWidth","borderBottomColor","container","left","top","exports","StyleSheet","create","position","borderRadius","borderStyle","borderLeftColor","borderRightColor"],"sourceRoot":"../../src","sources":["ConfettiParticle.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAH,uBAAA,CAAAC,OAAA;AAMiC,IAAAG,WAAA,GAAAH,OAAA;AAAA,SAAAD,wBAAAK,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAP,uBAAA,YAAAA,CAAAK,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA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;IACRE,MAAM,EAAE,CAAC;IACTC,eAAe,EAAE,aAAa;IAC9BsB,WAAW,EAAE,OAAO;IACpBC,eAAe,EAAE,aAAa;IAC9BC,gBAAgB,EAAE;EACpB;AACF,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "ConfettiCanvas", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _ConfettiCanvas.ConfettiCanvas;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "presets", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _presets.presets;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "useConfetti", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _useConfetti.useConfetti;
22
+ }
23
+ });
24
+ var _ConfettiCanvas = require("./ConfettiCanvas");
25
+ var _useConfetti = require("./useConfetti");
26
+ var _presets = require("./presets");
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_ConfettiCanvas","require","_useConfetti","_presets"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}