1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = overlay;
|
7 |
|
8 | var _color = _interopRequireDefault(require("color"));
|
9 |
|
10 | var _reactNative = require("react-native");
|
11 |
|
12 | var _DarkTheme = _interopRequireDefault(require("./DarkTheme"));
|
13 |
|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15 |
|
16 | const isAnimatedValue = it => it instanceof _reactNative.Animated.Value;
|
17 |
|
18 | function overlay(elevation) {
|
19 | let surfaceColor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _DarkTheme.default.colors.surface;
|
20 |
|
21 | if (isAnimatedValue(elevation)) {
|
22 | const inputRange = [0, 1, 2, 3, 8, 24];
|
23 |
|
24 | return elevation.interpolate({
|
25 | inputRange,
|
26 | outputRange: inputRange.map(elevation => {
|
27 | return calculateColor(surfaceColor, elevation);
|
28 | })
|
29 | });
|
30 | }
|
31 |
|
32 |
|
33 | return calculateColor(surfaceColor, elevation);
|
34 | }
|
35 |
|
36 | function calculateColor(surfaceColor) {
|
37 | let elevation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
38 | let overlayTransparency;
|
39 |
|
40 | if (elevation >= 1 && elevation <= 24) {
|
41 | overlayTransparency = elevationOverlayTransparency[elevation];
|
42 | } else if (elevation > 24) {
|
43 | overlayTransparency = elevationOverlayTransparency[24];
|
44 | } else {
|
45 | overlayTransparency = elevationOverlayTransparency[1];
|
46 | }
|
47 |
|
48 | return (0, _color.default)(surfaceColor).mix((0, _color.default)('white'), overlayTransparency * 0.01).hex();
|
49 | }
|
50 |
|
51 | const elevationOverlayTransparency = {
|
52 | 1: 5,
|
53 | 2: 7,
|
54 | 3: 8,
|
55 | 4: 9,
|
56 | 5: 10,
|
57 | 6: 11,
|
58 | 7: 11.5,
|
59 | 8: 12,
|
60 | 9: 12.5,
|
61 | 10: 13,
|
62 | 11: 13.5,
|
63 | 12: 14,
|
64 | 13: 14.25,
|
65 | 14: 14.5,
|
66 | 15: 14.75,
|
67 | 16: 15,
|
68 | 17: 15.12,
|
69 | 18: 15.24,
|
70 | 19: 15.36,
|
71 | 20: 15.48,
|
72 | 21: 15.6,
|
73 | 22: 15.72,
|
74 | 23: 15.84,
|
75 | 24: 16
|
76 | };
|
77 |
|
\ | No newline at end of file |