react-native-confetti-reanimated 0.1.0 → 0.1.2

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.
package/src/presets.ts CHANGED
@@ -5,122 +5,108 @@ import type { ConfettiConfig } from './types';
5
5
  */
6
6
 
7
7
  /**
8
- * Basic celebration with confetti from the center
8
+ * Basic Cannon - The default basic blast of confetti
9
9
  */
10
- export const celebration: ConfettiConfig = {
10
+ export const basicCannon: ConfettiConfig = {
11
11
  particleCount: 100,
12
12
  spread: 70,
13
13
  origin: { y: 0.6 },
14
14
  };
15
15
 
16
16
  /**
17
- * Fireworks effect
17
+ * Random Direction - Random amount in random directions
18
+ */
19
+ export const randomDirection: ConfettiConfig = {
20
+ particleCount: Math.floor(200 + Math.random() * 100),
21
+ angle: Math.random() * 360,
22
+ spread: 180 + Math.random() * 180,
23
+ origin: {
24
+ x: Math.random(),
25
+ y: Math.random() - 0.2,
26
+ },
27
+ startVelocity: 30 + Math.random() * 20,
28
+ };
29
+
30
+ /**
31
+ * Realistic Look - Mix multiple effects to avoid "flattened cone"
32
+ * Fires 3 bursts with varying parameters for natural look
33
+ */
34
+ export const realistic: ConfettiConfig = {
35
+ particleCount: 100, // Per burst (will fire 3x)
36
+ spread: 70,
37
+ startVelocity: 45,
38
+ decay: 0.91,
39
+ scalar: 1,
40
+ origin: { y: 0.7 },
41
+ };
42
+
43
+ /**
44
+ * Fireworks - From the sides
18
45
  */
19
46
  export const fireworks: ConfettiConfig = {
20
- particleCount: 150,
47
+ particleCount: 100,
21
48
  spread: 360,
22
49
  startVelocity: 30,
23
50
  decay: 0.94,
24
51
  scalar: 1.2,
52
+ origin: { y: 0.6 },
25
53
  };
26
54
 
27
55
  /**
28
- * Confetti from the bottom
56
+ * Stars - Burst of star shapes
29
57
  */
30
- export const bottomCannon: ConfettiConfig = {
58
+ export const stars: ConfettiConfig = {
31
59
  particleCount: 50,
32
- angle: 60,
33
- spread: 55,
34
- origin: { y: 0.8, x: 0.5 },
35
- startVelocity: 55,
60
+ spread: 360,
61
+ startVelocity: 20,
62
+ decay: 0.95,
63
+ gravity: 0.5,
64
+ shapes: ['star'],
65
+ scalar: 1.5, // Scaled appropriately for star character
66
+ colors: ['#FFD700', '#FFA500', '#FFFF00'],
36
67
  };
37
68
 
38
69
  /**
39
- * Confetti from left side
70
+ * Left Cannon - Confetti from left side
40
71
  */
41
72
  export const leftCannon: ConfettiConfig = {
42
73
  particleCount: 50,
43
- angle: 45,
74
+ angle: 60,
44
75
  spread: 55,
45
76
  origin: { x: 0, y: 0.6 },
46
77
  startVelocity: 55,
47
78
  };
48
79
 
49
80
  /**
50
- * Confetti from right side
81
+ * Right Cannon - Confetti from right side
51
82
  */
52
83
  export const rightCannon: ConfettiConfig = {
53
84
  particleCount: 50,
54
- angle: 135,
85
+ angle: 120,
55
86
  spread: 55,
56
87
  origin: { x: 1, y: 0.6 },
57
88
  startVelocity: 55,
58
89
  };
59
90
 
60
91
  /**
61
- * Realistic looking confetti
92
+ * Bottom Cannon - Confetti from bottom
62
93
  */
63
- export const realistic: ConfettiConfig = {
64
- particleCount: 200,
65
- spread: 160,
66
- origin: { y: 0.5 },
67
- startVelocity: 35,
68
- gravity: 1.5,
69
- drift: 1,
70
- tilt: true,
71
- shapes: ['square', 'circle', 'triangle'],
72
- scalar: 0.8,
73
- };
74
-
75
- /**
76
- * Snow effect
77
- */
78
- export const snow: ConfettiConfig = {
79
- particleCount: 100,
80
- spread: 180,
81
- origin: { y: -0.1 },
82
- startVelocity: 0,
83
- gravity: 0.3,
84
- drift: 1,
85
- colors: ['#ffffff', '#e8f4ff', '#c9e5ff'],
86
- shapes: ['circle'],
87
- scalar: 0.6,
88
- angle: 270,
89
- };
90
-
91
- /**
92
- * Stars effect
93
- */
94
- export const stars: ConfettiConfig = {
94
+ export const bottomCannon: ConfettiConfig = {
95
95
  particleCount: 50,
96
- spread: 360,
97
- startVelocity: 20,
98
- decay: 0.95,
99
- gravity: 0.5,
100
- colors: ['#FFD700', '#FFA500', '#FFFF00'],
101
- shapes: ['circle'],
102
- scalar: 0.5,
103
- };
104
-
105
- /**
106
- * School pride (custom colors)
107
- */
108
- export const schoolPride: ConfettiConfig = {
109
- particleCount: 100,
110
- spread: 160,
111
- origin: { y: 0.6 },
112
- colors: ['#bb0000', '#ffffff'],
96
+ angle: 90,
97
+ spread: 45,
98
+ origin: { y: 1, x: 0.5 },
99
+ startVelocity: 55,
113
100
  };
114
101
 
115
102
  export const presets = {
116
- celebration,
103
+ basicCannon,
104
+ randomDirection,
105
+ realistic,
117
106
  fireworks,
118
- bottomCannon,
107
+ stars,
119
108
  leftCannon,
120
109
  rightCannon,
121
- realistic,
122
- snow,
123
- stars,
124
- schoolPride,
110
+ bottomCannon,
125
111
  };
126
112
 
package/src/types.ts CHANGED
@@ -73,7 +73,7 @@ export interface ConfettiConfig {
73
73
  * Shapes for confetti
74
74
  * @default ['square', 'circle']
75
75
  */
76
- shapes?: Array<'square' | 'circle' | 'triangle'>;
76
+ shapes?: Array<'square' | 'circle' | 'star'>;
77
77
 
78
78
  /**
79
79
  * Whether the confetti should be affected by tilt
@@ -109,10 +109,11 @@ export interface ConfettiConfig {
109
109
  export interface ConfettiParticle {
110
110
  id: string;
111
111
  color: string;
112
- shape: 'square' | 'circle' | 'triangle';
112
+ shape: 'square' | 'circle' | 'star';
113
113
  x: number;
114
114
  y: number;
115
- size: number;
115
+ width: number;
116
+ height: number;
116
117
  velocity: {
117
118
  x: number;
118
119
  y: number;
package/src/utils.ts CHANGED
@@ -1,13 +1,30 @@
1
1
  import type { ConfettiConfig, ConfettiParticle } from './types';
2
2
 
3
+ // Canvas-confetti uses highly contrasting, distinct colors for realistic effect
4
+ // Each color is maximally different from others for clear visibility
3
5
  export const DEFAULT_COLORS = [
4
- '#26ccff',
5
- '#a25afd',
6
- '#ff5e7e',
7
- '#88ff5a',
8
- '#fcff42',
9
- '#ffa62d',
10
- '#ff36ff',
6
+ // Primary vibrant colors (maximally distinct)
7
+ '#26ccff', // Bright Cyan
8
+ '#a25afd', // Purple
9
+ '#ff5e7e', // Pink
10
+ '#88ff5a', // Lime Green
11
+ '#fcff42', // Yellow
12
+ '#ffa62d', // Orange
13
+ '#ff36ff', // Magenta
14
+ // Secondary distinct colors
15
+ '#1e90ff', // Dodger Blue
16
+ '#9400d3', // Dark Violet
17
+ '#ff1493', // Deep Pink
18
+ '#32cd32', // Lime
19
+ '#ffd700', // Gold
20
+ '#ff6347', // Tomato
21
+ '#00ffff', // Cyan
22
+ '#ff00ff', // Fuchsia
23
+ // Additional contrast colors
24
+ '#00ff00', // Pure Green
25
+ '#ff0000', // Pure Red
26
+ '#0000ff', // Pure Blue
27
+ '#ffff00', // Pure Yellow
11
28
  ];
12
29
 
13
30
  export const DEFAULT_CONFIG: Required<ConfettiConfig> = {
@@ -22,7 +39,7 @@ export const DEFAULT_CONFIG: Required<ConfettiConfig> = {
22
39
  colors: DEFAULT_COLORS,
23
40
  scalar: 1,
24
41
  origin: { x: 0.5, y: 0.5 },
25
- shapes: ['square', 'circle'],
42
+ shapes: ['square'], // Rectangular strips are most realistic
26
43
  tilt: true,
27
44
  tiltAngleIncrement: 10,
28
45
  tickDuration: 200,
@@ -61,29 +78,38 @@ export const randomFromArray = <T>(arr: T[]): T => {
61
78
  export const createConfettiParticles = (
62
79
  config: Required<ConfettiConfig>,
63
80
  screenWidth: number,
64
- screenHeight: number
81
+ screenHeight: number,
65
82
  ): ConfettiParticle[] => {
66
83
  const particles: ConfettiParticle[] = [];
67
84
  const angleInRadians = degreesToRadians(config.angle);
68
85
  const spreadInRadians = degreesToRadians(config.spread);
69
86
 
87
+ const timestamp = Date.now();
70
88
  for (let i = 0; i < config.particleCount; i++) {
71
- const angle = angleInRadians + randomRange(-spreadInRadians / 2, spreadInRadians / 2);
72
- const velocity = config.startVelocity * (0.5 + Math.random() * 0.5);
73
-
89
+ // Add spread variation to the angle
90
+ const spreadVariation = randomRange(-spreadInRadians / 2, spreadInRadians / 2);
91
+ const particleAngle = angleInRadians + spreadVariation;
92
+ // Randomize velocity within range
93
+ const velocityMagnitude = config.startVelocity * (0.5 + Math.random() * 0.5);
94
+ // Create confetti particles - broader and shorter like canvas-confetti
95
+ const baseWidth = (6 + Math.random() * 4) * config.scalar; // 6-10px wide (BROADER)
96
+ const aspectRatio = 0.5 + Math.random() * 0.3; // 0.5-0.8 ratio (SHORTER than wide)
74
97
  const particle: ConfettiParticle = {
75
- id: `confetti-${i}-${Date.now()}`,
98
+ id: `confetti-${timestamp}-${i}-${Math.random()}`,
76
99
  color: randomFromArray(config.colors),
77
100
  shape: randomFromArray(config.shapes),
78
101
  x: (config.origin.x ?? 0.5) * screenWidth,
79
102
  y: (config.origin.y ?? 0.5) * screenHeight,
80
- size: (5 + Math.random() * 5) * config.scalar,
103
+ width: baseWidth,
104
+ height: baseWidth * aspectRatio, // Height is SMALLER than width
81
105
  velocity: {
82
- x: Math.cos(angle) * velocity,
83
- y: Math.sin(angle) * velocity,
106
+ // Canvas-confetti uses pixels per frame (60fps)
107
+ // Use velocity as-is for proper scaling to device
108
+ x: Math.cos(particleAngle) * velocityMagnitude,
109
+ y: -Math.sin(particleAngle) * velocityMagnitude, // Negative = upward initially
84
110
  },
85
111
  rotation: Math.random() * 360,
86
- rotationVelocity: randomRange(-10, 10),
112
+ rotationVelocity: randomRange(-50, 50), // Very wide range for dramatic spinning
87
113
  tiltAngle: config.tilt ? Math.random() * config.tiltAngleIncrement : 0,
88
114
  opacity: 1,
89
115
  };
@@ -100,13 +126,12 @@ export const createConfettiParticles = (
100
126
  export const updateParticle = (
101
127
  particle: ConfettiParticle,
102
128
  config: Required<ConfettiConfig>,
103
- deltaTime: number
129
+ deltaTime: number,
104
130
  ): ConfettiParticle => {
105
131
  const dt = deltaTime / 16; // Normalize to 60fps
106
132
 
107
133
  // Apply gravity
108
134
  const newVelocityY = particle.velocity.y - config.gravity * dt;
109
-
110
135
  // Apply drift
111
136
  const newVelocityX = particle.velocity.x + config.drift * dt;
112
137
 
@@ -132,4 +157,3 @@ export const updateParticle = (
132
157
  opacity: newOpacity,
133
158
  };
134
159
  };
135
-
@@ -1 +0,0 @@
1
- {"type":"module"}