nativebits-animated-text 0.0.0-stage → 0.1.1

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 +564 -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,255 @@
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
+ cancelAnimation,
10
+ Easing,
11
+ useAnimatedStyle,
12
+ useSharedValue,
13
+ withDelay,
14
+ withRepeat,
15
+ withSequence,
16
+ withTiming,
17
+ } from 'react-native-reanimated';
18
+
19
+ export interface RevealTextProps {
20
+ text: string;
21
+ direction?: 'left' | 'right' | 'top' | 'bottom';
22
+ duration?: number;
23
+ delay?: number;
24
+ stagger?: number;
25
+ mode?: 'word' | 'character';
26
+ fade?: boolean;
27
+ slide?: boolean;
28
+ slideDistance?: number;
29
+ loop?: boolean;
30
+ style?: TextStyle;
31
+ characterStyle?: TextStyle;
32
+ containerStyle?: ViewStyle;
33
+ }
34
+
35
+ interface RevealCharacterProps {
36
+ character: string;
37
+ index: number;
38
+ duration: number;
39
+ delay: number;
40
+ direction: RevealTextProps['direction'];
41
+ fade: boolean;
42
+ slide: boolean;
43
+ slideDistance: number;
44
+ style?: TextStyle;
45
+ }
46
+
47
+ const RevealCharacter = ({
48
+ character,
49
+ index,
50
+ duration,
51
+ delay,
52
+ direction,
53
+ fade,
54
+ slide,
55
+ slideDistance,
56
+ style,
57
+ }: RevealCharacterProps) => {
58
+ const progress = useSharedValue(0);
59
+
60
+ useEffect(() => {
61
+ progress.value = withDelay(
62
+ delay,
63
+ withTiming(1, {
64
+ duration,
65
+ easing: Easing.out(Easing.cubic),
66
+ }),
67
+ );
68
+
69
+ return () => cancelAnimation(progress);
70
+ }, [delay, duration, progress]);
71
+
72
+ const animatedStyle = useAnimatedStyle(() => {
73
+ const offset = slide
74
+ ? slideDistance * (1 - progress.value)
75
+ : 0;
76
+
77
+ const translateX =
78
+ direction === 'left'
79
+ ? -offset
80
+ : direction === 'right'
81
+ ? offset
82
+ : 0;
83
+
84
+ const translateY =
85
+ direction === 'top'
86
+ ? -offset
87
+ : direction === 'bottom'
88
+ ? offset
89
+ : 0;
90
+
91
+ return {
92
+ opacity: fade ? progress.value : 1,
93
+ transform: [
94
+ { translateX },
95
+ { translateY },
96
+ ],
97
+ };
98
+ });
99
+
100
+ return (
101
+ <View
102
+ style={{
103
+ overflow: 'hidden',
104
+ }}
105
+ >
106
+ <Animated.Text
107
+ style={[
108
+ style,
109
+ animatedStyle,
110
+ ]}
111
+ >
112
+ {character === ' ' ? '\u00A0' : character}
113
+ </Animated.Text>
114
+ </View>
115
+ );
116
+ };
117
+
118
+ export const RevealText = ({
119
+ text,
120
+ direction = 'left',
121
+ duration = 700,
122
+ delay = 0,
123
+ stagger = 45,
124
+ mode = 'character',
125
+ fade = true,
126
+ slide = false,
127
+ slideDistance = 20,
128
+ loop = false,
129
+ style,
130
+ characterStyle,
131
+ containerStyle,
132
+ }: RevealTextProps) => {
133
+ const progress = useSharedValue(0);
134
+
135
+ useEffect(() => {
136
+ cancelAnimation(progress);
137
+ progress.value = 0;
138
+
139
+ const animation = withTiming(1, {
140
+ duration,
141
+ easing: Easing.out(Easing.cubic),
142
+ });
143
+
144
+ progress.value = withDelay(
145
+ delay,
146
+ loop
147
+ ? withRepeat(
148
+ withSequence(
149
+ animation,
150
+ withTiming(0, { duration: 400 }),
151
+ ),
152
+ -1,
153
+ false,
154
+ )
155
+ : animation,
156
+ );
157
+
158
+ return () => cancelAnimation(progress);
159
+ }, [duration, delay, loop, progress]);
160
+
161
+ const wholeTextStyle = useAnimatedStyle(() => {
162
+ const offset = slide
163
+ ? slideDistance * (1 - progress.value)
164
+ : 0;
165
+
166
+ return {
167
+ opacity: fade ? progress.value : 1,
168
+ transform: [
169
+ {
170
+ translateX:
171
+ direction === 'left'
172
+ ? -offset
173
+ : direction === 'right'
174
+ ? offset
175
+ : 0,
176
+ },
177
+ {
178
+ translateY:
179
+ direction === 'top'
180
+ ? -offset
181
+ : direction === 'bottom'
182
+ ? offset
183
+ : 0,
184
+ },
185
+ ],
186
+ };
187
+ });
188
+
189
+ const characters = Array.from(text);
190
+
191
+ if (mode === 'word') {
192
+ return (
193
+ <View
194
+ style={[
195
+ {
196
+ flexDirection: 'row',
197
+ flexWrap: 'wrap',
198
+ },
199
+ containerStyle,
200
+ ]}
201
+ >
202
+ {text.split(/(\s+)/).map((word, index) => {
203
+ if (/^\s+$/.test(word)) {
204
+ return (
205
+ <Animated.Text key={`space-${index}`} style={style}>
206
+ {word}
207
+ </Animated.Text>
208
+ );
209
+ }
210
+
211
+ return (
212
+ <View
213
+ key={`word-${index}`}
214
+ style={{ overflow: 'hidden' }}
215
+ >
216
+ <Animated.Text style={[style, wholeTextStyle]}>
217
+ {word}
218
+ </Animated.Text>
219
+ </View>
220
+ );
221
+ })}
222
+ </View>
223
+ );
224
+ }
225
+
226
+ return (
227
+ <View
228
+ style={[
229
+ {
230
+ flexDirection: 'row',
231
+ flexWrap: 'wrap',
232
+ },
233
+ containerStyle,
234
+ ]}
235
+ >
236
+ {characters.map((character, index) => (
237
+ <RevealCharacter
238
+ key={`${index}-${character}`}
239
+ character={character}
240
+ index={index}
241
+ duration={duration}
242
+ delay={delay + index * stagger}
243
+ direction={direction}
244
+ fade={fade}
245
+ slide={slide}
246
+ slideDistance={slideDistance}
247
+ style={{
248
+ ...style,
249
+ ...characterStyle,
250
+ }}
251
+ />
252
+ ))}
253
+ </View>
254
+ );
255
+ };
@@ -0,0 +1,179 @@
1
+
2
+ import React, { useEffect } from 'react';
3
+ import {
4
+ View,
5
+ type TextStyle,
6
+ type ViewStyle,
7
+ } from 'react-native';
8
+
9
+ import Animated, {
10
+ cancelAnimation,
11
+ Easing,
12
+ useAnimatedStyle,
13
+ useSharedValue,
14
+ withDelay,
15
+ withRepeat,
16
+ withSequence,
17
+ withTiming,
18
+ } from 'react-native-reanimated';
19
+
20
+ export interface RotateTextProps {
21
+ text: string;
22
+ duration?: number;
23
+ stagger?: number;
24
+ delay?: number;
25
+ rotation?: number;
26
+ axis?: 'x' | 'y' | 'z';
27
+ perspective?: number;
28
+ loop?: boolean;
29
+ style?: TextStyle;
30
+ characterStyle?: TextStyle;
31
+ containerStyle?: ViewStyle;
32
+ }
33
+
34
+ interface AnimatedCharacterProps {
35
+ character: string;
36
+ index: number;
37
+ duration: number;
38
+ stagger: number;
39
+ delay: number;
40
+ rotation: number;
41
+ axis: 'x' | 'y' | 'z';
42
+ perspective: number;
43
+ loop: boolean;
44
+ style?: TextStyle;
45
+ characterStyle?: TextStyle;
46
+ }
47
+
48
+ function AnimatedCharacter({
49
+ character,
50
+ index,
51
+ duration,
52
+ stagger,
53
+ delay,
54
+ rotation,
55
+ axis,
56
+ perspective,
57
+ loop,
58
+ style,
59
+ characterStyle,
60
+ }: AnimatedCharacterProps) {
61
+ const rotate = useSharedValue(rotation);
62
+
63
+ useEffect(() => {
64
+ cancelAnimation(rotate);
65
+ rotate.value = rotation;
66
+
67
+ const animation = loop
68
+ ? withRepeat(
69
+ withSequence(
70
+ withTiming(0, {
71
+ duration,
72
+ easing: Easing.out(Easing.cubic),
73
+ }),
74
+ withTiming(rotation, {
75
+ duration,
76
+ easing: Easing.inOut(Easing.ease),
77
+ })
78
+ ),
79
+ -1,
80
+ false
81
+ )
82
+ : withTiming(0, {
83
+ duration,
84
+ easing: Easing.out(Easing.cubic),
85
+ });
86
+
87
+ rotate.value = withDelay(
88
+ delay + index * stagger,
89
+ animation
90
+ );
91
+
92
+ return () => cancelAnimation(rotate);
93
+ }, [
94
+ rotation,
95
+ duration,
96
+ stagger,
97
+ delay,
98
+ index,
99
+ loop,
100
+ rotate,
101
+ ]);
102
+
103
+ const animatedStyle = useAnimatedStyle(() => {
104
+ const transform =
105
+ axis === 'x'
106
+ ? [
107
+ { perspective },
108
+ { rotateX: `${rotate.value}deg` },
109
+ ]
110
+ : axis === 'y'
111
+ ? [
112
+ { perspective },
113
+ { rotateY: `${rotate.value}deg` },
114
+ ]
115
+ : [{ rotate: `${rotate.value}deg` }];
116
+
117
+ return {
118
+ transform,
119
+ };
120
+ });
121
+
122
+ return (
123
+ <Animated.Text
124
+ style={[
125
+ style,
126
+ characterStyle,
127
+ animatedStyle,
128
+ ]}
129
+ >
130
+ {character === ' ' ? '\u00A0' : character}
131
+ </Animated.Text>
132
+ );
133
+ }
134
+
135
+ export function RotateText({
136
+ text,
137
+ duration = 700,
138
+ stagger = 50,
139
+ delay = 0,
140
+ rotation = 90,
141
+ axis = 'y',
142
+ perspective = 600,
143
+ loop = false,
144
+ style,
145
+ characterStyle,
146
+ containerStyle,
147
+ }: RotateTextProps) {
148
+ const characters = Array.from(text);
149
+
150
+ return (
151
+ <View
152
+ style={[
153
+ {
154
+ flexDirection: 'row',
155
+ flexWrap: 'wrap',
156
+ alignItems: 'center',
157
+ },
158
+ containerStyle,
159
+ ]}
160
+ >
161
+ {characters.map((character, index) => (
162
+ <AnimatedCharacter
163
+ key={`${index}-${character}`}
164
+ character={character}
165
+ index={index}
166
+ duration={duration}
167
+ stagger={stagger}
168
+ delay={delay}
169
+ rotation={rotation}
170
+ axis={axis}
171
+ perspective={perspective}
172
+ loop={loop}
173
+ style={style}
174
+ characterStyle={characterStyle}
175
+ />
176
+ ))}
177
+ </View>
178
+ );
179
+ }
@@ -0,0 +1,137 @@
1
+
2
+ import React, { useEffect, useState } from 'react';
3
+ import {
4
+ Text,
5
+ View,
6
+ type TextStyle,
7
+ type ViewStyle,
8
+ } from 'react-native';
9
+
10
+ export interface ScrambleTextProps {
11
+ text: string;
12
+ characters?: string;
13
+ speed?: number;
14
+ delay?: number;
15
+ pauseDuration?: number;
16
+ loop?: boolean;
17
+ style?: TextStyle;
18
+ containerStyle?: ViewStyle;
19
+ }
20
+
21
+ const DEFAULT_CHARACTERS =
22
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*';
23
+
24
+ function getRandomCharacter(characters: string) {
25
+ const availableCharacters = Array.from(characters);
26
+
27
+ if (availableCharacters.length === 0) {
28
+ return '';
29
+ }
30
+
31
+ const randomIndex = Math.floor(
32
+ Math.random() * availableCharacters.length
33
+ );
34
+
35
+ return availableCharacters[randomIndex];
36
+ }
37
+
38
+ function scrambleText(text: string, characters: string) {
39
+ return Array.from(text)
40
+ .map((character) => {
41
+ if (character === ' ') {
42
+ return ' ';
43
+ }
44
+
45
+ return getRandomCharacter(characters);
46
+ })
47
+ .join('');
48
+ }
49
+
50
+ export function ScrambleText({
51
+ text,
52
+ characters = DEFAULT_CHARACTERS,
53
+ speed = 50,
54
+ delay = 0,
55
+ pauseDuration = 1500,
56
+ loop = false,
57
+ style,
58
+ containerStyle,
59
+ }: ScrambleTextProps) {
60
+ const [displayedText, setDisplayedText] = useState(() =>
61
+ scrambleText(text, characters)
62
+ );
63
+
64
+ useEffect(() => {
65
+ const targetCharacters = Array.from(text);
66
+
67
+ let currentIndex = 0;
68
+ let timeout: ReturnType<typeof setTimeout>;
69
+
70
+ const randomizeRemaining = (revealedCount: number) => {
71
+ return targetCharacters
72
+ .map((character, index) => {
73
+ if (character === ' ') {
74
+ return ' ';
75
+ }
76
+
77
+ if (index < revealedCount) {
78
+ return character;
79
+ }
80
+
81
+ return getRandomCharacter(characters);
82
+ })
83
+ .join('');
84
+ };
85
+
86
+ const revealNext = () => {
87
+ if (currentIndex >= targetCharacters.length) {
88
+ if (loop) {
89
+ timeout = setTimeout(() => {
90
+ currentIndex = 0;
91
+ setDisplayedText(
92
+ scrambleText(text, characters)
93
+ );
94
+ revealNext();
95
+ }, Math.max(0, pauseDuration));
96
+ }
97
+
98
+ return;
99
+ }
100
+
101
+ currentIndex += 1;
102
+
103
+ setDisplayedText(
104
+ randomizeRemaining(currentIndex)
105
+ );
106
+
107
+ timeout = setTimeout(
108
+ revealNext,
109
+ Math.max(1, speed)
110
+ );
111
+ };
112
+
113
+ setDisplayedText(scrambleText(text, characters));
114
+
115
+ timeout = setTimeout(
116
+ revealNext,
117
+ Math.max(0, delay)
118
+ );
119
+
120
+ return () => clearTimeout(timeout);
121
+ }, [
122
+ text,
123
+ characters,
124
+ speed,
125
+ delay,
126
+ pauseDuration,
127
+ loop,
128
+ ]);
129
+
130
+ return (
131
+ <View style={containerStyle}>
132
+ <Text style={style}>
133
+ {displayedText}
134
+ </Text>
135
+ </View>
136
+ );
137
+ }
@@ -0,0 +1,163 @@
1
+
2
+ import React, { useEffect, useMemo } from 'react';
3
+ import {
4
+ View,
5
+ type TextStyle,
6
+ type ViewStyle,
7
+ } from 'react-native';
8
+
9
+ import {
10
+ Canvas,
11
+ Group,
12
+ LinearGradient,
13
+ matchFont,
14
+ Text as SkiaText,
15
+ vec,
16
+ } from '@shopify/react-native-skia';
17
+
18
+ import {
19
+ cancelAnimation,
20
+ Easing,
21
+ useDerivedValue,
22
+ useSharedValue,
23
+ withDelay,
24
+ withRepeat,
25
+ withTiming,
26
+ } from 'react-native-reanimated';
27
+
28
+ export interface ShinyTextProps {
29
+ text: string;
30
+ color?: string;
31
+ shineColor?: string;
32
+ duration?: number;
33
+ delay?: number;
34
+ loop?: boolean;
35
+ shineWidth?: number;
36
+ style?: TextStyle;
37
+ containerStyle?: ViewStyle;
38
+ }
39
+
40
+ export const ShinyText = ({
41
+ text,
42
+ color = '#808080',
43
+ shineColor = '#FFFFFF',
44
+ duration = 2000,
45
+ delay = 0,
46
+ loop = true,
47
+ shineWidth = 0.2,
48
+ style,
49
+ containerStyle,
50
+ }: ShinyTextProps) => {
51
+ const fontSize = Number(style?.fontSize ?? 32);
52
+ const fontFamily = style?.fontFamily ?? 'Arial';
53
+
54
+ const fontWeight =
55
+ style?.fontWeight === 'bold' ? 'bold' : 'normal';
56
+
57
+ const fontStyle =
58
+ style?.fontStyle === 'italic' ? 'italic' : 'normal';
59
+
60
+ const font = useMemo(
61
+ () =>
62
+ matchFont({
63
+ fontFamily,
64
+ fontSize,
65
+ fontWeight,
66
+ fontStyle,
67
+ }),
68
+ [fontFamily, fontSize, fontWeight, fontStyle],
69
+ );
70
+
71
+ const textWidth = Math.max(1, font.measureText(text).width);
72
+ const metrics = font.getMetrics();
73
+
74
+ const padding = Math.ceil(fontSize * 0.2);
75
+
76
+ const canvasHeight =
77
+ metrics.descent - metrics.ascent + padding * 2;
78
+
79
+ const baseline = -metrics.ascent + padding;
80
+
81
+ const progress = useSharedValue(0);
82
+
83
+ useEffect(() => {
84
+ progress.value = withDelay(
85
+ delay,
86
+ withRepeat(
87
+ withTiming(1, {
88
+ duration,
89
+ easing: Easing.linear,
90
+ }),
91
+ loop ? -1 : 1,
92
+ false,
93
+ ),
94
+ );
95
+
96
+ return () => cancelAnimation(progress);
97
+ }, [delay, duration, loop, progress]);
98
+
99
+ const gradientTransform = useDerivedValue(() => {
100
+ return [
101
+ {
102
+ translateX:
103
+ -textWidth + progress.value * textWidth * 2,
104
+ },
105
+ ];
106
+ });
107
+
108
+ const shineStart = Math.max(
109
+ 0,
110
+ 0.5 - shineWidth / 2,
111
+ );
112
+
113
+ const shineEnd = Math.min(
114
+ 1,
115
+ 0.5 + shineWidth / 2,
116
+ );
117
+
118
+ return (
119
+ <View style={containerStyle}>
120
+ <Canvas
121
+ style={{
122
+ width: textWidth + padding * 2,
123
+ height: canvasHeight,
124
+ }}
125
+ >
126
+ {/* Original text */}
127
+ <SkiaText
128
+ x={padding}
129
+ y={baseline}
130
+ text={text}
131
+ font={font}
132
+ color={color}
133
+ />
134
+
135
+ {/* Moving shine reflection */}
136
+ <Group>
137
+ <SkiaText
138
+ x={padding}
139
+ y={baseline}
140
+ text={text}
141
+ font={font}
142
+ >
143
+ <LinearGradient
144
+ start={vec(0, 0)}
145
+ end={vec(textWidth, 0)}
146
+ colors={[
147
+ 'rgba(255,255,255,0)',
148
+ shineColor,
149
+ 'rgba(255,255,255,0)',
150
+ ]}
151
+ positions={[
152
+ shineStart,
153
+ 0.5,
154
+ shineEnd,
155
+ ]}
156
+ transform={gradientTransform}
157
+ />
158
+ </SkiaText>
159
+ </Group>
160
+ </Canvas>
161
+ </View>
162
+ );
163
+ };