@@ -145,7 +145,7 @@ const Card = (
145
145
onLongPress,
146
146
onPressOut,
147
147
onPressIn,
148
- mode : cardMode = 'elevated' ,
148
+ mode = 'elevated' ,
149
149
children,
150
150
style,
151
151
contentStyle,
@@ -158,11 +158,16 @@ const Card = (
158
158
ref : React . ForwardedRef < View >
159
159
) => {
160
160
const theme = useInternalTheme ( themeOverrides ) ;
161
+ const {
162
+ animation : { scale } ,
163
+ roundness,
164
+ } = theme ;
165
+
161
166
const isMode = React . useCallback (
162
167
( modeToCompare : Mode ) => {
163
- return cardMode === modeToCompare ;
168
+ return mode === modeToCompare ;
164
169
} ,
165
- [ cardMode ]
170
+ [ mode ]
166
171
) ;
167
172
168
173
const hasPassedTouchHandler = hasTouchHandler ( {
@@ -172,65 +177,21 @@ const Card = (
172
177
onPressOut,
173
178
} ) ;
174
179
175
- // Default animated value
176
180
const { current : elevation } = React . useRef < Animated . Value > (
177
181
new Animated . Value ( cardElevation )
178
182
) ;
179
- // Dark adaptive animated value, used in case of toggling the theme,
180
- // it prevents animating the background with native drivers inside Surface
181
- const { current : elevationDarkAdaptive } = React . useRef < Animated . Value > (
182
- new Animated . Value ( cardElevation )
183
- ) ;
184
- const { animation, dark, mode, roundness } = theme ;
185
-
186
- const prevDarkRef = React . useRef < boolean > ( dark ) ;
187
- React . useEffect ( ( ) => {
188
- prevDarkRef . current = dark ;
189
- } ) ;
190
-
191
- const prevDark = prevDarkRef . current ;
192
- const isAdaptiveMode = mode === 'adaptive' ;
193
- const animationDuration = 150 * animation . scale ;
194
-
195
- React . useEffect ( ( ) => {
196
- /**
197
- * Resets animations values if updating to dark adaptive mode,
198
- * otherwise, any card that is in the middle of animation while
199
- * toggling the theme will stay at that animated value until
200
- * the next press-in
201
- */
202
- if ( dark && isAdaptiveMode && ! prevDark ) {
203
- elevation . setValue ( cardElevation ) ;
204
- elevationDarkAdaptive . setValue ( cardElevation ) ;
205
- }
206
- } , [
207
- prevDark ,
208
- dark ,
209
- isAdaptiveMode ,
210
- cardElevation ,
211
- elevation ,
212
- elevationDarkAdaptive ,
213
- ] ) ;
214
183
215
184
const runElevationAnimation = ( pressType : HandlePressType ) => {
216
185
if ( isMode ( 'contained' ) ) {
217
186
return ;
218
187
}
219
188
220
189
const isPressTypeIn = pressType === 'in' ;
221
- if ( dark && isAdaptiveMode ) {
222
- Animated . timing ( elevationDarkAdaptive , {
223
- toValue : isPressTypeIn ? 2 : cardElevation ,
224
- duration : animationDuration ,
225
- useNativeDriver : false ,
226
- } ) . start ( ) ;
227
- } else {
228
- Animated . timing ( elevation , {
229
- toValue : isPressTypeIn ? 2 : cardElevation ,
230
- duration : animationDuration ,
231
- useNativeDriver : false ,
232
- } ) . start ( ) ;
233
- }
190
+ Animated . timing ( elevation , {
191
+ toValue : isPressTypeIn ? 2 : cardElevation ,
192
+ duration : 150 * scale ,
193
+ useNativeDriver : false ,
194
+ } ) . start ( ) ;
234
195
} ;
235
196
236
197
const handlePressIn = useLatestCallback ( ( e : GestureResponderEvent ) => {
@@ -249,12 +210,10 @@ const Card = (
249
210
? ( child . type as any ) . displayName
250
211
: null
251
212
) ;
252
- const computedElevation =
253
- dark && isAdaptiveMode ? elevationDarkAdaptive : elevation ;
254
213
255
214
const { backgroundColor, borderColor : themedBorderColor } = getCardColors ( {
256
215
theme,
257
- mode : cardMode ,
216
+ mode,
258
217
} ) ;
259
218
260
219
const flattenedStyles = ( StyleSheet . flatten ( style ) || { } ) as ViewStyle ;
@@ -295,7 +254,7 @@ const Card = (
295
254
style ,
296
255
] }
297
256
theme = { theme }
298
- elevation = { isMode ( 'elevated' ) ? computedElevation : 0 }
257
+ elevation = { isMode ( 'elevated' ) ? elevation : 0 }
299
258
testID = { `${ testID } -container` }
300
259
container
301
260
{ ...rest }
0 commit comments