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.
- package/LICENSE +17 -0
- package/README.md +564 -2
- package/docs/android-demo.gif +0 -0
- package/lib/commonjs/index.js +146 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/text/BlurText.js +146 -0
- package/lib/commonjs/text/BlurText.js.map +1 -0
- package/lib/commonjs/text/BounceText.js +83 -0
- package/lib/commonjs/text/BounceText.js.map +1 -0
- package/lib/commonjs/text/CountUpText.js +77 -0
- package/lib/commonjs/text/CountUpText.js.map +1 -0
- package/lib/commonjs/text/ElasticText.js +85 -0
- package/lib/commonjs/text/ElasticText.js.map +1 -0
- package/lib/commonjs/text/ExplosionText.js +191 -0
- package/lib/commonjs/text/ExplosionText.js.map +1 -0
- package/lib/commonjs/text/FlipText.js +101 -0
- package/lib/commonjs/text/FlipText.js.map +1 -0
- package/lib/commonjs/text/GlitchText.js +329 -0
- package/lib/commonjs/text/GlitchText.js.map +1 -0
- package/lib/commonjs/text/GradientText.js +73 -0
- package/lib/commonjs/text/GradientText.js.map +1 -0
- package/lib/commonjs/text/MorphText.js +192 -0
- package/lib/commonjs/text/MorphText.js.map +1 -0
- package/lib/commonjs/text/NeonText.js +134 -0
- package/lib/commonjs/text/NeonText.js.map +1 -0
- package/lib/commonjs/text/ParticleText.js +328 -0
- package/lib/commonjs/text/ParticleText.js.map +1 -0
- package/lib/commonjs/text/RevealText.js +142 -0
- package/lib/commonjs/text/RevealText.js.map +1 -0
- package/lib/commonjs/text/RotateText.js +99 -0
- package/lib/commonjs/text/RotateText.js.map +1 -0
- package/lib/commonjs/text/ScrambleText.js +82 -0
- package/lib/commonjs/text/ScrambleText.js.map +1 -0
- package/lib/commonjs/text/ShinyText.js +87 -0
- package/lib/commonjs/text/ShinyText.js.map +1 -0
- package/lib/commonjs/text/SplitText.js +81 -0
- package/lib/commonjs/text/SplitText.js.map +1 -0
- package/lib/commonjs/text/TextWave.js +130 -0
- package/lib/commonjs/text/TextWave.js.map +1 -0
- package/lib/commonjs/text/ThreeDText.js +145 -0
- package/lib/commonjs/text/ThreeDText.js.map +1 -0
- package/lib/commonjs/text/TypewriterText.js +119 -0
- package/lib/commonjs/text/TypewriterText.js.map +1 -0
- package/lib/commonjs/text/WaveText.js +79 -0
- package/lib/commonjs/text/WaveText.js.map +1 -0
- package/lib/module/index.js +23 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/text/BlurText.js +139 -0
- package/lib/module/text/BlurText.js.map +1 -0
- package/lib/module/text/BounceText.js +77 -0
- package/lib/module/text/BounceText.js.map +1 -0
- package/lib/module/text/CountUpText.js +70 -0
- package/lib/module/text/CountUpText.js.map +1 -0
- package/lib/module/text/ElasticText.js +78 -0
- package/lib/module/text/ElasticText.js.map +1 -0
- package/lib/module/text/ExplosionText.js +184 -0
- package/lib/module/text/ExplosionText.js.map +1 -0
- package/lib/module/text/FlipText.js +94 -0
- package/lib/module/text/FlipText.js.map +1 -0
- package/lib/module/text/GlitchText.js +322 -0
- package/lib/module/text/GlitchText.js.map +1 -0
- package/lib/module/text/GradientText.js +66 -0
- package/lib/module/text/GradientText.js.map +1 -0
- package/lib/module/text/MorphText.js +185 -0
- package/lib/module/text/MorphText.js.map +1 -0
- package/lib/module/text/NeonText.js +127 -0
- package/lib/module/text/NeonText.js.map +1 -0
- package/lib/module/text/ParticleText.js +321 -0
- package/lib/module/text/ParticleText.js.map +1 -0
- package/lib/module/text/RevealText.js +135 -0
- package/lib/module/text/RevealText.js.map +1 -0
- package/lib/module/text/RotateText.js +93 -0
- package/lib/module/text/RotateText.js.map +1 -0
- package/lib/module/text/ScrambleText.js +76 -0
- package/lib/module/text/ScrambleText.js.map +1 -0
- package/lib/module/text/ShinyText.js +80 -0
- package/lib/module/text/ShinyText.js.map +1 -0
- package/lib/module/text/SplitText.js +74 -0
- package/lib/module/text/SplitText.js.map +1 -0
- package/lib/module/text/TextWave.js +123 -0
- package/lib/module/text/TextWave.js.map +1 -0
- package/lib/module/text/ThreeDText.js +138 -0
- package/lib/module/text/ThreeDText.js.map +1 -0
- package/lib/module/text/TypewriterText.js +113 -0
- package/lib/module/text/TypewriterText.js.map +1 -0
- package/lib/module/text/WaveText.js +72 -0
- package/lib/module/text/WaveText.js.map +1 -0
- package/lib/typescript/index.d.ts +41 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/text/BlurText.d.ts +16 -0
- package/lib/typescript/text/BlurText.d.ts.map +1 -0
- package/lib/typescript/text/BounceText.d.ts +15 -0
- package/lib/typescript/text/BounceText.d.ts.map +1 -0
- package/lib/typescript/text/CountUpText.d.ts +20 -0
- package/lib/typescript/text/CountUpText.d.ts.map +1 -0
- package/lib/typescript/text/ElasticText.d.ts +17 -0
- package/lib/typescript/text/ElasticText.d.ts.map +1 -0
- package/lib/typescript/text/ExplosionText.d.ts +23 -0
- package/lib/typescript/text/ExplosionText.d.ts.map +1 -0
- package/lib/typescript/text/FlipText.d.ts +17 -0
- package/lib/typescript/text/FlipText.d.ts.map +1 -0
- package/lib/typescript/text/GlitchText.d.ts +19 -0
- package/lib/typescript/text/GlitchText.d.ts.map +1 -0
- package/lib/typescript/text/GradientText.d.ts +12 -0
- package/lib/typescript/text/GradientText.d.ts.map +1 -0
- package/lib/typescript/text/MorphText.d.ts +18 -0
- package/lib/typescript/text/MorphText.d.ts.map +1 -0
- package/lib/typescript/text/NeonText.d.ts +16 -0
- package/lib/typescript/text/NeonText.d.ts.map +1 -0
- package/lib/typescript/text/ParticleText.d.ts +23 -0
- package/lib/typescript/text/ParticleText.d.ts.map +1 -0
- package/lib/typescript/text/RevealText.d.ts +19 -0
- package/lib/typescript/text/RevealText.d.ts.map +1 -0
- package/lib/typescript/text/RotateText.d.ts +17 -0
- package/lib/typescript/text/RotateText.d.ts.map +1 -0
- package/lib/typescript/text/ScrambleText.d.ts +14 -0
- package/lib/typescript/text/ScrambleText.d.ts.map +1 -0
- package/lib/typescript/text/ShinyText.d.ts +15 -0
- package/lib/typescript/text/ShinyText.d.ts.map +1 -0
- package/lib/typescript/text/SplitText.d.ts +28 -0
- package/lib/typescript/text/SplitText.d.ts.map +1 -0
- package/lib/typescript/text/TextWave.d.ts +15 -0
- package/lib/typescript/text/TextWave.d.ts.map +1 -0
- package/lib/typescript/text/ThreeDText.d.ts +24 -0
- package/lib/typescript/text/ThreeDText.d.ts.map +1 -0
- package/lib/typescript/text/TypewriterText.d.ts +21 -0
- package/lib/typescript/text/TypewriterText.d.ts.map +1 -0
- package/lib/typescript/text/WaveText.d.ts +14 -0
- package/lib/typescript/text/WaveText.d.ts.map +1 -0
- package/package.json +48 -4
- package/src/index.ts +45 -0
- package/src/text/BlurText.tsx +243 -0
- package/src/text/BounceText.tsx +158 -0
- package/src/text/CountUpText.tsx +153 -0
- package/src/text/ElasticText.tsx +143 -0
- package/src/text/ExplosionText.tsx +242 -0
- package/src/text/FlipText.tsx +161 -0
- package/src/text/GlitchText.tsx +525 -0
- package/src/text/GradientText.tsx +118 -0
- package/src/text/MorphText.tsx +305 -0
- package/src/text/NeonText.tsx +205 -0
- package/src/text/ParticleText.tsx +489 -0
- package/src/text/RevealText.tsx +255 -0
- package/src/text/RotateText.tsx +179 -0
- package/src/text/ScrambleText.tsx +137 -0
- package/src/text/ShinyText.tsx +163 -0
- package/src/text/SplitText.tsx +122 -0
- package/src/text/TextWave.tsx +223 -0
- package/src/text/ThreeDText.tsx +268 -0
- package/src/text/TypewriterText.tsx +189 -0
- 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
|
+
};
|