-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGradientText.js
59 lines (56 loc) · 1.69 KB
/
GradientText.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import MaskedView from '@react-native-masked-view/masked-view';
import LinearGradient from 'react-native-linear-gradient';
// Reusable GradientText component
const GradientText = ({
text = 'Colorful Text', // Default text
colors = ['#FF6B6B', '#FFD93D'], // Default gradient colors
start = { x: 0, y: 0 }, // Default gradient start point
end = { x: 1, y: 1 }, // Default gradient end point
textStyle = {}, // Customizable text styles
gradientStyle = {}, // Customizable gradient styles
backgroundColor = '#fff' // Default background color (white)
}) => {
return (
<View style={[styles.container, { backgroundColor }]}>
<MaskedView
maskElement={
<View style={styles.maskContainer}>
<Text style={[styles.text, textStyle]}>{text}</Text>
</View>
}
>
{/* Gradient background */}
<LinearGradient
colors={colors}
start={start}
end={end}
style={[styles.gradient, gradientStyle]}
/>
</MaskedView>
</View>
);
};
// Default styles for the component
const styles = StyleSheet.create({
container: {
justifyContent: 'center',
alignItems: 'center',
},
maskContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
text: {
fontSize: 40,
fontWeight: 'bold',
color: 'black', // The text color for the mask
},
gradient: {
height: 60, // Default height for the gradient
width: 300, // Default width for the gradient
},
});
export default GradientText;