From 0bd3c9232c60290babfeaa4a7bd3636932d60ba2 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 17 Mar 2024 01:17:19 -0400 Subject: [PATCH] REF: DrawerList to TSX --- Navigation.tsx | 9 +- .../wallets/{drawerList.js => DrawerList.tsx} | 85 ++++++++++--------- 2 files changed, 51 insertions(+), 43 deletions(-) rename screen/wallets/{drawerList.js => DrawerList.tsx} (55%) diff --git a/Navigation.tsx b/Navigation.tsx index a3d350826..183a9cf14 100644 --- a/Navigation.tsx +++ b/Navigation.tsx @@ -83,7 +83,7 @@ import LnurlPay from './screen/lnd/lnurlPay'; import LnurlPaySuccess from './screen/lnd/lnurlPaySuccess'; import ScanLndInvoice from './screen/lnd/scanLndInvoice'; import SettingsPrivacy from './screen/settings/SettingsPrivacy'; -import DrawerList from './screen/wallets/drawerList'; +import DrawerList from './screen/wallets/DrawerList'; import LdkViewLogs from './screen/wallets/ldkViewLogs'; import PaymentCode from './screen/wallets/paymentCode'; import PaymentCodesList from './screen/wallets/paymentCodesList'; @@ -383,12 +383,17 @@ const ReorderWalletsStackRoot = () => { ); }; +const DrawerListContent = (props: any) => { + return ; +}; + const Drawer = createDrawerNavigator(); const DrawerRoot = () => { const dimensions = useWindowDimensions(); const isLargeScreen = useMemo(() => { return Platform.OS === 'android' ? isTablet() : (dimensions.width >= Dimensions.get('screen').width / 2 && isTablet()) || isDesktop; }, [dimensions.width]); + const drawerStyle: DrawerNavigationOptions = useMemo( () => ({ drawerPosition: I18nManager.isRTL ? 'right' : 'left', @@ -399,7 +404,7 @@ const DrawerRoot = () => { ); return ( - + { - const walletsCarousel = useRef(); +interface DrawerListProps { + navigation: NavigationProp; + // include other props as necessary +} + +const DrawerList: React.FC = memo(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, - }, - }); + + const stylesHook = useMemo( + () => + StyleSheet.create({ + root: { + backgroundColor: colors.elevated, + }, + }), + [colors.elevated], + ); useEffect(() => { if (walletsCount.current < wallets.length) { @@ -29,36 +39,39 @@ const DrawerList = props => { walletsCount.current = wallets.length; }, [wallets]); - const handleClick = item => { - if (item?.getID) { - const walletID = item.getID(); - 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 handleClick = useCallback( + (item: AbstractWallet) => { + if (item?.getID) { + const walletID = item.getID(); + LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); + setSelectedWalletID(walletID); + props.navigation.navigate({ + name: 'WalletTransactions', + params: { walletID, walletType: item.type }, + }); + } else { + props.navigation.navigate('Navigation', { screen: 'AddWalletRoot' }); + } + }, + [props.navigation, setSelectedWalletID], + ); - const handleLongPress = () => { + const handleLongPress = useCallback(() => { if (wallets.length > 1) { props.navigation.navigate('ReorderWallets'); } else { triggerHapticFeedback(HapticFeedbackTypes.NotificationError); } - }; + }, [wallets.length, props.navigation]); - const onNewWalletPress = () => { + const onNewWalletPress = useCallback(() => { return props.navigation.navigate('AddWalletRoot'); - }; + }, [props.navigation]); return ( { > { /> ); -}; +}); export default DrawerList; @@ -86,14 +100,3 @@ const styles = StyleSheet.create({ flex: 1, }, }); - -DrawerList.propTypes = { - navigation: PropTypes.shape({ - navigate: PropTypes.func, - addListener: PropTypes.func, - }), - route: PropTypes.shape({ - name: PropTypes.string, - params: PropTypes.object, - }), -};