UNPKG

1.44 kBJavaScriptView Raw
1import * as Colors from './colors';
2import { Animated } from 'react-native';
3const SHADOW_COLOR = Colors.black;
4const SHADOW_OPACITY = 0.24;
5export default function shadow() {
6 let elevation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
7
8 if (elevation instanceof Animated.Value) {
9 const inputRange = [0, 1, 2, 3, 8, 24];
10 return {
11 shadowColor: SHADOW_COLOR,
12 shadowOffset: {
13 width: new Animated.Value(0),
14 height: elevation.interpolate({
15 inputRange,
16 outputRange: [0, 0.5, 0.75, 2, 7, 23]
17 })
18 },
19 shadowOpacity: elevation.interpolate({
20 inputRange: [0, 1],
21 outputRange: [0, SHADOW_OPACITY],
22 extrapolate: 'clamp'
23 }),
24 shadowRadius: elevation.interpolate({
25 inputRange,
26 outputRange: [0, 0.75, 1.5, 3, 8, 24]
27 })
28 };
29 } else {
30 if (elevation === 0) {
31 return {};
32 }
33
34 let height, radius;
35
36 switch (elevation) {
37 case 1:
38 height = 0.5;
39 radius = 0.75;
40 break;
41
42 case 2:
43 height = 0.75;
44 radius = 1.5;
45 break;
46
47 default:
48 height = elevation - 1;
49 radius = elevation;
50 }
51
52 return {
53 shadowColor: SHADOW_COLOR,
54 shadowOffset: {
55 width: 0,
56 height
57 },
58 shadowOpacity: SHADOW_OPACITY,
59 shadowRadius: radius
60 };
61 }
62}
63//# sourceMappingURL=shadow.js.map
\No newline at end of file