forked from hexboy/react-native-svg-dynamic-colors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
74 lines (67 loc) · 1.7 KB
/
App.tsx
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { useState } from 'react';
import { StyleSheet, Dimensions, View, Slider } from 'react-native';
import BallIcon from './src/ball.svg';
import AvatarIcon from './src/avatar.svg';
import MessageIcon from './src/heart.svg';
const { width } = Dimensions.get('window');
const iconSize = width * 0.3;
const colors = [
'rgb(0, 0, 0)', // black
'rgb(255, 159, 64)', // orange
'brown',
'rgb(255, 99, 132)', // pink
'rgb(54, 162, 235)', // blue
'rgb(0, 100, 192)', // green
'rgb(255, 206, 86)', // yellow
'rgb(153, 102, 255)', // purple
];
export default function App() {
const [index, setIndex] = useState(1);
const primaryColor = colors[index - 1];
const secondaryColor = colors[index % colors.length];
return (
<View style={styles.container}>
<View style={styles.row}>
<BallIcon width={iconSize} height={iconSize} fill={primaryColor} />
</View>
<View style={styles.row}>
<AvatarIcon
width={iconSize}
height={iconSize}
fill={primaryColor}
fillSecondary={secondaryColor}
/>
</View>
<View style={styles.row}>
<MessageIcon
width={iconSize}
height={iconSize}
fill={primaryColor}
fillSecondary={secondaryColor}
/>
</View>
<Slider
step={1}
minimumValue={1}
maximumValue={colors.length}
onValueChange={setIndex}
style={styles.slider}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f5f5f5',
alignItems: 'center',
justifyContent: 'flex-start'
},
row: {
paddingTop: 20
},
slider: {
marginTop: 30,
width: '90%'
}
});