nativebits-animated-text 0.0.0-stage → 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 (152) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +562 -2
  3. package/docs/android-demo.gif +0 -0
  4. package/lib/commonjs/index.js +146 -0
  5. package/lib/commonjs/index.js.map +1 -0
  6. package/lib/commonjs/package.json +1 -0
  7. package/lib/commonjs/text/BlurText.js +146 -0
  8. package/lib/commonjs/text/BlurText.js.map +1 -0
  9. package/lib/commonjs/text/BounceText.js +83 -0
  10. package/lib/commonjs/text/BounceText.js.map +1 -0
  11. package/lib/commonjs/text/CountUpText.js +77 -0
  12. package/lib/commonjs/text/CountUpText.js.map +1 -0
  13. package/lib/commonjs/text/ElasticText.js +85 -0
  14. package/lib/commonjs/text/ElasticText.js.map +1 -0
  15. package/lib/commonjs/text/ExplosionText.js +191 -0
  16. package/lib/commonjs/text/ExplosionText.js.map +1 -0
  17. package/lib/commonjs/text/FlipText.js +101 -0
  18. package/lib/commonjs/text/FlipText.js.map +1 -0
  19. package/lib/commonjs/text/GlitchText.js +329 -0
  20. package/lib/commonjs/text/GlitchText.js.map +1 -0
  21. package/lib/commonjs/text/GradientText.js +73 -0
  22. package/lib/commonjs/text/GradientText.js.map +1 -0
  23. package/lib/commonjs/text/MorphText.js +192 -0
  24. package/lib/commonjs/text/MorphText.js.map +1 -0
  25. package/lib/commonjs/text/NeonText.js +134 -0
  26. package/lib/commonjs/text/NeonText.js.map +1 -0
  27. package/lib/commonjs/text/ParticleText.js +328 -0
  28. package/lib/commonjs/text/ParticleText.js.map +1 -0
  29. package/lib/commonjs/text/RevealText.js +142 -0
  30. package/lib/commonjs/text/RevealText.js.map +1 -0
  31. package/lib/commonjs/text/RotateText.js +99 -0
  32. package/lib/commonjs/text/RotateText.js.map +1 -0
  33. package/lib/commonjs/text/ScrambleText.js +82 -0
  34. package/lib/commonjs/text/ScrambleText.js.map +1 -0
  35. package/lib/commonjs/text/ShinyText.js +87 -0
  36. package/lib/commonjs/text/ShinyText.js.map +1 -0
  37. package/lib/commonjs/text/SplitText.js +81 -0
  38. package/lib/commonjs/text/SplitText.js.map +1 -0
  39. package/lib/commonjs/text/TextWave.js +130 -0
  40. package/lib/commonjs/text/TextWave.js.map +1 -0
  41. package/lib/commonjs/text/ThreeDText.js +145 -0
  42. package/lib/commonjs/text/ThreeDText.js.map +1 -0
  43. package/lib/commonjs/text/TypewriterText.js +119 -0
  44. package/lib/commonjs/text/TypewriterText.js.map +1 -0
  45. package/lib/commonjs/text/WaveText.js +79 -0
  46. package/lib/commonjs/text/WaveText.js.map +1 -0
  47. package/lib/module/index.js +23 -0
  48. package/lib/module/index.js.map +1 -0
  49. package/lib/module/text/BlurText.js +139 -0
  50. package/lib/module/text/BlurText.js.map +1 -0
  51. package/lib/module/text/BounceText.js +77 -0
  52. package/lib/module/text/BounceText.js.map +1 -0
  53. package/lib/module/text/CountUpText.js +70 -0
  54. package/lib/module/text/CountUpText.js.map +1 -0
  55. package/lib/module/text/ElasticText.js +78 -0
  56. package/lib/module/text/ElasticText.js.map +1 -0
  57. package/lib/module/text/ExplosionText.js +184 -0
  58. package/lib/module/text/ExplosionText.js.map +1 -0
  59. package/lib/module/text/FlipText.js +94 -0
  60. package/lib/module/text/FlipText.js.map +1 -0
  61. package/lib/module/text/GlitchText.js +322 -0
  62. package/lib/module/text/GlitchText.js.map +1 -0
  63. package/lib/module/text/GradientText.js +66 -0
  64. package/lib/module/text/GradientText.js.map +1 -0
  65. package/lib/module/text/MorphText.js +185 -0
  66. package/lib/module/text/MorphText.js.map +1 -0
  67. package/lib/module/text/NeonText.js +127 -0
  68. package/lib/module/text/NeonText.js.map +1 -0
  69. package/lib/module/text/ParticleText.js +321 -0
  70. package/lib/module/text/ParticleText.js.map +1 -0
  71. package/lib/module/text/RevealText.js +135 -0
  72. package/lib/module/text/RevealText.js.map +1 -0
  73. package/lib/module/text/RotateText.js +93 -0
  74. package/lib/module/text/RotateText.js.map +1 -0
  75. package/lib/module/text/ScrambleText.js +76 -0
  76. package/lib/module/text/ScrambleText.js.map +1 -0
  77. package/lib/module/text/ShinyText.js +80 -0
  78. package/lib/module/text/ShinyText.js.map +1 -0
  79. package/lib/module/text/SplitText.js +74 -0
  80. package/lib/module/text/SplitText.js.map +1 -0
  81. package/lib/module/text/TextWave.js +123 -0
  82. package/lib/module/text/TextWave.js.map +1 -0
  83. package/lib/module/text/ThreeDText.js +138 -0
  84. package/lib/module/text/ThreeDText.js.map +1 -0
  85. package/lib/module/text/TypewriterText.js +113 -0
  86. package/lib/module/text/TypewriterText.js.map +1 -0
  87. package/lib/module/text/WaveText.js +72 -0
  88. package/lib/module/text/WaveText.js.map +1 -0
  89. package/lib/typescript/index.d.ts +41 -0
  90. package/lib/typescript/index.d.ts.map +1 -0
  91. package/lib/typescript/text/BlurText.d.ts +16 -0
  92. package/lib/typescript/text/BlurText.d.ts.map +1 -0
  93. package/lib/typescript/text/BounceText.d.ts +15 -0
  94. package/lib/typescript/text/BounceText.d.ts.map +1 -0
  95. package/lib/typescript/text/CountUpText.d.ts +20 -0
  96. package/lib/typescript/text/CountUpText.d.ts.map +1 -0
  97. package/lib/typescript/text/ElasticText.d.ts +17 -0
  98. package/lib/typescript/text/ElasticText.d.ts.map +1 -0
  99. package/lib/typescript/text/ExplosionText.d.ts +23 -0
  100. package/lib/typescript/text/ExplosionText.d.ts.map +1 -0
  101. package/lib/typescript/text/FlipText.d.ts +17 -0
  102. package/lib/typescript/text/FlipText.d.ts.map +1 -0
  103. package/lib/typescript/text/GlitchText.d.ts +19 -0
  104. package/lib/typescript/text/GlitchText.d.ts.map +1 -0
  105. package/lib/typescript/text/GradientText.d.ts +12 -0
  106. package/lib/typescript/text/GradientText.d.ts.map +1 -0
  107. package/lib/typescript/text/MorphText.d.ts +18 -0
  108. package/lib/typescript/text/MorphText.d.ts.map +1 -0
  109. package/lib/typescript/text/NeonText.d.ts +16 -0
  110. package/lib/typescript/text/NeonText.d.ts.map +1 -0
  111. package/lib/typescript/text/ParticleText.d.ts +23 -0
  112. package/lib/typescript/text/ParticleText.d.ts.map +1 -0
  113. package/lib/typescript/text/RevealText.d.ts +19 -0
  114. package/lib/typescript/text/RevealText.d.ts.map +1 -0
  115. package/lib/typescript/text/RotateText.d.ts +17 -0
  116. package/lib/typescript/text/RotateText.d.ts.map +1 -0
  117. package/lib/typescript/text/ScrambleText.d.ts +14 -0
  118. package/lib/typescript/text/ScrambleText.d.ts.map +1 -0
  119. package/lib/typescript/text/ShinyText.d.ts +15 -0
  120. package/lib/typescript/text/ShinyText.d.ts.map +1 -0
  121. package/lib/typescript/text/SplitText.d.ts +28 -0
  122. package/lib/typescript/text/SplitText.d.ts.map +1 -0
  123. package/lib/typescript/text/TextWave.d.ts +15 -0
  124. package/lib/typescript/text/TextWave.d.ts.map +1 -0
  125. package/lib/typescript/text/ThreeDText.d.ts +24 -0
  126. package/lib/typescript/text/ThreeDText.d.ts.map +1 -0
  127. package/lib/typescript/text/TypewriterText.d.ts +21 -0
  128. package/lib/typescript/text/TypewriterText.d.ts.map +1 -0
  129. package/lib/typescript/text/WaveText.d.ts +14 -0
  130. package/lib/typescript/text/WaveText.d.ts.map +1 -0
  131. package/package.json +48 -4
  132. package/src/index.ts +45 -0
  133. package/src/text/BlurText.tsx +243 -0
  134. package/src/text/BounceText.tsx +158 -0
  135. package/src/text/CountUpText.tsx +153 -0
  136. package/src/text/ElasticText.tsx +143 -0
  137. package/src/text/ExplosionText.tsx +242 -0
  138. package/src/text/FlipText.tsx +161 -0
  139. package/src/text/GlitchText.tsx +525 -0
  140. package/src/text/GradientText.tsx +118 -0
  141. package/src/text/MorphText.tsx +305 -0
  142. package/src/text/NeonText.tsx +205 -0
  143. package/src/text/ParticleText.tsx +489 -0
  144. package/src/text/RevealText.tsx +255 -0
  145. package/src/text/RotateText.tsx +179 -0
  146. package/src/text/ScrambleText.tsx +137 -0
  147. package/src/text/ShinyText.tsx +163 -0
  148. package/src/text/SplitText.tsx +122 -0
  149. package/src/text/TextWave.tsx +223 -0
  150. package/src/text/ThreeDText.tsx +268 -0
  151. package/src/text/TypewriterText.tsx +189 -0
  152. package/src/text/WaveText.tsx +132 -0
@@ -0,0 +1,143 @@
1
+
2
+ import React, { useEffect } from 'react';
3
+ import {
4
+ Text,
5
+ View,
6
+ type TextStyle,
7
+ type ViewStyle,
8
+ } from 'react-native';
9
+ import Animated, {
10
+ cancelAnimation,
11
+ Easing,
12
+ useAnimatedStyle,
13
+ useSharedValue,
14
+ withRepeat,
15
+ withSequence,
16
+ withSpring,
17
+ withTiming,
18
+ } from 'react-native-reanimated';
19
+
20
+ export interface ElasticTextProps {
21
+ text: string;
22
+ duration?: number;
23
+ delay?: number;
24
+ amplitude?: number;
25
+ damping?: number;
26
+ stiffness?: number;
27
+ loop?: boolean;
28
+ pauseDuration?: number;
29
+ style?: TextStyle;
30
+ containerStyle?: ViewStyle;
31
+ }
32
+
33
+ export function ElasticText({
34
+ text,
35
+ duration = 220,
36
+ delay = 0,
37
+ amplitude = 0.5,
38
+ damping = 7,
39
+ stiffness = 160,
40
+ loop = false,
41
+ pauseDuration = 1000,
42
+ style,
43
+ containerStyle,
44
+ }: ElasticTextProps) {
45
+ const stretch = useSharedValue(0);
46
+
47
+ useEffect(() => {
48
+ const springConfig = {
49
+ damping,
50
+ stiffness,
51
+ };
52
+
53
+ const animation = withSequence(
54
+ // Stretch horizontally and squash vertically
55
+ withTiming(amplitude, {
56
+ duration,
57
+ easing: Easing.out(Easing.cubic),
58
+ }),
59
+
60
+ // Overshoot in the opposite direction
61
+ withTiming(-amplitude * 0.35, {
62
+ duration: duration * 0.65,
63
+ easing: Easing.out(Easing.quad),
64
+ }),
65
+
66
+ // Settle naturally
67
+ withSpring(0, springConfig),
68
+ );
69
+
70
+ const startAnimation = () => {
71
+ if (loop) {
72
+ stretch.value = withRepeat(
73
+ withSequence(
74
+ animation,
75
+ withTiming(0, { duration: pauseDuration }),
76
+ ),
77
+ -1,
78
+ false,
79
+ );
80
+ } else {
81
+ stretch.value = animation;
82
+ }
83
+ };
84
+
85
+ const timeout = setTimeout(startAnimation, delay);
86
+
87
+ return () => {
88
+ clearTimeout(timeout);
89
+ cancelAnimation(stretch);
90
+ };
91
+ }, [
92
+ amplitude,
93
+ damping,
94
+ delay,
95
+ duration,
96
+ loop,
97
+ pauseDuration,
98
+ stiffness,
99
+ stretch,
100
+ ]);
101
+
102
+ const animatedStyle = useAnimatedStyle(() => {
103
+ const value = stretch.value;
104
+
105
+ return {
106
+ transform: [
107
+ {
108
+ scaleX: 1 + value,
109
+ },
110
+ {
111
+ scaleY: 1 - value * 0.45,
112
+ },
113
+ ],
114
+ };
115
+ });
116
+
117
+ return (
118
+ <View
119
+ style={[
120
+ {
121
+ alignItems: 'center',
122
+ justifyContent: 'center',
123
+ overflow: 'visible',
124
+ },
125
+ containerStyle,
126
+ ]}
127
+ >
128
+ <Animated.Text
129
+ style={[
130
+ {
131
+ includeFontPadding: false,
132
+ },
133
+ style,
134
+ animatedStyle,
135
+ ]}
136
+ >
137
+ {text}
138
+ </Animated.Text>
139
+ </View>
140
+ );
141
+ }
142
+
143
+ export default ElasticText;
@@ -0,0 +1,242 @@
1
+ import React, { memo, useEffect, useMemo } from 'react';
2
+ import {
3
+ StyleSheet,
4
+ Text,
5
+ View,
6
+ type TextStyle,
7
+ type ViewStyle,
8
+ } from 'react-native';
9
+ import Animated, {
10
+ cancelAnimation,
11
+ Easing,
12
+ useAnimatedStyle,
13
+ useSharedValue,
14
+ withDelay,
15
+ withRepeat,
16
+ withTiming,
17
+ type SharedValue,
18
+ } from 'react-native-reanimated';
19
+
20
+ export interface ExplosionTextProps {
21
+ text: string;
22
+ /** Motion duration per character in milliseconds. */
23
+ duration?: number;
24
+ /** Initial delay in milliseconds. */
25
+ delay?: number;
26
+ /** Offset between visible characters in milliseconds. */
27
+ stagger?: number;
28
+ /** Travel distance in layout points. */
29
+ distance?: number;
30
+ /** Maximum rotation in degrees. Neighboring characters rotate in opposite directions. */
31
+ rotation?: number;
32
+ direction?: 'explode' | 'implode';
33
+ loop?: boolean;
34
+ fade?: boolean;
35
+ scale?: boolean;
36
+ style?: TextStyle;
37
+ containerStyle?: ViewStyle;
38
+ }
39
+
40
+ // Distribute consecutive characters around the origin without a repeating fan.
41
+ const GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
42
+
43
+ type GraphemeSegmenter = {
44
+ segment: (value: string) => Iterable<{ segment: string }>;
45
+ };
46
+
47
+ const Segmenter = typeof Intl === 'undefined'
48
+ ? undefined
49
+ : (Intl as typeof Intl & {
50
+ Segmenter?: new (locale?: string, options?: { granularity: 'grapheme' }) => GraphemeSegmenter;
51
+ }).Segmenter;
52
+ const segmenter = Segmenter
53
+ ? new Segmenter(undefined, { granularity: 'grapheme' })
54
+ : undefined;
55
+
56
+ const getTextLayout = (text: string) => {
57
+ let characterCount = 0;
58
+ const lines = text.split(/\r\n|[\n\r\u2028\u2029]/).map((line) => {
59
+ const runs = line.match(/[^ \t]+|[ \t]/g) ?? [];
60
+ return runs.map((run) => {
61
+ if (run === ' ' || run === '\t') {
62
+ return { space: run === ' ' ? '\u00a0' : run };
63
+ }
64
+ const characters = segmenter
65
+ ? Array.from(segmenter.segment(run), ({ segment }) => segment)
66
+ : Array.from(run);
67
+ return {
68
+ characters: characters.map((character) => ({ character, index: characterCount++ })),
69
+ };
70
+ });
71
+ });
72
+ return { lines, characterCount };
73
+ };
74
+
75
+ interface CharacterProps {
76
+ character: string;
77
+ index: number;
78
+ timeline: SharedValue<number>;
79
+ duration: number;
80
+ stagger: number;
81
+ distance: number;
82
+ rotation: number;
83
+ implode: boolean;
84
+ fade: boolean;
85
+ scale: boolean;
86
+ style?: TextStyle;
87
+ }
88
+
89
+ const ExplosionCharacter = memo(({
90
+ character,
91
+ index,
92
+ timeline,
93
+ duration,
94
+ stagger,
95
+ distance,
96
+ rotation,
97
+ implode,
98
+ fade,
99
+ scale,
100
+ style,
101
+ }: CharacterProps) => {
102
+ const angle = index * GOLDEN_ANGLE;
103
+ const x = Math.cos(angle) * distance;
104
+ const y = Math.sin(angle) * distance;
105
+ const spin = index % 2 === 0 ? rotation : -rotation;
106
+ const offset = index * stagger;
107
+
108
+ const animatedStyle = useAnimatedStyle(() => {
109
+ const phase = Math.min(1, Math.max(0, (timeline.value - offset) / duration));
110
+ const eased = phase * phase * (3 - 2 * phase);
111
+ const spread = implode ? 1 - eased : eased;
112
+
113
+ return {
114
+ opacity: fade ? 1 - spread : 1,
115
+ transform: [
116
+ { translateX: x * spread },
117
+ { translateY: y * spread },
118
+ { rotate: `${spin * spread}deg` },
119
+ { scale: scale ? 1 - 0.65 * spread : 1 },
120
+ ],
121
+ };
122
+ });
123
+
124
+ return (
125
+ <Animated.Text style={[style, styles.character, animatedStyle]} accessible={false}>
126
+ {character}
127
+ </Animated.Text>
128
+ );
129
+ });
130
+
131
+ ExplosionCharacter.displayName = 'ExplosionCharacter';
132
+
133
+ export const ExplosionText = ({
134
+ text,
135
+ duration = 1800,
136
+ delay = 0,
137
+ stagger = 40,
138
+ distance = 100,
139
+ rotation = 180,
140
+ direction = 'explode',
141
+ loop = false,
142
+ fade = true,
143
+ scale = true,
144
+ style,
145
+ containerStyle,
146
+ }: ExplosionTextProps) => {
147
+ const layout = useMemo(() => getTextLayout(text), [text]);
148
+ const timeline = useSharedValue(0);
149
+ const characterDuration = Number.isFinite(duration) ? Math.max(1, duration) : 1800;
150
+ const characterStagger = Number.isFinite(stagger) ? Math.max(0, stagger) : 40;
151
+ const startDelay = Number.isFinite(delay) ? Math.max(0, delay) : 0;
152
+ const travel = Number.isFinite(distance) ? Math.max(0, distance) : 100;
153
+ const spin = Number.isFinite(rotation) ? rotation : 180;
154
+ const implode = direction === 'implode';
155
+
156
+ useEffect(() => {
157
+ timeline.value = 0;
158
+ if (layout.characterCount === 0) {
159
+ return;
160
+ }
161
+
162
+ // The shared clock runs linearly so each character controls its own stagger and easing.
163
+ const totalDuration = characterDuration + (layout.characterCount - 1) * characterStagger;
164
+ const timing = withTiming(totalDuration, { duration: totalDuration, easing: Easing.linear });
165
+ const animation = loop ? withRepeat(timing, -1, true) : timing;
166
+ timeline.value = startDelay > 0 ? withDelay(startDelay, animation) : animation;
167
+
168
+ return () => cancelAnimation(timeline);
169
+ }, [characterDuration, characterStagger, direction, layout, loop, startDelay, timeline]);
170
+
171
+ if (!text) {
172
+ return null;
173
+ }
174
+
175
+ const alignment: ViewStyle = {
176
+ justifyContent: style?.textAlign === 'center'
177
+ ? 'center'
178
+ : style?.textAlign === 'right' ? 'flex-end' : 'flex-start',
179
+ };
180
+
181
+ return (
182
+ <View accessible accessibilityLabel={text} style={[styles.container, containerStyle]}>
183
+ {layout.lines.map((runs, lineIndex) => (
184
+ <View key={lineIndex} style={[styles.line, alignment]}>
185
+ {runs.length === 0 && (
186
+ <Text style={style} accessible={false}>{'\u00a0'}</Text>
187
+ )}
188
+ {runs.map((run, runIndex) =>
189
+ run.characters ? (
190
+ <View key={runIndex} style={[styles.word, alignment]}>
191
+ {run.characters.map(({ character, index }) => (
192
+ <ExplosionCharacter
193
+ key={`${index}-${character}`}
194
+ character={character}
195
+ index={index}
196
+ timeline={timeline}
197
+ duration={characterDuration}
198
+ stagger={characterStagger}
199
+ distance={travel}
200
+ rotation={spin}
201
+ implode={implode}
202
+ fade={fade}
203
+ scale={scale}
204
+ style={style}
205
+ />
206
+ ))}
207
+ </View>
208
+ ) : (
209
+ <Text key={runIndex} style={[style, styles.character]} accessible={false}>
210
+ {run.space}
211
+ </Text>
212
+ )
213
+ )}
214
+ </View>
215
+ ))}
216
+ </View>
217
+ );
218
+ };
219
+
220
+ const styles = StyleSheet.create({
221
+ container: {
222
+ maxWidth: '100%',
223
+ overflow: 'visible',
224
+ },
225
+ line: {
226
+ flexDirection: 'row',
227
+ flexWrap: 'wrap',
228
+ alignItems: 'baseline',
229
+ alignSelf: 'stretch',
230
+ overflow: 'visible',
231
+ },
232
+ word: {
233
+ flexDirection: 'row',
234
+ flexWrap: 'wrap',
235
+ alignItems: 'baseline',
236
+ maxWidth: '100%',
237
+ overflow: 'visible',
238
+ },
239
+ character: {
240
+ flexShrink: 0,
241
+ },
242
+ });
@@ -0,0 +1,161 @@
1
+
2
+ import React, { useEffect } from 'react';
3
+ import {
4
+ View,
5
+ type TextStyle,
6
+ type ViewStyle,
7
+ } from 'react-native';
8
+ import Animated, {
9
+ Easing,
10
+ useAnimatedStyle,
11
+ useSharedValue,
12
+ withDelay,
13
+ withTiming,
14
+ } from 'react-native-reanimated';
15
+
16
+ export interface FlipTextProps {
17
+ text: string;
18
+ duration?: number;
19
+ stagger?: number;
20
+ delay?: number;
21
+ rotation?: number;
22
+ axis?: 'x' | 'y';
23
+ perspective?: number;
24
+ loop?: boolean;
25
+ style?: TextStyle;
26
+ characterStyle?: TextStyle;
27
+ containerStyle?: ViewStyle;
28
+ }
29
+
30
+ interface AnimatedCharacterProps {
31
+ character: string;
32
+ index: number;
33
+ duration: number;
34
+ stagger: number;
35
+ delay: number;
36
+ rotation: number;
37
+ axis: 'x' | 'y';
38
+ perspective: number;
39
+ loop: boolean;
40
+ style?: TextStyle;
41
+ characterStyle?: TextStyle;
42
+ }
43
+
44
+ const AnimatedCharacter = ({
45
+ character,
46
+ index,
47
+ duration,
48
+ stagger,
49
+ delay,
50
+ rotation,
51
+ axis,
52
+ perspective,
53
+ loop,
54
+ style,
55
+ characterStyle,
56
+ }: AnimatedCharacterProps) => {
57
+ const progress = useSharedValue(0);
58
+
59
+ useEffect(() => {
60
+ const animation = withTiming(
61
+ 1,
62
+ {
63
+ duration,
64
+ easing: Easing.out(Easing.cubic),
65
+ },
66
+ );
67
+
68
+ progress.value = withDelay(
69
+ delay + index * stagger,
70
+ loop
71
+ ? withTiming(1, {
72
+ duration,
73
+ easing: Easing.out(Easing.cubic),
74
+ })
75
+ : animation,
76
+ );
77
+
78
+ return () => {
79
+ progress.value = 0;
80
+ };
81
+ }, [duration, stagger, delay, index, loop, progress]);
82
+
83
+ const animatedStyle = useAnimatedStyle(() => {
84
+ const angle = rotation * (1 - progress.value);
85
+
86
+ if (axis === 'x') {
87
+ return {
88
+ opacity: progress.value,
89
+ transform: [
90
+ { perspective },
91
+ { rotateX: `${angle}deg` },
92
+ ],
93
+ };
94
+ }
95
+
96
+ return {
97
+ opacity: progress.value,
98
+ transform: [
99
+ { perspective },
100
+ { rotateY: `${angle}deg` },
101
+ ],
102
+ };
103
+ });
104
+
105
+ return (
106
+ <Animated.Text
107
+ style={[
108
+ style,
109
+ characterStyle,
110
+ animatedStyle,
111
+ ]}
112
+ >
113
+ {character === ' ' ? '\u00A0' : character}
114
+ </Animated.Text>
115
+ );
116
+ };
117
+
118
+ export const FlipText = ({
119
+ text,
120
+ duration = 600,
121
+ stagger = 60,
122
+ delay = 0,
123
+ rotation = 90,
124
+ axis = 'x',
125
+ perspective = 600,
126
+ loop = false,
127
+ style,
128
+ characterStyle,
129
+ containerStyle,
130
+ }: FlipTextProps) => {
131
+ const characters = Array.from(text);
132
+
133
+ return (
134
+ <View
135
+ style={[
136
+ {
137
+ flexDirection: 'row',
138
+ flexWrap: 'wrap',
139
+ },
140
+ containerStyle,
141
+ ]}
142
+ >
143
+ {characters.map((character, index) => (
144
+ <AnimatedCharacter
145
+ key={`${index}-${character}`}
146
+ character={character}
147
+ index={index}
148
+ duration={duration}
149
+ stagger={stagger}
150
+ delay={delay}
151
+ rotation={rotation}
152
+ axis={axis}
153
+ perspective={perspective}
154
+ loop={loop}
155
+ style={style}
156
+ characterStyle={characterStyle}
157
+ />
158
+ ))}
159
+ </View>
160
+ );
161
+ };