1
- import React from "react" ;
1
+ import React , { memo } from "react" ;
2
2
import { Image , StyleSheet , View } from "react-native" ;
3
3
import { useTheme } from "@react-navigation/native" ;
4
4
import { ChevronDown } from "lucide-react-native" ;
@@ -18,13 +18,13 @@ import { BlurView } from "expo-blur";
18
18
const ReanimatedBlurView = Reanimated . createAnimatedComponent ( BlurView ) ;
19
19
const AnimatedChevronDown = Reanimated . createAnimatedComponent ( ChevronDown ) ;
20
20
21
- const AccountSwitcher : React . FC < {
22
- small ?: boolean ;
23
- opened ?: boolean ;
24
- modalOpen ?: boolean ;
25
- translationY ?: Reanimated . SharedValue < number > ;
26
- loading ?: boolean ;
27
- } > = ( { small , opened , modalOpen , translationY , loading } ) => {
21
+ const AccountSwitcher = ( {
22
+ small = false ,
23
+ opened = false ,
24
+ modalOpen = false ,
25
+ translationY,
26
+ loading = false ,
27
+ } ) => {
28
28
const theme = useTheme ( ) ;
29
29
const { colors } = theme ;
30
30
const account = useCurrentAccount ( ( store ) => store . account ! ) ;
@@ -48,11 +48,7 @@ const AccountSwitcher: React.FC<{
48
48
} ) ) ;
49
49
50
50
const textAnimatedStyle = useAnimatedStyle ( ( ) => ( {
51
- color : interpolateColor (
52
- translationY ?. value || 0 ,
53
- [ 200 , 251 ] ,
54
- [ "#FFF" , colors . text ]
55
- ) ,
51
+ color : colors . text ,
56
52
fontSize : 16 ,
57
53
fontFamily : "semibold" ,
58
54
maxWidth : 140 ,
@@ -94,58 +90,29 @@ const AccountSwitcher: React.FC<{
94
90
95
91
return (
96
92
< Reanimated . View
97
- style = { {
98
- backgroundColor : opened
99
- ? theme . dark && ! modalOpen
100
- ? "#00000044"
101
- : "#FFFFFF22"
102
- : modalOpen
103
- ? colors . text + "10"
104
- : "#FFFFFF12" ,
105
- borderRadius : 12 ,
106
- borderCurve : "continuous" ,
107
- overflow : "hidden" ,
108
- alignSelf : "flex-start" ,
109
- } }
93
+ style = { [
94
+ styles . container ,
95
+ {
96
+ backgroundColor : theme . dark ? colors . background : colors . card ,
97
+ borderColor : modalOpen ? colors . border : "transparent" ,
98
+ shadowOpacity : modalOpen ? 0.16 : 0 ,
99
+ } ,
100
+ ] }
110
101
layout = { animPapillon ( LinearTransition ) }
111
102
>
112
- < ReanimatedBlurView
113
- tint = "default"
114
- experimentalBlurMethod = "dimezisBlurView"
115
- style = { {
116
- paddingHorizontal : 2 ,
117
- paddingVertical : 0 ,
118
- alignSelf : "flex-start" ,
119
- } }
120
- layout = { animPapillon ( LinearTransition ) }
121
- >
103
+ < Reanimated . View style = { styles . innerContainer } layout = { animPapillon ( LinearTransition ) } >
122
104
< Reanimated . View
123
105
layout = { animPapillon ( LinearTransition ) }
124
106
style = { [
125
107
styles . accountSwitcher ,
126
108
loading && { shadowOpacity : 0 } ,
127
- small && {
128
- paddingHorizontal : 0 ,
129
- shadowOpacity : 0 ,
130
- elevation : 0 ,
131
- borderRadius : 0 ,
132
- paddingVertical : 0 ,
133
- backgroundColor : "transparent" ,
134
- } ,
109
+ small && styles . smallAccountSwitcher ,
135
110
] }
136
111
>
137
- < Reanimated . View
138
- style = { { flexDirection : "row" , alignItems : "center" , gap : 12 } }
139
- layout = { animPapillon ( LinearTransition ) }
140
- >
112
+ < Reanimated . View style = { styles . row } layout = { animPapillon ( LinearTransition ) } >
141
113
{ renderProfilePicture ( ) }
142
114
< Reanimated . Text
143
- style = { {
144
- color : modalOpen && ! opened ? colors . text : "#FFF" ,
145
- fontSize : 16 ,
146
- fontFamily : "semibold" ,
147
- maxWidth : 140 ,
148
- } }
115
+ style = { textAnimatedStyle }
149
116
numberOfLines = { 1 }
150
117
ellipsizeMode = "tail"
151
118
>
@@ -157,7 +124,7 @@ const AccountSwitcher: React.FC<{
157
124
< PapillonSpinner
158
125
size = { 20 }
159
126
strokeWidth = { 3 }
160
- color = { modalOpen && ! opened ? colors . text : "#FFF" }
127
+ color = { colors . text }
161
128
animated
162
129
entering = { animPapillon ( ZoomIn ) }
163
130
exiting = { animPapillon ( ZoomOut ) }
@@ -168,17 +135,36 @@ const AccountSwitcher: React.FC<{
168
135
size = { 24 }
169
136
strokeWidth = { 2.3 }
170
137
style = { iconAnimatedStyle }
171
- color = { modalOpen && ! opened ? colors . text : "#FFF" }
138
+ color = { colors . text }
172
139
/>
173
140
</ Reanimated . View >
174
141
</ Reanimated . View >
175
142
</ Reanimated . View >
176
- </ ReanimatedBlurView >
143
+ </ Reanimated . View >
177
144
</ Reanimated . View >
178
145
) ;
179
146
} ;
180
147
181
148
const styles = StyleSheet . create ( {
149
+ container : {
150
+ borderRadius : 12 ,
151
+ borderCurve : "continuous" ,
152
+ overflow : "visible" ,
153
+ alignSelf : "flex-start" ,
154
+ shadowColor : "black" ,
155
+ shadowOffset : { width : 0 , height : 1 } ,
156
+ shadowRadius : 4 ,
157
+ shadowOpacity : 0 ,
158
+ borderWidth : 1 ,
159
+ } ,
160
+ innerContainer : {
161
+ paddingHorizontal : 2 ,
162
+ paddingVertical : 0 ,
163
+ alignSelf : "flex-start" ,
164
+ borderRadius : 12 ,
165
+ borderCurve : "continuous" ,
166
+ overflow : "hidden" ,
167
+ } ,
182
168
accountSwitcher : {
183
169
flexDirection : "row" ,
184
170
justifyContent : "center" ,
@@ -191,6 +177,18 @@ const styles = StyleSheet.create({
191
177
paddingVertical : 6 ,
192
178
gap : 6 ,
193
179
} ,
180
+ smallAccountSwitcher : {
181
+ paddingHorizontal : 0 ,
182
+ elevation : 0 ,
183
+ borderRadius : 0 ,
184
+ paddingVertical : 0 ,
185
+ backgroundColor : "transparent" ,
186
+ } ,
187
+ row : {
188
+ flexDirection : "row" ,
189
+ alignItems : "center" ,
190
+ gap : 12 ,
191
+ } ,
194
192
avatar : {
195
193
aspectRatio : 1 ,
196
194
borderRadius : 24 ,
@@ -200,4 +198,4 @@ const styles = StyleSheet.create({
200
198
} ,
201
199
} ) ;
202
200
203
- export default AccountSwitcher ;
201
+ export default memo ( AccountSwitcher ) ;
0 commit comments