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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
import {useNavigation} from '@react-navigation/native';
import React, {useEffect, useState} from 'react';
import {Image, StyleSheet} from 'react-native';
import {TouchableOpacity} from 'react-native-gesture-handler';
import LinearGradient from 'react-native-linear-gradient';
import Animated, {Easing} from 'react-native-reanimated';
import {UniversityBadge} from 'src/types';
import {UniversityIcon} from '..';
import {normalize, SCREEN_WIDTH} from '../../utils';
interface BadgesDropdownProps {
localBadges: {
badge: UniversityBadge;
img: string;
}[];
}
const BadgesDropdown: React.FC<BadgesDropdownProps> = ({localBadges}) => {
const [displayBadges, setDisplayBadges] = useState<boolean>(false);
let [top, setTop] = useState<Animated.Value<number>[]>([]);
const navigation = useNavigation();
useEffect(() => {
const defineBadgePositions = () => {
let localTop: Animated.Value<number>[] = [];
localBadges.forEach(() => {
localTop.push(new Animated.Value(0));
});
setTop(localTop);
};
defineBadgePositions();
}, []);
const animate = () => {
for (let i = 0; i < localBadges.length; i++) {
if (top) {
Animated.timing(top[i], {
toValue: i * 40 + 50,
duration: 500,
easing: Easing.linear,
}).start();
}
}
};
const animateBack = () => {
for (let i = 0; i < localBadges.length; i++) {
if (top) {
Animated.timing(top[i], {
toValue: 0,
duration: 500,
easing: Easing.linear,
}).start();
}
}
};
return (
<Animated.View
style={[styles.badgesContainer, {height: 50 + 40 * localBadges.length}]}>
<TouchableOpacity
activeOpacity={0.95}
onPress={() => {
setDisplayBadges(!displayBadges);
if (displayBadges) {
animate();
} else {
animateBack();
}
}}>
<UniversityIcon
university="brown"
style={styles.universityIconContainer}
imageStyle={{width: normalize(31), height: normalize(38)}}
/>
</TouchableOpacity>
{localBadges &&
localBadges.map(({badge, img}, index) => (
<Animated.View
key={badge.id}
style={[
styles.animatedBadgeView,
{
top: top[index],
zIndex: -1 * parseInt(badge.id, 10),
},
]}>
<TouchableOpacity
style={styles.badgeButton}
onPress={() => {
navigation.navigate('MutualBadgeHolders', {
badge_id: badge.id,
badge_title: badge.name,
});
}}>
<LinearGradient
colors={['#4E3629', '#EC2027']}
useAngle={true}
angle={154.72}
angleCenter={{x: 0.5, y: 0.5}}
style={styles.badgeBackground}>
<Image
source={img}
style={{
width: SCREEN_WIDTH * 0.04,
height: SCREEN_WIDTH * 0.04,
}}
/>
</LinearGradient>
</TouchableOpacity>
</Animated.View>
))}
</Animated.View>
);
};
const styles = StyleSheet.create({
badgeBackground: {
position: 'absolute',
width: '100%',
height: '100%',
borderRadius: 50,
borderColor: 'transparent',
borderWidth: 1,
alignSelf: 'center',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
badgesContainer: {
flexDirection: 'column',
justifyContent: 'space-between',
alignItems: 'center',
width: 38,
left: '5%',
paddingBottom: '2%',
},
badgeButton: {
width: 30,
height: 30,
borderRadius: 15,
},
animatedBadgeView: {position: 'absolute'},
universityIconContainer: {
width: normalize(31),
height: normalize(38),
},
});
export default BadgesDropdown;
|