@@ -145,7 +145,7 @@ const Card = (
145145 onLongPress,
146146 onPressOut,
147147 onPressIn,
148- mode : cardMode = 'elevated' ,
148+ mode = 'elevated' ,
149149 children,
150150 style,
151151 contentStyle,
@@ -158,11 +158,16 @@ const Card = (
158158 ref : React . ForwardedRef < View >
159159) => {
160160 const theme = useInternalTheme ( themeOverrides ) ;
161+ const {
162+ animation : { scale } ,
163+ roundness,
164+ } = theme ;
165+
161166 const isMode = React . useCallback (
162167 ( modeToCompare : Mode ) => {
163- return cardMode === modeToCompare ;
168+ return mode === modeToCompare ;
164169 } ,
165- [ cardMode ]
170+ [ mode ]
166171 ) ;
167172
168173 const hasPassedTouchHandler = hasTouchHandler ( {
@@ -172,65 +177,21 @@ const Card = (
172177 onPressOut,
173178 } ) ;
174179
175- // Default animated value
176180 const { current : elevation } = React . useRef < Animated . Value > (
177181 new Animated . Value ( cardElevation )
178182 ) ;
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- ] ) ;
214183
215184 const runElevationAnimation = ( pressType : HandlePressType ) => {
216185 if ( isMode ( 'contained' ) ) {
217186 return ;
218187 }
219188
220189 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 ( ) ;
234195 } ;
235196
236197 const handlePressIn = useLatestCallback ( ( e : GestureResponderEvent ) => {
@@ -249,12 +210,10 @@ const Card = (
249210 ? ( child . type as any ) . displayName
250211 : null
251212 ) ;
252- const computedElevation =
253- dark && isAdaptiveMode ? elevationDarkAdaptive : elevation ;
254213
255214 const { backgroundColor, borderColor : themedBorderColor } = getCardColors ( {
256215 theme,
257- mode : cardMode ,
216+ mode,
258217 } ) ;
259218
260219 const flattenedStyles = ( StyleSheet . flatten ( style ) || { } ) as ViewStyle ;
@@ -295,7 +254,7 @@ const Card = (
295254 style ,
296255 ] }
297256 theme = { theme }
298- elevation = { isMode ( 'elevated' ) ? computedElevation : 0 }
257+ elevation = { isMode ( 'elevated' ) ? elevation : 0 }
299258 testID = { `${ testID } -container` }
300259 container
301260 { ...rest }
0 commit comments