Skip to content

Commit 4ce80c1

Browse files
add accordion animation
1 parent a7a59dc commit 4ce80c1

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

packages/core-mobile/app/new/common/components/WalletCard.tsx

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ import { useManageWallet } from 'common/hooks/useManageWallet'
99
import { AccountDisplayData, WalletDisplayData } from 'common/types'
1010
import { AccountListItem } from 'features/wallets/components/AccountListItem'
1111
import { WalletBalance } from 'features/wallets/components/WalletBalance'
12-
import React, { useCallback } from 'react'
13-
import { FlatList, ListRenderItem, StyleProp, ViewStyle } from 'react-native'
12+
import React, { useCallback, useState } from 'react'
13+
import {
14+
FlatList,
15+
LayoutChangeEvent,
16+
ListRenderItem,
17+
StyleProp,
18+
ViewStyle
19+
} from 'react-native'
20+
import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'
1421
import { WalletType } from 'services/wallet/types'
1522
import { DropdownMenu } from './DropdownMenu'
1623

@@ -95,23 +102,59 @@ const WalletCard = ({
95102
return null
96103
}, [colors.$surfaceSecondary, colors.$textSecondary, searchText])
97104

105+
const [contentHeight, setContentHeight] = useState(HEADER_HEIGHT)
106+
const onContentLayout = useCallback((event: LayoutChangeEvent) => {
107+
const { height } = event.nativeEvent.layout
108+
setContentHeight(height)
109+
}, [])
110+
111+
const animatedContentStyle = useAnimatedStyle(() => {
112+
return {
113+
minHeight: withTiming(
114+
isExpanded ? contentHeight + HEADER_HEIGHT * 2 : HEADER_HEIGHT
115+
)
116+
}
117+
})
118+
98119
return (
99-
<View
120+
<Animated.View
100121
style={[
122+
animatedContentStyle,
101123
{
102124
backgroundColor: colors.$surfaceSecondary,
103125
borderRadius: 16,
104126
overflow: 'hidden'
105127
},
106128
style
107129
]}>
130+
<View
131+
sx={{
132+
paddingHorizontal: 10,
133+
gap: 10,
134+
paddingBottom: 10,
135+
position: 'absolute',
136+
top: HEADER_HEIGHT,
137+
left: 0,
138+
right: 0
139+
}}>
140+
<FlatList
141+
data={wallet.accounts}
142+
onLayout={onContentLayout}
143+
renderItem={renderAccountItem}
144+
keyExtractor={item => item.account.id}
145+
ListEmptyComponent={renderEmpty}
146+
scrollEnabled={false}
147+
/>
148+
{renderBottom?.()}
149+
</View>
150+
108151
<TouchableOpacity
109152
onPress={onToggleExpansion}
110153
sx={{
111154
flexDirection: 'row',
112155
alignItems: 'center',
113156
justifyContent: 'space-between',
114-
minHeight: HEADER_HEIGHT
157+
height: HEADER_HEIGHT
115158
}}>
116159
<View
117160
sx={{
@@ -217,19 +260,8 @@ const WalletCard = ({
217260
</View>
218261
</TouchableOpacity>
219262

220-
{isExpanded && (
221-
<View sx={{ paddingHorizontal: 10, gap: 10, paddingBottom: 10 }}>
222-
<FlatList
223-
data={wallet.accounts}
224-
renderItem={renderAccountItem}
225-
keyExtractor={item => item.account.id}
226-
ListEmptyComponent={renderEmpty}
227-
scrollEnabled={false}
228-
/>
229-
{renderBottom?.()}
230-
</View>
231-
)}
232-
</View>
263+
<View sx={{ flex: 1 }} />
264+
</Animated.View>
233265
)
234266
}
235267

0 commit comments

Comments
 (0)