-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
90 changed files
with
2,555 additions
and
264 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import { | ||
View, | ||
ScrollView, | ||
Dimensions, | ||
ViewStyle, | ||
RefreshControl | ||
} from 'react-native'; | ||
import Animated, { | ||
useAnimatedStyle, | ||
useSharedValue, | ||
withTiming | ||
} from 'react-native-reanimated'; | ||
import { Button, Row, Spacer, Text } from '@components/base'; | ||
import { verticalScale } from '@utils/scaling'; | ||
import { COLORS } from '@constants/colors'; | ||
import { styles } from './styles'; | ||
|
||
type AnimatedTab = { | ||
view: JSX.Element; | ||
title: string; | ||
}; | ||
|
||
interface AnimatedTabsProps { | ||
tabs: AnimatedTab[]; | ||
containerStyle?: ViewStyle; | ||
onRefresh?: () => unknown; | ||
isRefreshing?: boolean; | ||
} | ||
|
||
export const AnimatedTabs = (props: AnimatedTabsProps) => { | ||
const { tabs, containerStyle, onRefresh, isRefreshing } = props; | ||
const tabCount = tabs.length; | ||
const scrollView = useRef<ScrollView>(null); | ||
const [currentIndex, setCurrentIndex] = useState(0); | ||
|
||
const tabWidth = Dimensions.get('window').width; | ||
const tabBarWidth = tabWidth / tabCount; | ||
|
||
const indicatorPosition = useSharedValue(0); | ||
|
||
// @ts-ignore | ||
const indicatorStyle = useAnimatedStyle(() => { | ||
return { | ||
transform: [{ translateX: withTiming(indicatorPosition.value) }] | ||
}; | ||
}); | ||
|
||
useEffect(() => { | ||
indicatorPosition.value = withTiming(currentIndex * (tabWidth / 2), { | ||
duration: 0 | ||
}); | ||
}, [currentIndex, indicatorPosition, tabWidth]); | ||
|
||
const scrollToTab = (idx: number) => { | ||
scrollView.current?.scrollTo({ x: tabWidth * idx, animated: true }); | ||
setCurrentIndex(idx); | ||
indicatorPosition.value = withTiming(idx * tabBarWidth); | ||
}; | ||
|
||
const renderTabView = (tab: AnimatedTab, idx: number): JSX.Element => { | ||
return ( | ||
<View | ||
key={`${tab.title}-view-${idx}`} | ||
style={{ width: tabWidth, flex: 1 }} | ||
> | ||
{tab.view} | ||
</View> | ||
); | ||
}; | ||
|
||
const renderTabBar = (tab: AnimatedTab, idx: number): JSX.Element => { | ||
return ( | ||
<Button | ||
onPress={() => scrollToTab(idx)} | ||
key={`${tab.title}-${idx}-bar`} | ||
style={styles.tabBarTitle} | ||
> | ||
<Text | ||
fontFamily="Inter_500Medium" | ||
color={currentIndex === idx ? COLORS.brand500 : COLORS.midnight} | ||
fontSize={16} | ||
> | ||
{tab.title} | ||
</Text> | ||
</Button> | ||
); | ||
}; | ||
|
||
return ( | ||
<View style={containerStyle}> | ||
<Row alignItems="center" justifyContent="space-between"> | ||
{tabs.map(renderTabBar)} | ||
</Row> | ||
<View style={styles.tabsIndicator}> | ||
<Animated.View | ||
style={[ | ||
{ | ||
position: 'relative', | ||
bottom: 1, | ||
left: 0, | ||
width: tabWidth / 2, | ||
height: 2, | ||
backgroundColor: COLORS.brand500 | ||
}, | ||
indicatorStyle | ||
]} | ||
/> | ||
</View> | ||
<Spacer value={verticalScale(10)} /> | ||
<ScrollView | ||
ref={scrollView} | ||
horizontal | ||
pagingEnabled | ||
showsHorizontalScrollIndicator={false} | ||
onMomentumScrollEnd={(event) => { | ||
const scrollOffsetX = event.nativeEvent.contentOffset.x; | ||
setCurrentIndex(scrollOffsetX > 0 ? 1 : 0); | ||
}} | ||
contentContainerStyle={{ flexGrow: 1 }} | ||
refreshControl={ | ||
<RefreshControl | ||
onRefresh={onRefresh} | ||
refreshing={Boolean(isRefreshing)} | ||
/> | ||
} | ||
> | ||
{tabs.map(renderTabView)} | ||
</ScrollView> | ||
</View> | ||
); | ||
}; |
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,17 @@ | ||
import { COLORS } from '@constants/colors'; | ||
import { scale, verticalScale } from '@utils/scaling'; | ||
import { StyleSheet } from 'react-native'; | ||
|
||
export const styles = StyleSheet.create({ | ||
tabBarTitle: { | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
flex: 1, | ||
paddingVertical: verticalScale(12), | ||
paddingHorizontal: scale(24) | ||
}, | ||
tabsIndicator: { | ||
backgroundColor: COLORS.alphaBlack10, | ||
height: 0.5 | ||
} | ||
}); |
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,57 @@ | ||
import { Row, Spacer, Text } from '@components/base'; | ||
import { StakingPool } from '@models'; | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
import { TokenLogo } from '../TokenLogo'; | ||
import { scale, verticalScale } from '@utils/scaling'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { COLORS } from '@constants/colors'; | ||
|
||
interface StakingPoolItemProps { | ||
stakingPool: StakingPool; | ||
} | ||
|
||
export const StakingPoolItem = (props: StakingPoolItemProps) => { | ||
const { stakingPool } = props; | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Row | ||
alignItems="center" | ||
justifyContent="space-between" | ||
style={{ opacity: stakingPool.isActive ? 1 : 0.5 }} | ||
> | ||
<Row alignItems="center"> | ||
<TokenLogo token={stakingPool.token.name} /> | ||
<Spacer value={scale(12)} horizontal /> | ||
<View> | ||
<Text | ||
color={COLORS.neutral900} | ||
fontFamily="Inter_500Medium" | ||
fontWeight="500" | ||
> | ||
{stakingPool.token.name} | ||
</Text> | ||
<Spacer value={verticalScale(4)} /> | ||
<Text | ||
color={COLORS.neutral400} | ||
fontFamily="Inter_500Medium" | ||
fontWeight="500" | ||
> | ||
{t('staking.current.stake', { | ||
amount: stakingPool.userStake, | ||
symbol: stakingPool.token.symbol | ||
})} | ||
</Text> | ||
</View> | ||
</Row> | ||
<Text | ||
color={COLORS.success500} | ||
fontSize={14} | ||
fontFamily="Inter_500Medium" | ||
> | ||
{stakingPool.apy}% | ||
</Text> | ||
</Row> | ||
); | ||
}; |
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
Oops, something went wrong.