@medway-ui/native 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/Switch.js +176 -66
- package/lib/commonjs/components/Switch.js.map +1 -1
- package/lib/module/components/Switch.js +181 -69
- package/lib/module/components/Switch.js.map +1 -1
- package/lib/typescript/components/Switch.d.ts +5 -5
- package/lib/typescript/components/Switch.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Switch.tsx +303 -115
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.Switch =
|
|
7
|
-
exports.switchVariants = void 0;
|
|
6
|
+
exports.switchVariants = exports.Switch = void 0;
|
|
8
7
|
var _react = require("react");
|
|
9
8
|
var _reactNative = require("react-native");
|
|
9
|
+
var _nativewind = require("nativewind");
|
|
10
10
|
var SwitchPrimitive = _interopRequireWildcard(require("@rn-primitives/switch"));
|
|
11
11
|
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
12
12
|
var _classVarianceAuthority = require("class-variance-authority");
|
|
@@ -15,16 +15,29 @@ var _touchTarget = require("@/lib/touch-target");
|
|
|
15
15
|
var _useThemeColor = require("@/hooks/useThemeColor");
|
|
16
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
17
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
18
|
+
// `@rn-primitives/switch` renders a plain Pressable — cssInterop makes `className` work.
|
|
19
|
+
const StyledSwitchRoot = (0, _nativewind.cssInterop)(SwitchPrimitive.Root, {
|
|
20
|
+
className: "style"
|
|
21
|
+
});
|
|
22
|
+
const BORDER_WIDTH = 2;
|
|
23
|
+
/** Gap between thumb and inner edge of the track border (web `translate-x-0.5`). */
|
|
24
|
+
const THUMB_INSET = 2;
|
|
25
|
+
const CENTER = {
|
|
26
|
+
alignItems: "center",
|
|
27
|
+
justifyContent: "center"
|
|
28
|
+
};
|
|
18
29
|
const THUMB_SIZES = {
|
|
19
30
|
sm: 8,
|
|
20
31
|
md: 12,
|
|
21
32
|
lg: 16
|
|
22
33
|
};
|
|
23
|
-
const
|
|
24
|
-
sm:
|
|
25
|
-
md:
|
|
26
|
-
lg:
|
|
34
|
+
const ICON_SIZES = {
|
|
35
|
+
sm: 8,
|
|
36
|
+
md: 12,
|
|
37
|
+
lg: 14
|
|
27
38
|
};
|
|
39
|
+
|
|
40
|
+
/** Same scale as web `h-4 w-6` / `h-5 w-8` / `h-6 w-10` at 16px rem. */
|
|
28
41
|
const SWITCH_DIMENSIONS = {
|
|
29
42
|
sm: {
|
|
30
43
|
width: 24,
|
|
@@ -39,15 +52,43 @@ const SWITCH_DIMENSIONS = {
|
|
|
39
52
|
height: 24
|
|
40
53
|
}
|
|
41
54
|
};
|
|
42
|
-
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Thumb is a sibling of the bordered track (not a child of it), so offsets are
|
|
58
|
+
* from the root's outer box. That avoids Yoga content-box quirks where absolute
|
|
59
|
+
* children of a bordered view shift the knob down / past the right edge.
|
|
60
|
+
*
|
|
61
|
+
* off = border + inset
|
|
62
|
+
* on = width - border - inset - thumb
|
|
63
|
+
* on+disabled keeps a 1px tighter right inset, matching web.
|
|
64
|
+
*/
|
|
65
|
+
function getThumbTranslateX(trackWidth, thumbSize, checked, disabled) {
|
|
66
|
+
const off = BORDER_WIDTH + THUMB_INSET;
|
|
67
|
+
if (!checked) return off;
|
|
68
|
+
const on = trackWidth - BORDER_WIDTH - THUMB_INSET - thumbSize;
|
|
69
|
+
return disabled ? on - 1 : on;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Even curve. A strong ease-out spends the last frames crawling, which reads
|
|
74
|
+
* as the thumb catching. Track and thumb colors ride the same curve.
|
|
75
|
+
*/
|
|
76
|
+
const THUMB_MOTION = {
|
|
77
|
+
duration: 250,
|
|
78
|
+
easing: _reactNativeReanimated.Easing.inOut(_reactNativeReanimated.Easing.cubic)
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Px, not `h-6 w-10`: NativeWind resolves rem as 14px on native, which shrinks
|
|
82
|
+
// the track below SWITCH_DIMENSIONS and pushes the thumb down and out the right.
|
|
83
|
+
const switchVariants = exports.switchVariants = (0, _classVarianceAuthority.cva)("shrink-0", {
|
|
43
84
|
variants: {
|
|
44
85
|
variant: {
|
|
45
86
|
regular: ""
|
|
46
87
|
},
|
|
47
88
|
size: {
|
|
48
|
-
sm: "h-
|
|
49
|
-
md: "h-
|
|
50
|
-
lg: "h-
|
|
89
|
+
sm: "h-[16px] w-[24px]",
|
|
90
|
+
md: "h-[20px] w-[32px]",
|
|
91
|
+
lg: "h-[24px] w-[40px]"
|
|
51
92
|
}
|
|
52
93
|
},
|
|
53
94
|
defaultVariants: {
|
|
@@ -55,90 +96,159 @@ const switchVariants = exports.switchVariants = (0, _classVarianceAuthority.cva)
|
|
|
55
96
|
size: "md"
|
|
56
97
|
}
|
|
57
98
|
});
|
|
58
|
-
function
|
|
99
|
+
function renderThumbIcon(icon, color, size) {
|
|
100
|
+
if (! /*#__PURE__*/(0, _react.isValidElement)(icon)) return icon;
|
|
101
|
+
return /*#__PURE__*/(0, _react.cloneElement)(icon, {
|
|
102
|
+
color: icon.props.color ?? color,
|
|
103
|
+
width: icon.props.width ?? size,
|
|
104
|
+
height: icon.props.height ?? size
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function SwitchThumbIcons({
|
|
108
|
+
progress,
|
|
109
|
+
checkedIcon,
|
|
110
|
+
uncheckedIcon,
|
|
111
|
+
checkedIconColor,
|
|
112
|
+
uncheckedIconColor,
|
|
113
|
+
iconSize
|
|
114
|
+
}) {
|
|
115
|
+
const checkedIconStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
|
116
|
+
opacity: progress.value
|
|
117
|
+
}));
|
|
118
|
+
const uncheckedIconStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
|
119
|
+
opacity: 1 - progress.value
|
|
120
|
+
}));
|
|
121
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
122
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
123
|
+
style: [_reactNative.StyleSheet.absoluteFill, CENTER, uncheckedIconStyle],
|
|
124
|
+
children: renderThumbIcon(uncheckedIcon, uncheckedIconColor, iconSize)
|
|
125
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
126
|
+
style: [_reactNative.StyleSheet.absoluteFill, CENTER, checkedIconStyle],
|
|
127
|
+
children: renderThumbIcon(checkedIcon, checkedIconColor, iconSize)
|
|
128
|
+
})]
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
const Switch = exports.Switch = /*#__PURE__*/(0, _react.memo)(function Switch({
|
|
59
132
|
className,
|
|
60
133
|
size = "md",
|
|
61
|
-
variant,
|
|
134
|
+
variant = "regular",
|
|
62
135
|
checkedIcon,
|
|
63
136
|
uncheckedIcon,
|
|
64
137
|
checked,
|
|
65
138
|
defaultChecked,
|
|
66
139
|
onCheckedChange,
|
|
67
|
-
disabled,
|
|
140
|
+
disabled = false,
|
|
68
141
|
style,
|
|
69
142
|
...props
|
|
70
143
|
}) {
|
|
71
144
|
const resolvedSize = size ?? "md";
|
|
72
145
|
const dimensions = SWITCH_DIMENSIONS[resolvedSize];
|
|
146
|
+
const thumbSize = THUMB_SIZES[resolvedSize];
|
|
147
|
+
const iconSize = ICON_SIZES[resolvedSize];
|
|
73
148
|
const [internalChecked, setInternalChecked] = (0, _react.useState)(defaultChecked ?? false);
|
|
74
149
|
const isControlled = checked !== undefined;
|
|
75
|
-
const isChecked = isControlled ? checked
|
|
76
|
-
const trackOn = (0, _useThemeColor.useThemeColor)("primary-background-fill");
|
|
77
|
-
const trackOff = (0, _useThemeColor.useThemeColor)("surface-card");
|
|
78
|
-
const trackDisabled = (0, _useThemeColor.useThemeColor)("gray-background-soft-muted");
|
|
79
|
-
const trackBorder = (0, _useThemeColor.useThemeColor)("gray-stroke-muted");
|
|
80
|
-
const thumbOn = (0, _useThemeColor.useThemeColor)("primary-foreground-onfill");
|
|
81
|
-
const thumbOff = (0, _useThemeColor.useThemeColor)("gray-foreground-muted");
|
|
82
|
-
const thumbDisabled = (0, _useThemeColor.useThemeColor)("gray-background-fill-muted");
|
|
83
|
-
const translateX = (0, _reactNativeReanimated.useSharedValue)(isChecked ? THUMB_TRANSLATE[resolvedSize] : 2);
|
|
84
|
-
(0, _react.useEffect)(() => {
|
|
85
|
-
translateX.value = (0, _reactNativeReanimated.withTiming)(isChecked ? THUMB_TRANSLATE[resolvedSize] : 2, {
|
|
86
|
-
duration: 180,
|
|
87
|
-
easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.ease)
|
|
88
|
-
});
|
|
89
|
-
}, [isChecked, resolvedSize, translateX]);
|
|
90
|
-
const thumbStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
|
91
|
-
transform: [{
|
|
92
|
-
translateX: translateX.value
|
|
93
|
-
}]
|
|
94
|
-
}));
|
|
150
|
+
const isChecked = isControlled ? checked : internalChecked;
|
|
95
151
|
const hasIcons = Boolean(checkedIcon || uncheckedIcon);
|
|
96
|
-
const
|
|
152
|
+
const checkedIconColor = (0, _useThemeColor.useThemeColor)(disabled ? "gray-300" : "primary-foreground-onfill");
|
|
153
|
+
const uncheckedIconColor = (0, _useThemeColor.useThemeColor)(disabled ? "gray-300" : "gray-foreground");
|
|
154
|
+
const trackOffColor = (0, _useThemeColor.useThemeColor)(disabled ? "gray-background-soft-muted" : "surface-card");
|
|
155
|
+
const trackOnColor = (0, _useThemeColor.useThemeColor)(disabled ? "gray-background-soft-muted" : "primary-background-fill");
|
|
156
|
+
const borderOffColor = (0, _useThemeColor.useThemeColor)("gray-stroke-muted");
|
|
157
|
+
const borderOnColor = disabled ? borderOffColor : (0, _useThemeColor.withAlpha)(borderOffColor, 0);
|
|
158
|
+
const thumbDisabledColor = (0, _useThemeColor.useThemeColor)("gray-background-fill-muted");
|
|
159
|
+
const thumbOnToken = (0, _useThemeColor.useThemeColor)("primary-foreground-onfill");
|
|
160
|
+
const thumbOffToken = (0, _useThemeColor.useThemeColor)("gray-foreground-muted");
|
|
161
|
+
const thumbOffColor = hasIcons ? "rgba(0, 0, 0, 0)" : disabled ? thumbDisabledColor : thumbOffToken;
|
|
162
|
+
const thumbOnColor = hasIcons ? "rgba(0, 0, 0, 0)" : disabled ? thumbDisabledColor : thumbOnToken;
|
|
163
|
+
const offX = getThumbTranslateX(dimensions.width, thumbSize, false, disabled);
|
|
164
|
+
const onX = getThumbTranslateX(dimensions.width, thumbSize, true, disabled);
|
|
165
|
+
// Root has no border — center against the outer height.
|
|
166
|
+
const thumbTop = (dimensions.height - thumbSize) / 2;
|
|
167
|
+
|
|
168
|
+
// Single UI-thread driver for position, colors and icons. In controlled mode
|
|
169
|
+
// the visual only moves when `checked` changes (same as the web Radix switch).
|
|
170
|
+
const progress = (0, _reactNativeReanimated.useSharedValue)(isChecked ? 1 : 0);
|
|
171
|
+
const targetRef = (0, _react.useRef)(isChecked);
|
|
172
|
+
const animateTo = next => {
|
|
173
|
+
if (targetRef.current === next) return;
|
|
174
|
+
targetRef.current = next;
|
|
175
|
+
progress.value = (0, _reactNativeReanimated.withTiming)(next ? 1 : 0, THUMB_MOTION);
|
|
176
|
+
};
|
|
177
|
+
(0, _react.useLayoutEffect)(() => {
|
|
178
|
+
animateTo(isChecked);
|
|
179
|
+
}, [isChecked]);
|
|
97
180
|
const handleCheckedChange = nextChecked => {
|
|
98
|
-
if (!isControlled)
|
|
181
|
+
if (!isControlled) {
|
|
182
|
+
animateTo(nextChecked);
|
|
183
|
+
setInternalChecked(nextChecked);
|
|
184
|
+
}
|
|
99
185
|
onCheckedChange?.(nextChecked);
|
|
100
186
|
};
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
187
|
+
const trackMotionStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
|
188
|
+
backgroundColor: (0, _reactNativeReanimated.interpolateColor)(progress.value, [0, 1], [trackOffColor, trackOnColor]),
|
|
189
|
+
borderColor: (0, _reactNativeReanimated.interpolateColor)(progress.value, [0, 1], [borderOffColor, borderOnColor])
|
|
190
|
+
}));
|
|
191
|
+
const thumbMotionStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
|
192
|
+
transform: [{
|
|
193
|
+
translateX: offX + (onX - offX) * progress.value
|
|
194
|
+
}]
|
|
195
|
+
}), [offX, onX]);
|
|
196
|
+
const thumbColorStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
|
197
|
+
backgroundColor: (0, _reactNativeReanimated.interpolateColor)(progress.value, [0, 1], [thumbOffColor, thumbOnColor])
|
|
198
|
+
}));
|
|
199
|
+
const baseRootStyle = (0, _react.useMemo)(() => ({
|
|
105
200
|
width: dimensions.width,
|
|
106
201
|
height: dimensions.height,
|
|
107
202
|
minWidth: dimensions.width,
|
|
108
203
|
minHeight: dimensions.height,
|
|
109
204
|
borderRadius: dimensions.height / 2,
|
|
110
|
-
borderWidth:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
205
|
+
borderWidth: 0,
|
|
206
|
+
padding: 0,
|
|
207
|
+
overflow: "visible"
|
|
208
|
+
}), [dimensions.height, dimensions.width]);
|
|
209
|
+
const trackStyle = (0, _react.useMemo)(() => ({
|
|
210
|
+
..._reactNative.StyleSheet.absoluteFill,
|
|
211
|
+
borderRadius: dimensions.height / 2,
|
|
212
|
+
borderWidth: BORDER_WIDTH
|
|
213
|
+
}), [dimensions.height]);
|
|
214
|
+
const thumbStyle = (0, _react.useMemo)(() => ({
|
|
215
|
+
position: "absolute",
|
|
216
|
+
top: thumbTop,
|
|
217
|
+
left: 0,
|
|
218
|
+
width: thumbSize,
|
|
219
|
+
height: thumbSize,
|
|
220
|
+
borderRadius: thumbSize / 2,
|
|
221
|
+
alignItems: "center",
|
|
222
|
+
justifyContent: "center"
|
|
223
|
+
}), [thumbSize, thumbTop]);
|
|
224
|
+
const hitSlop = (0, _react.useMemo)(() => (0, _touchTarget.getMinTouchHitSlop)(dimensions.width, dimensions.height), [dimensions.height, dimensions.width]);
|
|
225
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledSwitchRoot, {
|
|
226
|
+
hitSlop: hitSlop,
|
|
227
|
+
...props,
|
|
117
228
|
checked: isChecked,
|
|
118
229
|
onCheckedChange: handleCheckedChange,
|
|
119
230
|
disabled: disabled,
|
|
120
|
-
hitSlop: (0, _touchTarget.getMinTouchHitSlop)(dimensions.width, dimensions.height),
|
|
121
|
-
style: state => [rootStyle, typeof style === "function" ? style(state) : style],
|
|
122
231
|
className: (0, _utils.cn)(switchVariants({
|
|
123
|
-
size,
|
|
232
|
+
size: resolvedSize,
|
|
124
233
|
variant
|
|
125
234
|
}), className),
|
|
126
|
-
|
|
127
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
235
|
+
style: state => [baseRootStyle, typeof style === "function" ? style(state) : style],
|
|
236
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
237
|
+
pointerEvents: "none",
|
|
238
|
+
style: [trackStyle, trackMotionStyle]
|
|
239
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
240
|
+
pointerEvents: "none",
|
|
241
|
+
collapsable: false,
|
|
242
|
+
style: [thumbStyle, thumbMotionStyle, thumbColorStyle],
|
|
243
|
+
children: hasIcons ? /*#__PURE__*/(0, _jsxRuntime.jsx)(SwitchThumbIcons, {
|
|
244
|
+
progress: progress,
|
|
245
|
+
checkedIcon: checkedIcon,
|
|
246
|
+
uncheckedIcon: uncheckedIcon,
|
|
247
|
+
checkedIconColor: checkedIconColor,
|
|
248
|
+
uncheckedIconColor: uncheckedIconColor,
|
|
249
|
+
iconSize: iconSize
|
|
250
|
+
}) : null
|
|
251
|
+
})]
|
|
142
252
|
});
|
|
143
|
-
}
|
|
253
|
+
});
|
|
144
254
|
//# sourceMappingURL=Switch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","SwitchPrimitive","_interopRequireWildcard","_reactNativeReanimated","_classVarianceAuthority","_utils","_touchTarget","_useThemeColor","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","THUMB_SIZES","sm","md","lg","THUMB_TRANSLATE","SWITCH_DIMENSIONS","width","height","switchVariants","exports","cva","variants","variant","regular","size","defaultVariants","Switch","className","checkedIcon","uncheckedIcon","checked","defaultChecked","onCheckedChange","disabled","style","props","resolvedSize","dimensions","internalChecked","setInternalChecked","useState","isControlled","undefined","isChecked","trackOn","useThemeColor","trackOff","trackDisabled","trackBorder","thumbOn","thumbOff","thumbDisabled","translateX","useSharedValue","useEffect","value","withTiming","duration","easing","Easing","out","ease","thumbStyle","useAnimatedStyle","transform","hasIcons","Boolean","thumbSize","handleCheckedChange","nextChecked","trackBackgroundColor","trackBorderColor","thumbBackgroundColor","rootStyle","minWidth","minHeight","borderRadius","borderWidth","alignItems","justifyContent","backgroundColor","borderColor","jsx","Root","hitSlop","getMinTouchHitSlop","state","cn","children","Thumb","asChild","View","jsxs"],"sourceRoot":"../../../src","sources":["components/Switch.tsx"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAD,uBAAA,CAAAH,OAAA;AAMA,IAAAK,uBAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,YAAA,GAAAP,OAAA;AACA,IAAAQ,cAAA,GAAAR,OAAA;AAAsD,IAAAS,WAAA,GAAAT,OAAA;AAAA,SAAAG,wBAAAO,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAO,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA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Ae,EAAEoC,mBAAoB;IACrCnC,QAAQ,EAAEA,QAAS;IACnBmD,OAAO,EAAE,IAAAC,+BAAkB,EAAChD,UAAU,CAACrB,KAAK,EAAEqB,UAAU,CAACpB,MAAM,CAAE;IACjEiB,KAAK,EAAGoD,KAAK,IAAK,CAChBb,SAAS,EACT,OAAOvC,KAAK,KAAK,UAAU,GAAGA,KAAK,CAACoD,KAAK,CAAC,GAAGpD,KAAK,CAClD;IACFP,SAAS,EAAE,IAAA4D,SAAE,EAACrE,cAAc,CAAC;MAAEM,IAAI;MAAEF;IAAQ,CAAC,CAAC,EAAEK,SAAS,CAAE;IAAA,GACxDQ,KAAK;IAAAqD,QAAA,eAET,IAAAlG,WAAA,CAAA4F,GAAA,EAACnG,eAAe,CAAC0G,KAAK;MAACC,OAAO;MAAAF,QAAA,eAC5B,IAAAlG,WAAA,CAAA4F,GAAA,EAACjG,sBAAA,CAAAgB,OAAQ,CAAC0F,IAAI;QACZzD,KAAK,EAAE,CACL4B,UAAU,EACV;UACE9C,KAAK,EAAEmD,SAAS;UAChBlD,MAAM,EAAEkD,SAAS;UACjBS,YAAY,EAAET,SAAS,GAAG,CAAC;UAC3Ba,eAAe,EAAER;QACnB,CAAC,CACD;QAAAgB,QAAA,EAEDvB,QAAQ,gBACP,IAAA3E,WAAA,CAAAsG,IAAA,EAAC9G,YAAA,CAAA6G,IAAI;UAAChE,SAAS,EAAC,oCAAoC;UAAA6D,QAAA,GACjD7C,SAAS,IAAIf,WAAW,EACxB,CAACe,SAAS,IAAId,aAAa;QAAA,CACxB,CAAC,GACL;MAAI,CACK;IAAC,CACK;EAAC,CACJ,CAAC;AAE3B","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_nativewind","SwitchPrimitive","_interopRequireWildcard","_reactNativeReanimated","_classVarianceAuthority","_utils","_touchTarget","_useThemeColor","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","StyledSwitchRoot","cssInterop","Root","className","BORDER_WIDTH","THUMB_INSET","CENTER","alignItems","justifyContent","THUMB_SIZES","sm","md","lg","ICON_SIZES","SWITCH_DIMENSIONS","width","height","getThumbTranslateX","trackWidth","thumbSize","checked","disabled","off","on","THUMB_MOTION","duration","easing","Easing","inOut","cubic","switchVariants","exports","cva","variants","variant","regular","size","defaultVariants","renderThumbIcon","icon","color","isValidElement","cloneElement","props","SwitchThumbIcons","progress","checkedIcon","uncheckedIcon","checkedIconColor","uncheckedIconColor","iconSize","checkedIconStyle","useAnimatedStyle","opacity","value","uncheckedIconStyle","jsxs","Fragment","children","jsx","View","style","StyleSheet","absoluteFill","Switch","memo","defaultChecked","onCheckedChange","resolvedSize","dimensions","internalChecked","setInternalChecked","useState","isControlled","undefined","isChecked","hasIcons","Boolean","useThemeColor","trackOffColor","trackOnColor","borderOffColor","borderOnColor","withAlpha","thumbDisabledColor","thumbOnToken","thumbOffToken","thumbOffColor","thumbOnColor","offX","onX","thumbTop","useSharedValue","targetRef","useRef","animateTo","next","current","withTiming","useLayoutEffect","handleCheckedChange","nextChecked","trackMotionStyle","backgroundColor","interpolateColor","borderColor","thumbMotionStyle","transform","translateX","thumbColorStyle","baseRootStyle","useMemo","minWidth","minHeight","borderRadius","borderWidth","padding","overflow","trackStyle","thumbStyle","position","top","left","hitSlop","getMinTouchHitSlop","cn","state","pointerEvents","collapsable"],"sourceRoot":"../../../src","sources":["components/Switch.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAWA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAC,uBAAA,CAAAJ,OAAA;AACA,IAAAK,sBAAA,GAAAD,uBAAA,CAAAJ,OAAA;AAQA,IAAAM,uBAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,YAAA,GAAAR,OAAA;AACA,I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C","ignoreList":[]}
|
|
@@ -1,24 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { cloneElement, isValidElement, memo, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { StyleSheet } from "react-native";
|
|
5
|
+
import { cssInterop } from "nativewind";
|
|
5
6
|
import * as SwitchPrimitive from "@rn-primitives/switch";
|
|
6
|
-
import Animated, {
|
|
7
|
+
import Animated, { Easing, interpolateColor, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
7
8
|
import { cva } from "class-variance-authority";
|
|
8
9
|
import { cn } from "@/lib/utils";
|
|
9
10
|
import { getMinTouchHitSlop } from "@/lib/touch-target";
|
|
10
|
-
import { useThemeColor } from "@/hooks/useThemeColor";
|
|
11
|
-
|
|
11
|
+
import { useThemeColor, withAlpha } from "@/hooks/useThemeColor";
|
|
12
|
+
|
|
13
|
+
// `@rn-primitives/switch` renders a plain Pressable — cssInterop makes `className` work.
|
|
14
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
const StyledSwitchRoot = cssInterop(SwitchPrimitive.Root, {
|
|
16
|
+
className: "style"
|
|
17
|
+
});
|
|
18
|
+
const BORDER_WIDTH = 2;
|
|
19
|
+
/** Gap between thumb and inner edge of the track border (web `translate-x-0.5`). */
|
|
20
|
+
const THUMB_INSET = 2;
|
|
21
|
+
const CENTER = {
|
|
22
|
+
alignItems: "center",
|
|
23
|
+
justifyContent: "center"
|
|
24
|
+
};
|
|
12
25
|
const THUMB_SIZES = {
|
|
13
26
|
sm: 8,
|
|
14
27
|
md: 12,
|
|
15
28
|
lg: 16
|
|
16
29
|
};
|
|
17
|
-
const
|
|
18
|
-
sm:
|
|
19
|
-
md:
|
|
20
|
-
lg:
|
|
30
|
+
const ICON_SIZES = {
|
|
31
|
+
sm: 8,
|
|
32
|
+
md: 12,
|
|
33
|
+
lg: 14
|
|
21
34
|
};
|
|
35
|
+
|
|
36
|
+
/** Same scale as web `h-4 w-6` / `h-5 w-8` / `h-6 w-10` at 16px rem. */
|
|
22
37
|
const SWITCH_DIMENSIONS = {
|
|
23
38
|
sm: {
|
|
24
39
|
width: 24,
|
|
@@ -33,15 +48,43 @@ const SWITCH_DIMENSIONS = {
|
|
|
33
48
|
height: 24
|
|
34
49
|
}
|
|
35
50
|
};
|
|
36
|
-
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Thumb is a sibling of the bordered track (not a child of it), so offsets are
|
|
54
|
+
* from the root's outer box. That avoids Yoga content-box quirks where absolute
|
|
55
|
+
* children of a bordered view shift the knob down / past the right edge.
|
|
56
|
+
*
|
|
57
|
+
* off = border + inset
|
|
58
|
+
* on = width - border - inset - thumb
|
|
59
|
+
* on+disabled keeps a 1px tighter right inset, matching web.
|
|
60
|
+
*/
|
|
61
|
+
function getThumbTranslateX(trackWidth, thumbSize, checked, disabled) {
|
|
62
|
+
const off = BORDER_WIDTH + THUMB_INSET;
|
|
63
|
+
if (!checked) return off;
|
|
64
|
+
const on = trackWidth - BORDER_WIDTH - THUMB_INSET - thumbSize;
|
|
65
|
+
return disabled ? on - 1 : on;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Even curve. A strong ease-out spends the last frames crawling, which reads
|
|
70
|
+
* as the thumb catching. Track and thumb colors ride the same curve.
|
|
71
|
+
*/
|
|
72
|
+
const THUMB_MOTION = {
|
|
73
|
+
duration: 250,
|
|
74
|
+
easing: Easing.inOut(Easing.cubic)
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Px, not `h-6 w-10`: NativeWind resolves rem as 14px on native, which shrinks
|
|
78
|
+
// the track below SWITCH_DIMENSIONS and pushes the thumb down and out the right.
|
|
79
|
+
const switchVariants = cva("shrink-0", {
|
|
37
80
|
variants: {
|
|
38
81
|
variant: {
|
|
39
82
|
regular: ""
|
|
40
83
|
},
|
|
41
84
|
size: {
|
|
42
|
-
sm: "h-
|
|
43
|
-
md: "h-
|
|
44
|
-
lg: "h-
|
|
85
|
+
sm: "h-[16px] w-[24px]",
|
|
86
|
+
md: "h-[20px] w-[32px]",
|
|
87
|
+
lg: "h-[24px] w-[40px]"
|
|
45
88
|
}
|
|
46
89
|
},
|
|
47
90
|
defaultVariants: {
|
|
@@ -49,91 +92,160 @@ const switchVariants = cva("rounded-full border-2 items-center shrink-0", {
|
|
|
49
92
|
size: "md"
|
|
50
93
|
}
|
|
51
94
|
});
|
|
52
|
-
function
|
|
95
|
+
function renderThumbIcon(icon, color, size) {
|
|
96
|
+
if (! /*#__PURE__*/isValidElement(icon)) return icon;
|
|
97
|
+
return /*#__PURE__*/cloneElement(icon, {
|
|
98
|
+
color: icon.props.color ?? color,
|
|
99
|
+
width: icon.props.width ?? size,
|
|
100
|
+
height: icon.props.height ?? size
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function SwitchThumbIcons({
|
|
104
|
+
progress,
|
|
105
|
+
checkedIcon,
|
|
106
|
+
uncheckedIcon,
|
|
107
|
+
checkedIconColor,
|
|
108
|
+
uncheckedIconColor,
|
|
109
|
+
iconSize
|
|
110
|
+
}) {
|
|
111
|
+
const checkedIconStyle = useAnimatedStyle(() => ({
|
|
112
|
+
opacity: progress.value
|
|
113
|
+
}));
|
|
114
|
+
const uncheckedIconStyle = useAnimatedStyle(() => ({
|
|
115
|
+
opacity: 1 - progress.value
|
|
116
|
+
}));
|
|
117
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
118
|
+
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
119
|
+
style: [StyleSheet.absoluteFill, CENTER, uncheckedIconStyle],
|
|
120
|
+
children: renderThumbIcon(uncheckedIcon, uncheckedIconColor, iconSize)
|
|
121
|
+
}), /*#__PURE__*/_jsx(Animated.View, {
|
|
122
|
+
style: [StyleSheet.absoluteFill, CENTER, checkedIconStyle],
|
|
123
|
+
children: renderThumbIcon(checkedIcon, checkedIconColor, iconSize)
|
|
124
|
+
})]
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const Switch = /*#__PURE__*/memo(function Switch({
|
|
53
128
|
className,
|
|
54
129
|
size = "md",
|
|
55
|
-
variant,
|
|
130
|
+
variant = "regular",
|
|
56
131
|
checkedIcon,
|
|
57
132
|
uncheckedIcon,
|
|
58
133
|
checked,
|
|
59
134
|
defaultChecked,
|
|
60
135
|
onCheckedChange,
|
|
61
|
-
disabled,
|
|
136
|
+
disabled = false,
|
|
62
137
|
style,
|
|
63
138
|
...props
|
|
64
139
|
}) {
|
|
65
140
|
const resolvedSize = size ?? "md";
|
|
66
141
|
const dimensions = SWITCH_DIMENSIONS[resolvedSize];
|
|
142
|
+
const thumbSize = THUMB_SIZES[resolvedSize];
|
|
143
|
+
const iconSize = ICON_SIZES[resolvedSize];
|
|
67
144
|
const [internalChecked, setInternalChecked] = useState(defaultChecked ?? false);
|
|
68
145
|
const isControlled = checked !== undefined;
|
|
69
|
-
const isChecked = isControlled ? checked
|
|
70
|
-
const trackOn = useThemeColor("primary-background-fill");
|
|
71
|
-
const trackOff = useThemeColor("surface-card");
|
|
72
|
-
const trackDisabled = useThemeColor("gray-background-soft-muted");
|
|
73
|
-
const trackBorder = useThemeColor("gray-stroke-muted");
|
|
74
|
-
const thumbOn = useThemeColor("primary-foreground-onfill");
|
|
75
|
-
const thumbOff = useThemeColor("gray-foreground-muted");
|
|
76
|
-
const thumbDisabled = useThemeColor("gray-background-fill-muted");
|
|
77
|
-
const translateX = useSharedValue(isChecked ? THUMB_TRANSLATE[resolvedSize] : 2);
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
translateX.value = withTiming(isChecked ? THUMB_TRANSLATE[resolvedSize] : 2, {
|
|
80
|
-
duration: 180,
|
|
81
|
-
easing: Easing.out(Easing.ease)
|
|
82
|
-
});
|
|
83
|
-
}, [isChecked, resolvedSize, translateX]);
|
|
84
|
-
const thumbStyle = useAnimatedStyle(() => ({
|
|
85
|
-
transform: [{
|
|
86
|
-
translateX: translateX.value
|
|
87
|
-
}]
|
|
88
|
-
}));
|
|
146
|
+
const isChecked = isControlled ? checked : internalChecked;
|
|
89
147
|
const hasIcons = Boolean(checkedIcon || uncheckedIcon);
|
|
90
|
-
const
|
|
148
|
+
const checkedIconColor = useThemeColor(disabled ? "gray-300" : "primary-foreground-onfill");
|
|
149
|
+
const uncheckedIconColor = useThemeColor(disabled ? "gray-300" : "gray-foreground");
|
|
150
|
+
const trackOffColor = useThemeColor(disabled ? "gray-background-soft-muted" : "surface-card");
|
|
151
|
+
const trackOnColor = useThemeColor(disabled ? "gray-background-soft-muted" : "primary-background-fill");
|
|
152
|
+
const borderOffColor = useThemeColor("gray-stroke-muted");
|
|
153
|
+
const borderOnColor = disabled ? borderOffColor : withAlpha(borderOffColor, 0);
|
|
154
|
+
const thumbDisabledColor = useThemeColor("gray-background-fill-muted");
|
|
155
|
+
const thumbOnToken = useThemeColor("primary-foreground-onfill");
|
|
156
|
+
const thumbOffToken = useThemeColor("gray-foreground-muted");
|
|
157
|
+
const thumbOffColor = hasIcons ? "rgba(0, 0, 0, 0)" : disabled ? thumbDisabledColor : thumbOffToken;
|
|
158
|
+
const thumbOnColor = hasIcons ? "rgba(0, 0, 0, 0)" : disabled ? thumbDisabledColor : thumbOnToken;
|
|
159
|
+
const offX = getThumbTranslateX(dimensions.width, thumbSize, false, disabled);
|
|
160
|
+
const onX = getThumbTranslateX(dimensions.width, thumbSize, true, disabled);
|
|
161
|
+
// Root has no border — center against the outer height.
|
|
162
|
+
const thumbTop = (dimensions.height - thumbSize) / 2;
|
|
163
|
+
|
|
164
|
+
// Single UI-thread driver for position, colors and icons. In controlled mode
|
|
165
|
+
// the visual only moves when `checked` changes (same as the web Radix switch).
|
|
166
|
+
const progress = useSharedValue(isChecked ? 1 : 0);
|
|
167
|
+
const targetRef = useRef(isChecked);
|
|
168
|
+
const animateTo = next => {
|
|
169
|
+
if (targetRef.current === next) return;
|
|
170
|
+
targetRef.current = next;
|
|
171
|
+
progress.value = withTiming(next ? 1 : 0, THUMB_MOTION);
|
|
172
|
+
};
|
|
173
|
+
useLayoutEffect(() => {
|
|
174
|
+
animateTo(isChecked);
|
|
175
|
+
}, [isChecked]);
|
|
91
176
|
const handleCheckedChange = nextChecked => {
|
|
92
|
-
if (!isControlled)
|
|
177
|
+
if (!isControlled) {
|
|
178
|
+
animateTo(nextChecked);
|
|
179
|
+
setInternalChecked(nextChecked);
|
|
180
|
+
}
|
|
93
181
|
onCheckedChange?.(nextChecked);
|
|
94
182
|
};
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
183
|
+
const trackMotionStyle = useAnimatedStyle(() => ({
|
|
184
|
+
backgroundColor: interpolateColor(progress.value, [0, 1], [trackOffColor, trackOnColor]),
|
|
185
|
+
borderColor: interpolateColor(progress.value, [0, 1], [borderOffColor, borderOnColor])
|
|
186
|
+
}));
|
|
187
|
+
const thumbMotionStyle = useAnimatedStyle(() => ({
|
|
188
|
+
transform: [{
|
|
189
|
+
translateX: offX + (onX - offX) * progress.value
|
|
190
|
+
}]
|
|
191
|
+
}), [offX, onX]);
|
|
192
|
+
const thumbColorStyle = useAnimatedStyle(() => ({
|
|
193
|
+
backgroundColor: interpolateColor(progress.value, [0, 1], [thumbOffColor, thumbOnColor])
|
|
194
|
+
}));
|
|
195
|
+
const baseRootStyle = useMemo(() => ({
|
|
99
196
|
width: dimensions.width,
|
|
100
197
|
height: dimensions.height,
|
|
101
198
|
minWidth: dimensions.width,
|
|
102
199
|
minHeight: dimensions.height,
|
|
103
200
|
borderRadius: dimensions.height / 2,
|
|
104
|
-
borderWidth:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
201
|
+
borderWidth: 0,
|
|
202
|
+
padding: 0,
|
|
203
|
+
overflow: "visible"
|
|
204
|
+
}), [dimensions.height, dimensions.width]);
|
|
205
|
+
const trackStyle = useMemo(() => ({
|
|
206
|
+
...StyleSheet.absoluteFill,
|
|
207
|
+
borderRadius: dimensions.height / 2,
|
|
208
|
+
borderWidth: BORDER_WIDTH
|
|
209
|
+
}), [dimensions.height]);
|
|
210
|
+
const thumbStyle = useMemo(() => ({
|
|
211
|
+
position: "absolute",
|
|
212
|
+
top: thumbTop,
|
|
213
|
+
left: 0,
|
|
214
|
+
width: thumbSize,
|
|
215
|
+
height: thumbSize,
|
|
216
|
+
borderRadius: thumbSize / 2,
|
|
217
|
+
alignItems: "center",
|
|
218
|
+
justifyContent: "center"
|
|
219
|
+
}), [thumbSize, thumbTop]);
|
|
220
|
+
const hitSlop = useMemo(() => getMinTouchHitSlop(dimensions.width, dimensions.height), [dimensions.height, dimensions.width]);
|
|
221
|
+
return /*#__PURE__*/_jsxs(StyledSwitchRoot, {
|
|
222
|
+
hitSlop: hitSlop,
|
|
223
|
+
...props,
|
|
111
224
|
checked: isChecked,
|
|
112
225
|
onCheckedChange: handleCheckedChange,
|
|
113
226
|
disabled: disabled,
|
|
114
|
-
hitSlop: getMinTouchHitSlop(dimensions.width, dimensions.height),
|
|
115
|
-
style: state => [rootStyle, typeof style === "function" ? style(state) : style],
|
|
116
227
|
className: cn(switchVariants({
|
|
117
|
-
size,
|
|
228
|
+
size: resolvedSize,
|
|
118
229
|
variant
|
|
119
230
|
}), className),
|
|
120
|
-
|
|
121
|
-
children: /*#__PURE__*/_jsx(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
231
|
+
style: state => [baseRootStyle, typeof style === "function" ? style(state) : style],
|
|
232
|
+
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
233
|
+
pointerEvents: "none",
|
|
234
|
+
style: [trackStyle, trackMotionStyle]
|
|
235
|
+
}), /*#__PURE__*/_jsx(Animated.View, {
|
|
236
|
+
pointerEvents: "none",
|
|
237
|
+
collapsable: false,
|
|
238
|
+
style: [thumbStyle, thumbMotionStyle, thumbColorStyle],
|
|
239
|
+
children: hasIcons ? /*#__PURE__*/_jsx(SwitchThumbIcons, {
|
|
240
|
+
progress: progress,
|
|
241
|
+
checkedIcon: checkedIcon,
|
|
242
|
+
uncheckedIcon: uncheckedIcon,
|
|
243
|
+
checkedIconColor: checkedIconColor,
|
|
244
|
+
uncheckedIconColor: uncheckedIconColor,
|
|
245
|
+
iconSize: iconSize
|
|
246
|
+
}) : null
|
|
247
|
+
})]
|
|
136
248
|
});
|
|
137
|
-
}
|
|
249
|
+
});
|
|
138
250
|
export { Switch, switchVariants };
|
|
139
251
|
//# sourceMappingURL=Switch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","
|
|
1
|
+
{"version":3,"names":["cloneElement","isValidElement","memo","useLayoutEffect","useMemo","useRef","useState","StyleSheet","cssInterop","SwitchPrimitive","Animated","Easing","interpolateColor","useAnimatedStyle","useSharedValue","withTiming","cva","cn","getMinTouchHitSlop","useThemeColor","withAlpha","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","StyledSwitchRoot","Root","className","BORDER_WIDTH","THUMB_INSET","CENTER","alignItems","justifyContent","THUMB_SIZES","sm","md","lg","ICON_SIZES","SWITCH_DIMENSIONS","width","height","getThumbTranslateX","trackWidth","thumbSize","checked","disabled","off","on","THUMB_MOTION","duration","easing","inOut","cubic","switchVariants","variants","variant","regular","size","defaultVariants","renderThumbIcon","icon","color","props","SwitchThumbIcons","progress","checkedIcon","uncheckedIcon","checkedIconColor","uncheckedIconColor","iconSize","checkedIconStyle","opacity","value","uncheckedIconStyle","children","View","style","absoluteFill","Switch","defaultChecked","onCheckedChange","resolvedSize","dimensions","internalChecked","setInternalChecked","isControlled","undefined","isChecked","hasIcons","Boolean","trackOffColor","trackOnColor","borderOffColor","borderOnColor","thumbDisabledColor","thumbOnToken","thumbOffToken","thumbOffColor","thumbOnColor","offX","onX","thumbTop","targetRef","animateTo","next","current","handleCheckedChange","nextChecked","trackMotionStyle","backgroundColor","borderColor","thumbMotionStyle","transform","translateX","thumbColorStyle","baseRootStyle","minWidth","minHeight","borderRadius","borderWidth","padding","overflow","trackStyle","thumbStyle","position","top","left","hitSlop","state","pointerEvents","collapsable"],"sourceRoot":"../../../src","sources":["components/Switch.tsx"],"mappings":";;AAAA,SACEA,YAAY,EACZC,cAAc,EACdC,IAAI,EACJC,eAAe,EACfC,OAAO,EACPC,MAAM,EACNC,QAAQ,QAGH,OAAO;AACd,SAASC,UAAU,QAAwB,cAAc;AACzD,SAASC,UAAU,QAAQ,YAAY;AACvC,OAAO,KAAKC,eAAe,MAAM,uBAAuB;AACxD,OAAOC,QAAQ,IACbC,MAAM,EACNC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,QAEL,yBAAyB;AAChC,SAASC,GAAG,QAA2B,0BAA0B;AACjE,SAASC,EAAE,QAAQ,aAAa;AAChC,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,aAAa,EAAEC,SAAS,QAAQ,uBAAuB;;AAEhE;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AACA,MAAMC,gBAAgB,GAAGnB,UAAU,CAACC,eAAe,CAACmB,IAAI,EAAE;EACxDC,SAAS,EAAE;AACb,CAAC,CAAC;AAUF,MAAMC,YAAY,GAAG,CAAC;AACtB;AACA,MAAMC,WAAW,GAAG,CAAC;AACrB,MAAMC,MAAiB,GAAG;EAAEC,UAAU,EAAE,QAAQ;EAAEC,cAAc,EAAE;AAAS,CAAC;AAE5E,MAAMC,WAAuC,GAAG;EAC9CC,EAAE,EAAE,CAAC;EACLC,EAAE,EAAE,EAAE;EACNC,EAAE,EAAE;AACN,CAAC;AAED,MAAMC,UAAsC,GAAG;EAC7CH,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,CAClD;IAAAF,QAAA,gBAEFtD,IAAA,CAACZ,QAAQ,CAACmE,IAAI;MACZsD,aAAa,EAAC,MAAM;MACpBrD,KAAK,EAAE,CAAC8C,UAAU,EAAEd,gBAAgB;IAAE,CACvC,CAAC,eACFxF,IAAA,CAACZ,QAAQ,CAACmE,IAAI;MACZsD,aAAa,EAAC,MAAM;MACpBC,WAAW,EAAE,KAAM;MACnBtD,KAAK,EAAE,CAAC+C,UAAU,EAAEZ,gBAAgB,EAAEG,eAAe,CAAE;MAAAxC,QAAA,EAEtDc,QAAQ,gBACPpE,IAAA,CAAC2C,gBAAgB;QACfC,QAAQ,EAAEA,QAAS;QACnBC,WAAW,EAAEA,WAAY;QACzBC,aAAa,EAAEA,aAAc;QAC7BC,gBAAgB,EAAEA,gBAAiB;QACnCC,kBAAkB,EAAEA,kBAAmB;QACvCC,QAAQ,EAAEA;MAAS,CACpB,CAAC,GACA;IAAI,CACK,CAAC;EAAA,CACA,CAAC;AAEvB,CAAC,CAAC;AAEF,SAASS,MAAM,EAAEzB,cAAc","ignoreList":[]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import * as SwitchPrimitive from "@rn-primitives/switch";
|
|
3
3
|
import { type VariantProps } from "class-variance-authority";
|
|
4
|
+
declare const switchVariants: (props?: ({
|
|
5
|
+
variant?: "regular" | null | undefined;
|
|
6
|
+
size?: "sm" | "md" | "lg" | null | undefined;
|
|
7
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
4
8
|
interface SwitchProps extends Omit<SwitchPrimitive.RootProps, "checked" | "onCheckedChange" | "children">, VariantProps<typeof switchVariants> {
|
|
5
9
|
checked?: boolean;
|
|
6
10
|
defaultChecked?: boolean;
|
|
@@ -8,11 +12,7 @@ interface SwitchProps extends Omit<SwitchPrimitive.RootProps, "checked" | "onChe
|
|
|
8
12
|
checkedIcon?: ReactNode;
|
|
9
13
|
uncheckedIcon?: ReactNode;
|
|
10
14
|
}
|
|
11
|
-
declare const
|
|
12
|
-
variant?: "regular" | null | undefined;
|
|
13
|
-
size?: "sm" | "md" | "lg" | null | undefined;
|
|
14
|
-
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
15
|
-
declare function Switch({ className, size, variant, checkedIcon, uncheckedIcon, checked, defaultChecked, onCheckedChange, disabled, style, ...props }: SwitchProps): import("react").JSX.Element;
|
|
15
|
+
declare const Switch: import("react").NamedExoticComponent<SwitchProps>;
|
|
16
16
|
export { Switch, switchVariants };
|
|
17
17
|
export type { SwitchProps };
|
|
18
18
|
//# sourceMappingURL=Switch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../../src/components/Switch.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../../src/components/Switch.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AASzD,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AA2ElE,QAAA,MAAM,cAAc;;;8EAelB,CAAC;AAEH,UAAU,WACR,SAAQ,IAAI,CACR,eAAe,CAAC,SAAS,EACzB,SAAS,GAAG,iBAAiB,GAAG,UAAU,CAC3C,EACD,YAAY,CAAC,OAAO,cAAc,CAAC;IACrC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAoDD,QAAA,MAAM,MAAM,mDAyLV,CAAC;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;AAClC,YAAY,EAAE,WAAW,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,57 +1,109 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
cloneElement,
|
|
3
|
+
isValidElement,
|
|
4
|
+
memo,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
type ReactElement,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
} from "react";
|
|
12
|
+
import { StyleSheet, type ViewStyle } from "react-native";
|
|
13
|
+
import { cssInterop } from "nativewind";
|
|
3
14
|
import * as SwitchPrimitive from "@rn-primitives/switch";
|
|
4
15
|
import Animated, {
|
|
5
|
-
|
|
16
|
+
Easing,
|
|
17
|
+
interpolateColor,
|
|
6
18
|
useAnimatedStyle,
|
|
19
|
+
useSharedValue,
|
|
7
20
|
withTiming,
|
|
8
|
-
|
|
21
|
+
type SharedValue,
|
|
9
22
|
} from "react-native-reanimated";
|
|
10
23
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
11
24
|
import { cn } from "@/lib/utils";
|
|
12
25
|
import { getMinTouchHitSlop } from "@/lib/touch-target";
|
|
13
|
-
import { useThemeColor } from "@/hooks/useThemeColor";
|
|
26
|
+
import { useThemeColor, withAlpha } from "@/hooks/useThemeColor";
|
|
14
27
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
>,
|
|
20
|
-
VariantProps<typeof switchVariants> {
|
|
21
|
-
checked?: boolean;
|
|
22
|
-
defaultChecked?: boolean;
|
|
23
|
-
onCheckedChange?: (checked: boolean) => void;
|
|
24
|
-
checkedIcon?: ReactNode;
|
|
25
|
-
uncheckedIcon?: ReactNode;
|
|
26
|
-
}
|
|
28
|
+
// `@rn-primitives/switch` renders a plain Pressable — cssInterop makes `className` work.
|
|
29
|
+
const StyledSwitchRoot = cssInterop(SwitchPrimitive.Root, {
|
|
30
|
+
className: "style",
|
|
31
|
+
});
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
type SwitchSize = "sm" | "md" | "lg";
|
|
34
|
+
|
|
35
|
+
type SwitchIconProps = {
|
|
36
|
+
color?: string;
|
|
37
|
+
width?: number;
|
|
38
|
+
height?: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const BORDER_WIDTH = 2;
|
|
42
|
+
/** Gap between thumb and inner edge of the track border (web `translate-x-0.5`). */
|
|
43
|
+
const THUMB_INSET = 2;
|
|
44
|
+
const CENTER: ViewStyle = { alignItems: "center", justifyContent: "center" };
|
|
45
|
+
|
|
46
|
+
const THUMB_SIZES: Record<SwitchSize, number> = {
|
|
29
47
|
sm: 8,
|
|
30
48
|
md: 12,
|
|
31
49
|
lg: 16,
|
|
32
50
|
};
|
|
33
51
|
|
|
34
|
-
const
|
|
35
|
-
sm:
|
|
36
|
-
md:
|
|
37
|
-
lg:
|
|
52
|
+
const ICON_SIZES: Record<SwitchSize, number> = {
|
|
53
|
+
sm: 8,
|
|
54
|
+
md: 12,
|
|
55
|
+
lg: 14,
|
|
38
56
|
};
|
|
39
57
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
58
|
+
/** Same scale as web `h-4 w-6` / `h-5 w-8` / `h-6 w-10` at 16px rem. */
|
|
59
|
+
const SWITCH_DIMENSIONS: Record<SwitchSize, { width: number; height: number }> =
|
|
60
|
+
{
|
|
61
|
+
sm: { width: 24, height: 16 },
|
|
62
|
+
md: { width: 32, height: 20 },
|
|
63
|
+
lg: { width: 40, height: 24 },
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Thumb is a sibling of the bordered track (not a child of it), so offsets are
|
|
68
|
+
* from the root's outer box. That avoids Yoga content-box quirks where absolute
|
|
69
|
+
* children of a bordered view shift the knob down / past the right edge.
|
|
70
|
+
*
|
|
71
|
+
* off = border + inset
|
|
72
|
+
* on = width - border - inset - thumb
|
|
73
|
+
* on+disabled keeps a 1px tighter right inset, matching web.
|
|
74
|
+
*/
|
|
75
|
+
function getThumbTranslateX(
|
|
76
|
+
trackWidth: number,
|
|
77
|
+
thumbSize: number,
|
|
78
|
+
checked: boolean,
|
|
79
|
+
disabled: boolean
|
|
80
|
+
): number {
|
|
81
|
+
const off = BORDER_WIDTH + THUMB_INSET;
|
|
82
|
+
if (!checked) return off;
|
|
83
|
+
const on = trackWidth - BORDER_WIDTH - THUMB_INSET - thumbSize;
|
|
84
|
+
return disabled ? on - 1 : on;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Even curve. A strong ease-out spends the last frames crawling, which reads
|
|
89
|
+
* as the thumb catching. Track and thumb colors ride the same curve.
|
|
90
|
+
*/
|
|
91
|
+
const THUMB_MOTION = {
|
|
92
|
+
duration: 250,
|
|
93
|
+
easing: Easing.inOut(Easing.cubic),
|
|
94
|
+
} as const;
|
|
45
95
|
|
|
46
|
-
|
|
96
|
+
// Px, not `h-6 w-10`: NativeWind resolves rem as 14px on native, which shrinks
|
|
97
|
+
// the track below SWITCH_DIMENSIONS and pushes the thumb down and out the right.
|
|
98
|
+
const switchVariants = cva("shrink-0", {
|
|
47
99
|
variants: {
|
|
48
100
|
variant: {
|
|
49
101
|
regular: "",
|
|
50
102
|
},
|
|
51
103
|
size: {
|
|
52
|
-
sm: "h-
|
|
53
|
-
md: "h-
|
|
54
|
-
lg: "h-
|
|
104
|
+
sm: "h-[16px] w-[24px]",
|
|
105
|
+
md: "h-[20px] w-[32px]",
|
|
106
|
+
lg: "h-[24px] w-[40px]",
|
|
55
107
|
},
|
|
56
108
|
},
|
|
57
109
|
defaultVariants: {
|
|
@@ -60,119 +112,255 @@ const switchVariants = cva("rounded-full border-2 items-center shrink-0", {
|
|
|
60
112
|
},
|
|
61
113
|
});
|
|
62
114
|
|
|
63
|
-
|
|
115
|
+
interface SwitchProps
|
|
116
|
+
extends Omit<
|
|
117
|
+
SwitchPrimitive.RootProps,
|
|
118
|
+
"checked" | "onCheckedChange" | "children"
|
|
119
|
+
>,
|
|
120
|
+
VariantProps<typeof switchVariants> {
|
|
121
|
+
checked?: boolean;
|
|
122
|
+
defaultChecked?: boolean;
|
|
123
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
124
|
+
checkedIcon?: ReactNode;
|
|
125
|
+
uncheckedIcon?: ReactNode;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function renderThumbIcon(icon: ReactNode, color: string, size: number) {
|
|
129
|
+
if (!isValidElement<SwitchIconProps>(icon)) return icon;
|
|
130
|
+
|
|
131
|
+
return cloneElement(icon as ReactElement<SwitchIconProps>, {
|
|
132
|
+
color: icon.props.color ?? color,
|
|
133
|
+
width: icon.props.width ?? size,
|
|
134
|
+
height: icon.props.height ?? size,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
type SwitchThumbIconsProps = {
|
|
139
|
+
progress: SharedValue<number>;
|
|
140
|
+
checkedIcon: ReactNode;
|
|
141
|
+
uncheckedIcon: ReactNode;
|
|
142
|
+
checkedIconColor: string;
|
|
143
|
+
uncheckedIconColor: string;
|
|
144
|
+
iconSize: number;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
function SwitchThumbIcons({
|
|
148
|
+
progress,
|
|
149
|
+
checkedIcon,
|
|
150
|
+
uncheckedIcon,
|
|
151
|
+
checkedIconColor,
|
|
152
|
+
uncheckedIconColor,
|
|
153
|
+
iconSize,
|
|
154
|
+
}: SwitchThumbIconsProps) {
|
|
155
|
+
const checkedIconStyle = useAnimatedStyle(() => ({
|
|
156
|
+
opacity: progress.value,
|
|
157
|
+
}));
|
|
158
|
+
const uncheckedIconStyle = useAnimatedStyle(() => ({
|
|
159
|
+
opacity: 1 - progress.value,
|
|
160
|
+
}));
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<>
|
|
164
|
+
<Animated.View
|
|
165
|
+
style={[StyleSheet.absoluteFill, CENTER, uncheckedIconStyle]}
|
|
166
|
+
>
|
|
167
|
+
{renderThumbIcon(uncheckedIcon, uncheckedIconColor, iconSize)}
|
|
168
|
+
</Animated.View>
|
|
169
|
+
<Animated.View
|
|
170
|
+
style={[StyleSheet.absoluteFill, CENTER, checkedIconStyle]}
|
|
171
|
+
>
|
|
172
|
+
{renderThumbIcon(checkedIcon, checkedIconColor, iconSize)}
|
|
173
|
+
</Animated.View>
|
|
174
|
+
</>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const Switch = memo(function Switch({
|
|
64
179
|
className,
|
|
65
180
|
size = "md",
|
|
66
|
-
variant,
|
|
181
|
+
variant = "regular",
|
|
67
182
|
checkedIcon,
|
|
68
183
|
uncheckedIcon,
|
|
69
184
|
checked,
|
|
70
185
|
defaultChecked,
|
|
71
186
|
onCheckedChange,
|
|
72
|
-
disabled,
|
|
187
|
+
disabled = false,
|
|
73
188
|
style,
|
|
74
189
|
...props
|
|
75
190
|
}: SwitchProps) {
|
|
76
191
|
const resolvedSize = size ?? "md";
|
|
77
192
|
const dimensions = SWITCH_DIMENSIONS[resolvedSize];
|
|
78
|
-
const
|
|
193
|
+
const thumbSize = THUMB_SIZES[resolvedSize];
|
|
194
|
+
const iconSize = ICON_SIZES[resolvedSize];
|
|
195
|
+
const [internalChecked, setInternalChecked] = useState(
|
|
196
|
+
defaultChecked ?? false
|
|
197
|
+
);
|
|
79
198
|
const isControlled = checked !== undefined;
|
|
80
|
-
const isChecked = isControlled ?
|
|
81
|
-
|
|
82
|
-
const trackOn = useThemeColor("primary-background-fill");
|
|
83
|
-
const trackOff = useThemeColor("surface-card");
|
|
84
|
-
const trackDisabled = useThemeColor("gray-background-soft-muted");
|
|
85
|
-
const trackBorder = useThemeColor("gray-stroke-muted");
|
|
86
|
-
const thumbOn = useThemeColor("primary-foreground-onfill");
|
|
87
|
-
const thumbOff = useThemeColor("gray-foreground-muted");
|
|
88
|
-
const thumbDisabled = useThemeColor("gray-background-fill-muted");
|
|
89
|
-
|
|
90
|
-
const translateX = useSharedValue(isChecked ? THUMB_TRANSLATE[resolvedSize] : 2);
|
|
91
|
-
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
translateX.value = withTiming(isChecked ? THUMB_TRANSLATE[resolvedSize] : 2, {
|
|
94
|
-
duration: 180,
|
|
95
|
-
easing: Easing.out(Easing.ease),
|
|
96
|
-
});
|
|
97
|
-
}, [isChecked, resolvedSize, translateX]);
|
|
98
|
-
|
|
99
|
-
const thumbStyle = useAnimatedStyle(() => ({
|
|
100
|
-
transform: [{ translateX: translateX.value }],
|
|
101
|
-
}));
|
|
102
|
-
|
|
199
|
+
const isChecked = isControlled ? checked : internalChecked;
|
|
103
200
|
const hasIcons = Boolean(checkedIcon || uncheckedIcon);
|
|
104
|
-
|
|
201
|
+
|
|
202
|
+
const checkedIconColor = useThemeColor(
|
|
203
|
+
disabled ? "gray-300" : "primary-foreground-onfill"
|
|
204
|
+
);
|
|
205
|
+
const uncheckedIconColor = useThemeColor(
|
|
206
|
+
disabled ? "gray-300" : "gray-foreground"
|
|
207
|
+
);
|
|
208
|
+
const trackOffColor = useThemeColor(
|
|
209
|
+
disabled ? "gray-background-soft-muted" : "surface-card"
|
|
210
|
+
);
|
|
211
|
+
const trackOnColor = useThemeColor(
|
|
212
|
+
disabled ? "gray-background-soft-muted" : "primary-background-fill"
|
|
213
|
+
);
|
|
214
|
+
const borderOffColor = useThemeColor("gray-stroke-muted");
|
|
215
|
+
const borderOnColor = disabled ? borderOffColor : withAlpha(borderOffColor, 0);
|
|
216
|
+
const thumbDisabledColor = useThemeColor("gray-background-fill-muted");
|
|
217
|
+
const thumbOnToken = useThemeColor("primary-foreground-onfill");
|
|
218
|
+
const thumbOffToken = useThemeColor("gray-foreground-muted");
|
|
219
|
+
const thumbOffColor = hasIcons
|
|
220
|
+
? "rgba(0, 0, 0, 0)"
|
|
221
|
+
: disabled
|
|
222
|
+
? thumbDisabledColor
|
|
223
|
+
: thumbOffToken;
|
|
224
|
+
const thumbOnColor = hasIcons
|
|
225
|
+
? "rgba(0, 0, 0, 0)"
|
|
226
|
+
: disabled
|
|
227
|
+
? thumbDisabledColor
|
|
228
|
+
: thumbOnToken;
|
|
229
|
+
|
|
230
|
+
const offX = getThumbTranslateX(dimensions.width, thumbSize, false, disabled);
|
|
231
|
+
const onX = getThumbTranslateX(dimensions.width, thumbSize, true, disabled);
|
|
232
|
+
// Root has no border — center against the outer height.
|
|
233
|
+
const thumbTop = (dimensions.height - thumbSize) / 2;
|
|
234
|
+
|
|
235
|
+
// Single UI-thread driver for position, colors and icons. In controlled mode
|
|
236
|
+
// the visual only moves when `checked` changes (same as the web Radix switch).
|
|
237
|
+
const progress = useSharedValue(isChecked ? 1 : 0);
|
|
238
|
+
const targetRef = useRef(isChecked);
|
|
239
|
+
|
|
240
|
+
const animateTo = (next: boolean) => {
|
|
241
|
+
if (targetRef.current === next) return;
|
|
242
|
+
targetRef.current = next;
|
|
243
|
+
progress.value = withTiming(next ? 1 : 0, THUMB_MOTION);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
useLayoutEffect(() => {
|
|
247
|
+
animateTo(isChecked);
|
|
248
|
+
}, [isChecked]);
|
|
105
249
|
|
|
106
250
|
const handleCheckedChange = (nextChecked: boolean) => {
|
|
107
|
-
if (!isControlled)
|
|
251
|
+
if (!isControlled) {
|
|
252
|
+
animateTo(nextChecked);
|
|
253
|
+
setInternalChecked(nextChecked);
|
|
254
|
+
}
|
|
108
255
|
onCheckedChange?.(nextChecked);
|
|
109
256
|
};
|
|
110
257
|
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
258
|
+
const trackMotionStyle = useAnimatedStyle(() => ({
|
|
259
|
+
backgroundColor: interpolateColor(
|
|
260
|
+
progress.value,
|
|
261
|
+
[0, 1],
|
|
262
|
+
[trackOffColor, trackOnColor]
|
|
263
|
+
),
|
|
264
|
+
borderColor: interpolateColor(
|
|
265
|
+
progress.value,
|
|
266
|
+
[0, 1],
|
|
267
|
+
[borderOffColor, borderOnColor]
|
|
268
|
+
),
|
|
269
|
+
}));
|
|
270
|
+
|
|
271
|
+
const thumbMotionStyle = useAnimatedStyle(() => ({
|
|
272
|
+
transform: [{ translateX: offX + (onX - offX) * progress.value }],
|
|
273
|
+
}), [offX, onX]);
|
|
274
|
+
|
|
275
|
+
const thumbColorStyle = useAnimatedStyle(() => ({
|
|
276
|
+
backgroundColor: interpolateColor(
|
|
277
|
+
progress.value,
|
|
278
|
+
[0, 1],
|
|
279
|
+
[thumbOffColor, thumbOnColor]
|
|
280
|
+
),
|
|
281
|
+
}));
|
|
282
|
+
|
|
283
|
+
const baseRootStyle = useMemo<ViewStyle>(
|
|
284
|
+
() => ({
|
|
285
|
+
width: dimensions.width,
|
|
286
|
+
height: dimensions.height,
|
|
287
|
+
minWidth: dimensions.width,
|
|
288
|
+
minHeight: dimensions.height,
|
|
289
|
+
borderRadius: dimensions.height / 2,
|
|
290
|
+
borderWidth: 0,
|
|
291
|
+
padding: 0,
|
|
292
|
+
overflow: "visible",
|
|
293
|
+
}),
|
|
294
|
+
[dimensions.height, dimensions.width]
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
const trackStyle = useMemo<ViewStyle>(
|
|
298
|
+
() => ({
|
|
299
|
+
...StyleSheet.absoluteFill,
|
|
300
|
+
borderRadius: dimensions.height / 2,
|
|
301
|
+
borderWidth: BORDER_WIDTH,
|
|
302
|
+
}),
|
|
303
|
+
[dimensions.height]
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
const thumbStyle = useMemo<ViewStyle>(
|
|
307
|
+
() => ({
|
|
308
|
+
position: "absolute",
|
|
309
|
+
top: thumbTop,
|
|
310
|
+
left: 0,
|
|
311
|
+
width: thumbSize,
|
|
312
|
+
height: thumbSize,
|
|
313
|
+
borderRadius: thumbSize / 2,
|
|
314
|
+
alignItems: "center",
|
|
315
|
+
justifyContent: "center",
|
|
316
|
+
}),
|
|
317
|
+
[thumbSize, thumbTop]
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
const hitSlop = useMemo(
|
|
321
|
+
() => getMinTouchHitSlop(dimensions.width, dimensions.height),
|
|
322
|
+
[dimensions.height, dimensions.width]
|
|
323
|
+
);
|
|
139
324
|
|
|
140
325
|
return (
|
|
141
|
-
<
|
|
326
|
+
<StyledSwitchRoot
|
|
327
|
+
hitSlop={hitSlop}
|
|
328
|
+
{...props}
|
|
142
329
|
checked={isChecked}
|
|
143
330
|
onCheckedChange={handleCheckedChange}
|
|
144
331
|
disabled={disabled}
|
|
145
|
-
|
|
332
|
+
className={cn(
|
|
333
|
+
switchVariants({ size: resolvedSize, variant }),
|
|
334
|
+
className
|
|
335
|
+
)}
|
|
146
336
|
style={(state) => [
|
|
147
|
-
|
|
337
|
+
baseRootStyle,
|
|
148
338
|
typeof style === "function" ? style(state) : style,
|
|
149
339
|
]}
|
|
150
|
-
className={cn(switchVariants({ size, variant }), className)}
|
|
151
|
-
{...props}
|
|
152
340
|
>
|
|
153
|
-
<
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
</
|
|
173
|
-
</
|
|
341
|
+
<Animated.View
|
|
342
|
+
pointerEvents="none"
|
|
343
|
+
style={[trackStyle, trackMotionStyle]}
|
|
344
|
+
/>
|
|
345
|
+
<Animated.View
|
|
346
|
+
pointerEvents="none"
|
|
347
|
+
collapsable={false}
|
|
348
|
+
style={[thumbStyle, thumbMotionStyle, thumbColorStyle]}
|
|
349
|
+
>
|
|
350
|
+
{hasIcons ? (
|
|
351
|
+
<SwitchThumbIcons
|
|
352
|
+
progress={progress}
|
|
353
|
+
checkedIcon={checkedIcon}
|
|
354
|
+
uncheckedIcon={uncheckedIcon}
|
|
355
|
+
checkedIconColor={checkedIconColor}
|
|
356
|
+
uncheckedIconColor={uncheckedIconColor}
|
|
357
|
+
iconSize={iconSize}
|
|
358
|
+
/>
|
|
359
|
+
) : null}
|
|
360
|
+
</Animated.View>
|
|
361
|
+
</StyledSwitchRoot>
|
|
174
362
|
);
|
|
175
|
-
}
|
|
363
|
+
});
|
|
176
364
|
|
|
177
365
|
export { Switch, switchVariants };
|
|
178
366
|
export type { SwitchProps };
|