BlueWallet/screen/wallets/drawerList.js

100 lines
3 KiB
JavaScript
Raw Normal View History

import React, { useContext, useEffect, useRef } from 'react';
2024-01-05 04:18:01 -04:00
import { StyleSheet, LayoutAnimation } from 'react-native';
import { DrawerContentScrollView } from '@react-navigation/drawer';
import PropTypes from 'prop-types';
2023-10-23 21:28:44 -04:00
import { useIsFocused } from '@react-navigation/native';
import { BlueHeaderDefaultMain } from '../../BlueComponents';
2020-12-25 19:09:53 +03:00
import WalletsCarousel from '../../components/WalletsCarousel';
import loc from '../../loc';
import { BlueStorageContext } from '../../blue_modules/storage-context';
2023-10-23 21:28:44 -04:00
import { useTheme } from '../../components/themes';
import triggerHapticFeedback, { HapticFeedbackTypes } from '../../blue_modules/hapticFeedback';
const DrawerList = props => {
const walletsCarousel = useRef();
const { wallets, selectedWalletID, setSelectedWalletID } = useContext(BlueStorageContext);
const { colors } = useTheme();
const walletsCount = useRef(wallets.length);
const isFocused = useIsFocused();
const stylesHook = StyleSheet.create({
root: {
backgroundColor: colors.elevated,
},
});
2021-02-07 22:54:04 -05:00
useEffect(() => {
if (walletsCount.current < wallets.length) {
2021-06-16 02:05:04 -04:00
walletsCarousel.current?.scrollToItem({ item: wallets[walletsCount.current] });
2021-02-07 22:54:04 -05:00
}
walletsCount.current = wallets.length;
}, [wallets]);
const handleClick = item => {
if (item?.getID) {
const walletID = item.getID();
2024-01-05 04:18:01 -04:00
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
setSelectedWalletID(walletID);
props.navigation.navigate({
name: 'WalletTransactions',
params: { walletID, walletType: item.type },
});
} else {
props.navigation.navigate('Navigation', { screen: 'AddWalletRoot' });
}
};
const handleLongPress = () => {
if (wallets.length > 1) {
props.navigation.navigate('ReorderWallets');
} else {
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
}
};
2021-06-16 02:05:04 -04:00
const onNewWalletPress = () => {
return props.navigation.navigate('AddWalletRoot');
2021-06-16 02:05:04 -04:00
};
return (
2023-03-27 00:07:46 -04:00
<DrawerContentScrollView
{...props}
drawerContentContainerStyle={[styles.root, stylesHook.root]}
2023-03-27 00:07:46 -04:00
contentInsetAdjustmentBehavior="automatic"
automaticallyAdjustContentInsets
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
>
<BlueHeaderDefaultMain leftText={loc.wallets.list_title} onNewWalletPress={onNewWalletPress} isDrawerList />
<WalletsCarousel
data={wallets.concat(false)}
extraData={[wallets]}
onPress={handleClick}
handleLongPress={handleLongPress}
ref={walletsCarousel}
testID="WalletsList"
selectedWallet={selectedWalletID}
2023-03-27 00:07:46 -04:00
scrollEnabled={isFocused}
/>
</DrawerContentScrollView>
);
};
export default DrawerList;
2020-12-25 19:09:53 +03:00
const styles = StyleSheet.create({
root: {
flex: 1,
},
});
DrawerList.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
addListener: PropTypes.func,
}),
route: PropTypes.shape({
name: PropTypes.string,
params: PropTypes.object,
}),
};