aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShravya Ramesh <shravs1208@gmail.com>2021-03-09 10:21:41 -0800
committerShravya Ramesh <shravs1208@gmail.com>2021-03-09 10:21:41 -0800
commit0bb9f92aeb66c4b05a151bf86818ab2d386a7732 (patch)
treea63200fb6092ec066b8e48b1c16002ae60c4439c /src
parent13239b4b87f171a8d0c394af758968aa1e60f4ea (diff)
Added new component
Diffstat (limited to 'src')
-rw-r--r--src/components/suggestedPeople/BadgesDropdown.tsx149
1 files changed, 149 insertions, 0 deletions
diff --git a/src/components/suggestedPeople/BadgesDropdown.tsx b/src/components/suggestedPeople/BadgesDropdown.tsx
new file mode 100644
index 00000000..cd0d20cc
--- /dev/null
+++ b/src/components/suggestedPeople/BadgesDropdown.tsx
@@ -0,0 +1,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;