-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ (llm): new accounts and assets lists portfolio
- Loading branch information
1 parent
c23401a
commit bca80ac
Showing
7 changed files
with
222 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
apps/ledger-live-mobile/src/screens/Portfolio/TabSelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { useState } from "react"; | ||
import { Pressable, LayoutChangeEvent } from "react-native"; | ||
import Animated, { useSharedValue, useAnimatedStyle, withTiming } from "react-native-reanimated"; | ||
import styled from "styled-components/native"; | ||
import { Flex, Text } from "@ledgerhq/native-ui"; | ||
|
||
const Container = styled(Flex)` | ||
height: 100%; | ||
justify-content: space-between; | ||
flex-direction: row; | ||
position: relative; | ||
`; | ||
|
||
const AnimatedBackground = styled(Animated.View)` | ||
position: absolute; | ||
height: 100%; | ||
border-radius: 8px; | ||
background-color: ${({ theme }) => theme.colors.opacityDefault.c05}; | ||
`; | ||
|
||
const Tab = styled(Flex)` | ||
flex: 1; | ||
padding: 4px; | ||
border-radius: 8px; | ||
align-items: center; | ||
justify-content: center; | ||
`; | ||
|
||
type TabSelectorProps = { | ||
labels: string[]; | ||
onToggle: (value: string) => void; | ||
}; | ||
|
||
const TabSelector = ({ labels, onToggle }: TabSelectorProps) => { | ||
const translateX = useSharedValue(0); | ||
const [containerWidth, setContainerWidth] = useState(0); | ||
|
||
const handlePress = (value: string, index: number) => { | ||
onToggle(value); | ||
translateX.value = (containerWidth / labels.length) * index; | ||
}; | ||
|
||
const handleLayout = (event: LayoutChangeEvent) => { | ||
const { width } = event.nativeEvent.layout; | ||
setContainerWidth(width); | ||
}; | ||
|
||
const animatedStyle = useAnimatedStyle(() => { | ||
return { | ||
transform: [{ translateX: withTiming(translateX.value, { duration: 300 }) }], | ||
width: containerWidth / labels.length, | ||
}; | ||
}); | ||
|
||
return ( | ||
<Container onLayout={handleLayout}> | ||
<AnimatedBackground style={animatedStyle} /> | ||
{labels.map((label, index) => ( | ||
<Pressable | ||
hitSlop={16} | ||
key={label} | ||
onPress={() => handlePress(label, index)} | ||
style={({ pressed }: { pressed: boolean }) => [{ opacity: pressed ? 0.5 : 1.0, flex: 1 }]} | ||
> | ||
<Tab> | ||
<Text fontSize={14} fontWeight="semiBold" flexShrink={1} numberOfLines={1}> | ||
{label} | ||
</Text> | ||
</Tab> | ||
</Pressable> | ||
))} | ||
</Container> | ||
); | ||
}; | ||
|
||
export default TabSelector; |
69 changes: 69 additions & 0 deletions
69
apps/ledger-live-mobile/src/screens/Portfolio/useTabAnimation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// FILE: useTabAnimation.ts | ||
import { useSharedValue, useAnimatedStyle, withTiming } from "react-native-reanimated"; | ||
import { useState, useEffect } from "react"; | ||
import { LayoutChangeEvent } from "react-native"; | ||
|
||
const useTabAnimation = (initialTab: string) => { | ||
const [selectedTab, setSelectedTab] = useState(initialTab); | ||
const [containerWidth, setContainerWidth] = useState(0); | ||
|
||
const assetsTranslateX = useSharedValue(0); | ||
const accountsTranslateX = useSharedValue(containerWidth); | ||
const assetsOpacity = useSharedValue(1); | ||
const accountsOpacity = useSharedValue(0); | ||
|
||
const handleToggle = (value: string) => { | ||
setSelectedTab(value); | ||
}; | ||
|
||
const handleLayout = (event: LayoutChangeEvent) => { | ||
const { width } = event.nativeEvent.layout; | ||
setContainerWidth(width); | ||
accountsTranslateX.value = width; | ||
}; | ||
|
||
const assetsAnimatedStyle = useAnimatedStyle(() => { | ||
return { | ||
transform: [{ translateX: assetsTranslateX.value }], | ||
opacity: assetsOpacity.value, | ||
}; | ||
}); | ||
|
||
const accountsAnimatedStyle = useAnimatedStyle(() => { | ||
return { | ||
transform: [{ translateX: accountsTranslateX.value }], | ||
opacity: accountsOpacity.value, | ||
}; | ||
}); | ||
|
||
useEffect(() => { | ||
if (selectedTab === "Assets") { | ||
assetsTranslateX.value = withTiming(0, { duration: 300 }); | ||
assetsOpacity.value = withTiming(1, { duration: 300 }); | ||
accountsTranslateX.value = withTiming(containerWidth, { duration: 300 }); | ||
accountsOpacity.value = withTiming(0, { duration: 400 }); | ||
} else { | ||
assetsTranslateX.value = withTiming(-containerWidth / 2, { duration: 300 }); | ||
assetsOpacity.value = withTiming(0, { duration: 400 }); | ||
accountsTranslateX.value = withTiming(-containerWidth / 2, { duration: 300 }); | ||
accountsOpacity.value = withTiming(1, { duration: 300 }); | ||
} | ||
}, [ | ||
selectedTab, | ||
assetsTranslateX, | ||
accountsTranslateX, | ||
containerWidth, | ||
assetsOpacity, | ||
accountsOpacity, | ||
]); | ||
|
||
return { | ||
selectedTab, | ||
handleToggle, | ||
handleLayout, | ||
assetsAnimatedStyle, | ||
accountsAnimatedStyle, | ||
}; | ||
}; | ||
|
||
export default useTabAnimation; |