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,189 @@
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
+ import Animated, {
11
+ cancelAnimation,
12
+ Easing,
13
+ useAnimatedStyle,
14
+ useSharedValue,
15
+ withRepeat,
16
+ withTiming,
17
+ } from 'react-native-reanimated';
18
+
19
+ export interface TypewriterTextProps {
20
+ texts: string[];
21
+ typingSpeed?: number;
22
+ deletingSpeed?: number;
23
+ pauseDuration?: number;
24
+ loop?: boolean;
25
+
26
+ // Cursor customization
27
+ cursorWidth?: number;
28
+ cursorHeight?: number;
29
+ cursorColor?: string;
30
+ cursorBorderRadius?: number;
31
+ cursorMarginLeft?: number;
32
+
33
+ // Cursor animation
34
+ cursorAnimation?: 'blink' | 'pulse' | 'none';
35
+ cursorAnimationDuration?: number;
36
+
37
+ style?: TextStyle;
38
+ cursorStyle?: ViewStyle;
39
+ containerStyle?: ViewStyle;
40
+ }
41
+
42
+ export function TypewriterText({
43
+ texts,
44
+ typingSpeed = 80,
45
+ deletingSpeed = 40,
46
+ pauseDuration = 1500,
47
+ loop = false,
48
+
49
+ cursorWidth = 2,
50
+ cursorHeight = 26,
51
+ cursorColor = '#FFFFFF',
52
+ cursorBorderRadius = 2,
53
+ cursorMarginLeft = 3,
54
+
55
+ cursorAnimation = 'blink',
56
+ cursorAnimationDuration = 500,
57
+
58
+ style,
59
+ cursorStyle,
60
+ containerStyle,
61
+ }: TypewriterTextProps) {
62
+ const [displayedText, setDisplayedText] = useState('');
63
+ const [currentIndex, setCurrentIndex] = useState(0);
64
+ const [isDeleting, setIsDeleting] = useState(false);
65
+
66
+ // Typing and deleting logic
67
+ useEffect(() => {
68
+ if (texts.length === 0) {
69
+ setDisplayedText('');
70
+ return;
71
+ }
72
+
73
+ const currentText = texts[currentIndex] ?? '';
74
+
75
+ if (!isDeleting && displayedText === currentText) {
76
+ if (!loop && currentIndex === texts.length - 1) {
77
+ return;
78
+ }
79
+
80
+ const timeout = setTimeout(() => {
81
+ setIsDeleting(true);
82
+ }, pauseDuration);
83
+
84
+ return () => clearTimeout(timeout);
85
+ }
86
+
87
+ if (isDeleting && displayedText === '') {
88
+ setIsDeleting(false);
89
+ setCurrentIndex((previous) => (previous + 1) % texts.length);
90
+ return;
91
+ }
92
+
93
+ const timeout = setTimeout(() => {
94
+ if (isDeleting) {
95
+ setDisplayedText((previous) => previous.slice(0, -1));
96
+ } else {
97
+ setDisplayedText(
98
+ currentText.slice(0, displayedText.length + 1)
99
+ );
100
+ }
101
+ }, Math.max(0, isDeleting ? deletingSpeed : typingSpeed));
102
+
103
+ return () => clearTimeout(timeout);
104
+ }, [
105
+ texts,
106
+ currentIndex,
107
+ displayedText,
108
+ isDeleting,
109
+ typingSpeed,
110
+ deletingSpeed,
111
+ pauseDuration,
112
+ loop,
113
+ ]);
114
+
115
+ // Cursor animation values
116
+ const cursorOpacity = useSharedValue(1);
117
+ const cursorScale = useSharedValue(1);
118
+
119
+ useEffect(() => {
120
+ cancelAnimation(cursorOpacity);
121
+ cancelAnimation(cursorScale);
122
+
123
+ cursorOpacity.value = 1;
124
+ cursorScale.value = 1;
125
+
126
+ if (cursorAnimation === 'blink') {
127
+ cursorOpacity.value = withRepeat(
128
+ withTiming(0, {
129
+ duration: Math.max(1, cursorAnimationDuration / 2),
130
+ easing: Easing.linear,
131
+ }),
132
+ -1,
133
+ true
134
+ );
135
+ }
136
+
137
+ if (cursorAnimation === 'pulse') {
138
+ cursorOpacity.value = withRepeat(
139
+ withTiming(0.4, {
140
+ duration: Math.max(1, cursorAnimationDuration),
141
+ easing: Easing.inOut(Easing.ease),
142
+ }),
143
+ -1,
144
+ true
145
+ );
146
+
147
+ cursorScale.value = withRepeat(
148
+ withTiming(0.75, {
149
+ duration: Math.max(1, cursorAnimationDuration),
150
+ easing: Easing.inOut(Easing.ease),
151
+ }),
152
+ -1,
153
+ true
154
+ );
155
+ }
156
+
157
+ return () => {
158
+ cancelAnimation(cursorOpacity);
159
+ cancelAnimation(cursorScale);
160
+ };
161
+ }, [cursorAnimation, cursorAnimationDuration]);
162
+
163
+ const animatedCursorStyle = useAnimatedStyle(() => ({
164
+ opacity: cursorOpacity.value,
165
+ transform: [{ scaleY: cursorScale.value }],
166
+ }));
167
+
168
+ return (
169
+ <View style={containerStyle}>
170
+ <Text style={style}>
171
+ {displayedText}
172
+ <Animated.View
173
+ style={[
174
+ {
175
+ width: cursorWidth,
176
+ height: cursorHeight,
177
+ backgroundColor: cursorColor,
178
+ borderRadius: cursorBorderRadius,
179
+ marginLeft: cursorMarginLeft,
180
+ transform: [{ translateY: 2 }],
181
+ },
182
+ cursorStyle,
183
+ animatedCursorStyle,
184
+ ]}
185
+ />
186
+ </Text>
187
+ </View>
188
+ );
189
+ }
@@ -0,0 +1,132 @@
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
+ withTiming,
17
+ } from 'react-native-reanimated';
18
+
19
+ export interface WaveTextProps {
20
+ text: string;
21
+ duration?: number;
22
+ stagger?: number;
23
+ amplitude?: 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
+ amplitude: number;
36
+ loop: boolean;
37
+ style?: TextStyle;
38
+ characterStyle?: TextStyle;
39
+ }
40
+
41
+ const AnimatedCharacter = ({
42
+ character,
43
+ index,
44
+ duration,
45
+ stagger,
46
+ amplitude,
47
+ loop,
48
+ style,
49
+ characterStyle,
50
+ }: AnimatedCharacterProps) => {
51
+ const progress = useSharedValue(0);
52
+
53
+ useEffect(() => {
54
+ const animation = withTiming(
55
+ 1,
56
+ {
57
+ duration,
58
+ easing: Easing.inOut(Easing.sin),
59
+ },
60
+ );
61
+
62
+ progress.value = withDelay(
63
+ index * stagger,
64
+ loop
65
+ ? withRepeat(animation, -1, true)
66
+ : animation,
67
+ );
68
+
69
+ return () => {
70
+ cancelAnimation(progress);
71
+ };
72
+ }, [duration, index, stagger, loop]);
73
+
74
+ const animatedStyle = useAnimatedStyle(() => {
75
+ const translateY =
76
+ -Math.sin(progress.value * Math.PI) * amplitude;
77
+
78
+ return {
79
+ transform: [{ translateY }],
80
+ };
81
+ });
82
+
83
+ return (
84
+ <Animated.Text
85
+ style={[style, characterStyle, animatedStyle]}
86
+ >
87
+ {character === ' ' ? '\u00A0' : character}
88
+ </Animated.Text>
89
+ );
90
+ };
91
+
92
+ export const WaveText = ({
93
+ text,
94
+ duration = 500,
95
+ stagger = 80,
96
+ amplitude = 12,
97
+ style,
98
+ characterStyle,
99
+ containerStyle,
100
+ loop = false,
101
+ }: WaveTextProps) => {
102
+ const characters = Array.from(text);
103
+
104
+ return (
105
+ <View
106
+ accessible
107
+ accessibilityRole="text"
108
+ accessibilityLabel={text}
109
+ style={[
110
+ {
111
+ flexDirection: 'row',
112
+ flexWrap: 'wrap',
113
+ },
114
+ containerStyle,
115
+ ]}
116
+ >
117
+ {characters.map((character, index) => (
118
+ <AnimatedCharacter
119
+ key={`${index}-${character}`}
120
+ character={character}
121
+ index={index}
122
+ duration={duration}
123
+ stagger={stagger}
124
+ amplitude={amplitude}
125
+ loop={loop}
126
+ style={style}
127
+ characterStyle={characterStyle}
128
+ />
129
+ ))}
130
+ </View>
131
+ );
132
+ };