33
44import { Animated } from 'react-native' ;
55
6- import type { ThemeElevation } from '../../types' ;
6+ import { isAnimatedValue } from '../../../utils/animations' ;
7+ import type { Elevation , ThemeElevation } from '../../types' ;
78
89export const defaultElevation : ThemeElevation = {
910 level0 : 0 ,
@@ -14,9 +15,9 @@ export const defaultElevation: ThemeElevation = {
1415 level5 : 5 ,
1516} ;
1617
17- export const elevationInputRange = [ 0 , 1 , 2 , 3 , 4 , 5 ] as const ;
18+ export const elevationInputRange : Elevation [ ] = Object . values ( defaultElevation ) ;
1819
19- export const androidElevationLevels = [ 0 , 1 , 3 , 6 , 8 , 12 ] as const ;
20+ export const androidElevationLevels = [ 0 , 1 , 3 , 6 , 8 , 12 ] ;
2021
2122export const shadowLayers = [
2223 {
@@ -29,20 +30,20 @@ export const shadowLayers = [
2930 height : [ 0 , 1 , 1 , 1 , 2 , 4 ] ,
3031 shadowRadius : [ 0 , 2 , 2 , 3 , 3 , 4 ] ,
3132 } ,
32- ] as const ;
33+ ] ;
3334
3435export function shadow (
3536 elevation : number | Animated . Value = 0 ,
3637 shadowColor : string
3738) {
38- if ( elevation instanceof Animated . Value ) {
39+ if ( isAnimatedValue ( elevation ) ) {
3940 return {
4041 shadowColor,
4142 shadowOffset : {
4243 width : new Animated . Value ( 0 ) ,
4344 height : elevation . interpolate ( {
44- inputRange : [ ... elevationInputRange ] ,
45- outputRange : [ ... shadowLayers [ 0 ] . height ] ,
45+ inputRange : elevationInputRange ,
46+ outputRange : shadowLayers [ 0 ] . height ,
4647 } ) ,
4748 } ,
4849 shadowOpacity : elevation . interpolate ( {
@@ -51,8 +52,8 @@ export function shadow(
5152 extrapolate : 'clamp' ,
5253 } ) ,
5354 shadowRadius : elevation . interpolate ( {
54- inputRange : [ ... elevationInputRange ] ,
55- outputRange : [ ... shadowLayers [ 0 ] . shadowRadius ] ,
55+ inputRange : elevationInputRange ,
56+ outputRange : shadowLayers [ 0 ] . shadowRadius ,
5657 } ) ,
5758 } ;
5859 }
0 commit comments