1 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2 |
|
3 | import * as React from 'react';
|
4 | import { grey400, grey800, grey50, white, black } from '../styles/colors';
|
5 | import { NativeModules, Platform, Switch as NativeSwitch } from 'react-native';
|
6 | import setColor from 'color';
|
7 | import { withTheme } from '../core/theming';
|
8 | const version = NativeModules.PlatformConstants ? NativeModules.PlatformConstants.reactNativeVersion : undefined;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | const Switch = _ref => {
|
49 | let {
|
50 | value,
|
51 | disabled,
|
52 | onValueChange,
|
53 | color,
|
54 | theme,
|
55 | ...rest
|
56 | } = _ref;
|
57 | const checkedColor = color || theme.colors.accent;
|
58 | const onTintColor = Platform.OS === 'ios' ? checkedColor : disabled ? theme.dark ? setColor(white).alpha(0.1).rgb().string() : setColor(black).alpha(0.12).rgb().string() : setColor(checkedColor).alpha(0.5).rgb().string();
|
59 | const thumbTintColor = Platform.OS === 'ios' ? undefined : disabled ? theme.dark ? grey800 : grey400 : value ? checkedColor : theme.dark ? grey400 : grey50;
|
60 | const props = version && version.major === 0 && version.minor <= 56 ? {
|
61 | onTintColor,
|
62 | thumbTintColor
|
63 | } : Platform.OS === 'web' ? {
|
64 | activeTrackColor: onTintColor,
|
65 | thumbColor: thumbTintColor,
|
66 | activeThumbColor: checkedColor
|
67 | } : {
|
68 | thumbColor: thumbTintColor,
|
69 | trackColor: {
|
70 | true: onTintColor,
|
71 | false: ''
|
72 | }
|
73 | };
|
74 | return React.createElement(NativeSwitch, _extends({
|
75 | value: value,
|
76 | disabled: disabled,
|
77 | onValueChange: disabled ? undefined : onValueChange
|
78 | }, props, rest));
|
79 | };
|
80 |
|
81 | export default withTheme(Switch);
|
82 |
|
\ | No newline at end of file |