BlueWallet/screen/wallets/drawerList.js

101 lines
3 KiB
JavaScript
Raw Normal View History

import React, { useContext, useEffect, useRef } from 'react';
2023-03-27 09:21:40 -04:00
import { StyleSheet } from 'react-native';
import { DrawerContentScrollView } from '@react-navigation/drawer';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import PropTypes from 'prop-types';
2023-10-23 21:28:44 -04:00
import { useIsFocused } from '@react-navigation/native';
2020-12-25 19:09:53 +03:00
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';
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();
setSelectedWalletID(walletID);
props.navigation.navigate('WalletTransactions', {
walletID: item.getID(),
walletType: item.type,
key: `WalletTransactions-${walletID}`,
});
} else {
props.navigation.navigate('Navigation', { screen: 'AddWalletRoot' });
}
};
const handleLongPress = () => {
if (wallets.length > 1) {
props.navigation.navigate('ReorderWallets');
} else {
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
}
};
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}
style={[styles.root, stylesHook.root]}
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,
}),
};