Skip to content

Commit

Permalink
animated wallet connector menu button arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
krisbitney committed Dec 12, 2023
1 parent 6126d7d commit 22a1e32
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
14 changes: 3 additions & 11 deletions packages/app/src/components/Header/ConnectWalletMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Image, StyleSheet, Text, TextStyle, TouchableOpacity, View } from 'reac
import { useConnect } from 'wagmi';
import { Colors } from '../../utils/colors';
import { useState } from 'react';
import { backIconUri, metamaskLogoUri, walletConnectLogoUri } from './assets';
import { metamaskLogoUri, walletConnectLogoUri } from './assets';
import { WebIconUri } from '../../@constants/ConnectIcons';
import { RotatingArrowIcon } from './RotatingArrowIcon';

interface ConnectWalletMenuProps {
dropdownOffset: { top: number; right?: number; left?: number };
Expand All @@ -30,11 +31,7 @@ export const ConnectWalletMenu = (props: ConnectWalletMenuProps) => {
<>
<TouchableOpacity style={styles.walletConnectButton} onPress={() => setOpenDropdown(!openDropdown)}>
<Text style={styles.walletConnectButtonText}>Connect Wallet</Text>
<Image
source={{ uri: backIconUri }}
resizeMode="contain"
style={[styles.arrowIcon, { transform: [{ rotate: openDropdown ? '270deg' : '0deg' }] }]}
/>
<RotatingArrowIcon openDropdown={openDropdown} />
</TouchableOpacity>
{openDropdown && (
<View style={[styles.dropdownContainer, dropdownOffset]}>
Expand Down Expand Up @@ -94,11 +91,6 @@ const styles = StyleSheet.create({
position: 'absolute',
backgroundColor: Colors.white,
},
arrowIcon: {
width: 15,
height: 15,
tintColor: Colors.white,
},
walletConnector: {
width: '100%',
height: 40,
Expand Down
48 changes: 48 additions & 0 deletions packages/app/src/components/Header/RotatingArrowIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useEffect, useRef } from 'react';
import { Animated } from 'react-native';
import { backIconUri } from './assets';
import { Colors } from '../../utils/colors';

interface RotatingArrowIconProps {
openDropdown: boolean;
}

export const RotatingArrowIcon = (props: RotatingArrowIconProps) => {
const { openDropdown } = props;

const rotationAnim = useRef(new Animated.Value(0)).current;

const rotation = rotationAnim.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '-90deg'],
});

const startRotation = () => {
Animated.timing(rotationAnim, {
toValue: openDropdown ? 1 : 0,
duration: 50,
useNativeDriver: true,
}).start();
};

useEffect(() => {
startRotation();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [openDropdown]);

return (
<Animated.Image
source={{ uri: backIconUri }}
resizeMode="contain"
style={[styles.arrowIcon, { transform: [{ rotate: rotation }] }]}
/>
);
};

const styles = {
arrowIcon: {
width: 15,
height: 15,
tintColor: Colors.white,
},
};

0 comments on commit 22a1e32

Please sign in to comment.