@@ -10,7 +10,12 @@ import {
1010} from 'react-native' ;
1111
1212import { useInternalTheme } from '../core/theming' ;
13- import shadow from '../theme/shadow' ;
13+ import {
14+ androidElevationLevels ,
15+ elevationInputRange ,
16+ shadow ,
17+ shadowLayers ,
18+ } from '../theme/tokens/sys/elevation' ;
1419import type { Elevation , Theme , ThemeProp } from '../types' ;
1520import { isAnimatedValue } from '../utils/animations' ;
1621import { forwardRef } from '../utils/forwardRef' ;
@@ -75,54 +80,41 @@ const outerLayerStyleProperties: (keyof ViewStyle)[] = [
7580 'opacity' ,
7681] ;
7782
78- const shadowColor = '#000' ;
79- const iOSShadowOutputRanges = [
80- {
81- shadowOpacity : 0.15 ,
82- height : [ 0 , 1 , 2 , 4 , 6 , 8 ] ,
83- shadowRadius : [ 0 , 3 , 6 , 8 , 10 , 12 ] ,
84- } ,
85- {
86- shadowOpacity : 0.3 ,
87- height : [ 0 , 1 , 1 , 1 , 2 , 4 ] ,
88- shadowRadius : [ 0 , 1 , 2 , 3 , 3 , 4 ] ,
89- } ,
90- ] ;
91- const inputRange = [ 0 , 1 , 2 , 3 , 4 , 5 ] ;
9283function getStyleForShadowLayer (
9384 elevation : SurfaceElevation ,
94- layer : 0 | 1
85+ layer : 0 | 1 ,
86+ shadowColor : string
9587) : Animated . WithAnimatedValue < ShadowStyleIOS > {
9688 if ( isAnimatedValue ( elevation ) ) {
9789 return {
9890 shadowColor,
9991 shadowOpacity : elevation . interpolate ( {
10092 inputRange : [ 0 , 1 ] ,
101- outputRange : [ 0 , iOSShadowOutputRanges [ layer ] . shadowOpacity ] ,
93+ outputRange : [ 0 , shadowLayers [ layer ] . shadowOpacity ] ,
10294 extrapolate : 'clamp' ,
10395 } ) ,
10496 shadowOffset : {
10597 width : 0 ,
10698 height : elevation . interpolate ( {
107- inputRange,
108- outputRange : iOSShadowOutputRanges [ layer ] . height ,
99+ inputRange : [ ... elevationInputRange ] ,
100+ outputRange : [ ... shadowLayers [ layer ] . height ] ,
109101 } ) ,
110102 } ,
111103 shadowRadius : elevation . interpolate ( {
112- inputRange,
113- outputRange : iOSShadowOutputRanges [ layer ] . shadowRadius ,
104+ inputRange : [ ... elevationInputRange ] ,
105+ outputRange : [ ... shadowLayers [ layer ] . shadowRadius ] ,
114106 } ) ,
115107 } ;
116108 }
117109
118110 return {
119111 shadowColor,
120- shadowOpacity : elevation ? iOSShadowOutputRanges [ layer ] . shadowOpacity : 0 ,
112+ shadowOpacity : elevation ? shadowLayers [ layer ] . shadowOpacity : 0 ,
121113 shadowOffset : {
122114 width : 0 ,
123- height : iOSShadowOutputRanges [ layer ] . height [ elevation ] ,
115+ height : shadowLayers [ layer ] . height [ elevation ] ,
124116 } ,
125- shadowRadius : iOSShadowOutputRanges [ layer ] . shadowRadius [ elevation ] ,
117+ shadowRadius : shadowLayers [ layer ] . shadowRadius [ elevation ] ,
126118 } ;
127119}
128120
@@ -131,13 +123,15 @@ const SurfaceIOS = forwardRef<
131123 Omit < Props , 'elevation' > & {
132124 elevation : SurfaceElevation ;
133125 backgroundColor ?: string | Animated . AnimatedInterpolation < string | number > ;
126+ shadowColor : string ;
134127 }
135128> (
136129 (
137130 {
138131 elevation,
139132 style,
140133 backgroundColor,
134+ shadowColor,
141135 testID,
142136 children,
143137 mode = 'elevated' ,
@@ -173,14 +167,14 @@ const SurfaceIOS = forwardRef<
173167 const isElevated = mode === 'elevated' ;
174168
175169 const outerLayerViewStyles = {
176- ...( isElevated && getStyleForShadowLayer ( elevation , 0 ) ) ,
170+ ...( isElevated && getStyleForShadowLayer ( elevation , 0 , shadowColor ) ) ,
177171 ...outerLayerStyles ,
178172 ...borderRadiusStyles ,
179173 backgroundColor : bgColor ,
180174 } ;
181175
182176 const innerLayerViewStyles = {
183- ...( isElevated && getStyleForShadowLayer ( elevation , 1 ) ) ,
177+ ...( isElevated && getStyleForShadowLayer ( elevation , 1 , shadowColor ) ) ,
184178 ...filteredStyles ,
185179 ...borderRadiusStyles ,
186180 flex :
@@ -191,7 +185,7 @@ const SurfaceIOS = forwardRef<
191185 } ;
192186
193187 return [ outerLayerViewStyles , innerLayerViewStyles ] ;
194- } , [ style , elevation , backgroundColor , mode , container ] ) ;
188+ } , [ style , elevation , backgroundColor , shadowColor , mode , container ] ) ;
195189
196190 return (
197191 < Animated . View
@@ -255,13 +249,11 @@ const Surface = forwardRef<View, Props>(
255249
256250 const { colors } = theme as Theme ;
257251
258- const inputRange = [ 0 , 1 , 2 , 3 , 4 , 5 ] ;
259-
260252 const backgroundColor = ( ( ) => {
261253 if ( isAnimatedValue ( elevation ) ) {
262254 return elevation . interpolate ( {
263- inputRange,
264- outputRange : inputRange . map ( ( elevation ) => {
255+ inputRange : [ ... elevationInputRange ] ,
256+ outputRange : [ ... elevationInputRange ] . map ( ( elevation ) => {
265257 return colors . elevation ?. [ `level${ elevation as Elevation } ` ] ;
266258 } ) ,
267259 } ) ;
@@ -282,7 +274,9 @@ const Surface = forwardRef<View, Props>(
282274 testID = { testID }
283275 style = { [
284276 { backgroundColor } ,
285- elevation && isElevated ? shadow ( elevation ) : null ,
277+ elevation && isElevated
278+ ? shadow ( elevation , theme . colors . shadow )
279+ : null ,
286280 style ,
287281 ] }
288282 >
@@ -292,12 +286,12 @@ const Surface = forwardRef<View, Props>(
292286 }
293287
294288 if ( Platform . OS === 'android' ) {
295- const elevationLevel = [ 0 , 3 , 6 , 9 , 12 , 15 ] ;
289+ const elevationLevel = [ ... androidElevationLevels ] ;
296290
297291 const getElevationAndroid = ( ) => {
298292 if ( isAnimatedValue ( elevation ) ) {
299293 return elevation . interpolate ( {
300- inputRange,
294+ inputRange : [ ... elevationInputRange ] ,
301295 outputRange : elevationLevel ,
302296 } ) ;
303297 }
@@ -340,6 +334,7 @@ const Surface = forwardRef<View, Props>(
340334 ref = { ref }
341335 elevation = { elevation }
342336 backgroundColor = { backgroundColor }
337+ shadowColor = { theme . colors . shadow }
343338 style = { style }
344339 testID = { testID }
345340 mode = { mode }
0 commit comments