-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIconWithBadge.tsx
71 lines (67 loc) · 1.54 KB
/
IconWithBadge.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
import React from 'react';
import Ionicons from 'react-native-vector-icons/Ionicons';
import {Text, View} from 'react-native';
import {brandColors} from './colors';
import Animated, {
interpolateColor,
useAnimatedProps,
useAnimatedStyle,
} from 'react-native-reanimated';
const AnimatedIcon = Animated.createAnimatedComponent(Ionicons);
const IconWithBadge = ({
iconName = 'cart-outline',
badgeLabel = '1',
scrollPosY,
}: {
iconName: any;
badgeLabel: string;
scrollPosY: Animated.SharedValue<number>;
}) => {
const animatedStyle = useAnimatedStyle(() => {
return {
color: interpolateColor(
scrollPosY.value,
[0, 1],
['rgba(255,255,255,1)', 'rgba(0,0,0,1)'],
),
};
});
const iconColor = useAnimatedProps(() => {
return {
color: interpolateColor(
scrollPosY.value,
[0, 1],
['rgba(255,255,255,1)', 'rgba(0,0,0,1)'],
),
size: 20,
name: iconName,
};
});
return (
<View>
<View
style={{
position: 'absolute',
right: -5,
top: -5,
backgroundColor: brandColors.main,
borderRadius: 999,
width: 16,
height: 16,
zIndex: 9999,
}}>
<Text
style={{
textAlign: 'center',
textAlignVertical: 'center',
fontSize: 12,
color: 'white',
}}>
{badgeLabel}
</Text>
</View>
<AnimatedIcon animatedProps={iconColor}/>
</View>
);
};
export default IconWithBadge;