1 | var __rest = (this && this.__rest) || function (s, e) {
|
2 | var t = {};
|
3 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
4 | t[p] = s[p];
|
5 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
6 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
7 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
8 | t[p[i]] = s[p[i]];
|
9 | }
|
10 | return t;
|
11 | };
|
12 | import React from 'react';
|
13 | import { Switch as NativeSwitch, Platform, } from 'react-native';
|
14 | import { withTheme } from '../config';
|
15 | const Switch = (_a) => {
|
16 | var _b, _c, _d;
|
17 | var { value = false, disabled = false, onValueChange, color = 'primary', style, theme } = _a, rest = __rest(_a, ["value", "disabled", "onValueChange", "color", "style", "theme"]);
|
18 |
|
19 | const switchedOnColor = color === 'primary'
|
20 | ? ((_b = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _b === void 0 ? void 0 : _b.primary)
|
21 | ? theme.colors.primary
|
22 | : ''
|
23 | : color;
|
24 | const onTintColor = Platform.OS === 'ios' || !disabled
|
25 | ? switchedOnColor
|
26 | : ((_c = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _c === void 0 ? void 0 : _c.disabled)
|
27 | ? theme.colors.disabled
|
28 | : '';
|
29 | const thumbTintColor = Platform.OS === 'ios'
|
30 | ? undefined
|
31 | : disabled || !value
|
32 | ? (_d = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _d === void 0 ? void 0 : _d.disabled
|
33 | : switchedOnColor;
|
34 | const props = Platform.OS === 'web'
|
35 | ? {
|
36 | activeTrackColor: onTintColor,
|
37 | thumbColor: thumbTintColor,
|
38 | activeThumbColor: switchedOnColor,
|
39 | }
|
40 | : {
|
41 | thumbColor: thumbTintColor,
|
42 | trackColor: {
|
43 | true: onTintColor,
|
44 | false: '',
|
45 | },
|
46 | };
|
47 | return (<NativeSwitch value={value} accessibilityState={{
|
48 | checked: value,
|
49 | disabled,
|
50 | }} disabled={disabled} onValueChange={disabled ? undefined : onValueChange} style={style} {...props} {...rest}/>);
|
51 | };
|
52 | export { Switch };
|
53 | export default withTheme(Switch, 'Switch');
|
54 |
|
\ | No newline at end of file |