react-native-directional-toggle 0.1.1 → 0.1.3
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/README.en.md +236 -38
- package/README.md +236 -37
- package/lib/commonjs/AnimatedSwitch.js +211 -0
- package/lib/commonjs/AnimatedSwitch.js.map +1 -0
- package/lib/commonjs/index.js +15 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/AnimatedSwitch.js +150 -134
- package/lib/module/AnimatedSwitch.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/AnimatedSwitch.d.ts +48 -0
- package/lib/typescript/commonjs/src/AnimatedSwitch.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/AnimatedSwitch.d.ts +48 -0
- package/lib/typescript/module/src/AnimatedSwitch.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +43 -19
- package/src/AnimatedSwitch.tsx +243 -169
- package/src/index.tsx +2 -1
- package/lib/typescript/src/AnimatedSwitch.d.ts +0 -25
- package/lib/typescript/src/AnimatedSwitch.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -3
- package/lib/typescript/src/index.d.ts.map +0 -1
- /package/lib/typescript/{package.json → module/package.json} +0 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AnimatedSwitch = AnimatedSwitch;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _reactNativeGestureHandler = require("react-native-gesture-handler");
|
|
10
|
+
var _reactNativeWorklets = require("react-native-worklets");
|
|
11
|
+
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
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); }
|
|
14
|
+
const DEFAULT_ANIMATION = {
|
|
15
|
+
duration: 150,
|
|
16
|
+
damping: 5,
|
|
17
|
+
stiffness: 100
|
|
18
|
+
};
|
|
19
|
+
function AnimatedSwitch({
|
|
20
|
+
options,
|
|
21
|
+
value,
|
|
22
|
+
onChange,
|
|
23
|
+
vertical = false,
|
|
24
|
+
style,
|
|
25
|
+
thumbStyle,
|
|
26
|
+
textStyle,
|
|
27
|
+
activeTextStyle,
|
|
28
|
+
inactiveTextStyle,
|
|
29
|
+
animationConfig = DEFAULT_ANIMATION,
|
|
30
|
+
disabled = false
|
|
31
|
+
}) {
|
|
32
|
+
console.log('disabled ---->', disabled);
|
|
33
|
+
const itemSizeSV = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
34
|
+
const translate = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
35
|
+
const indexSV = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
36
|
+
const currentIndex = options.findIndex(o => o.value === value);
|
|
37
|
+
|
|
38
|
+
// Measure container layout
|
|
39
|
+
const onLayout = (0, _react.useCallback)(e => {
|
|
40
|
+
const {
|
|
41
|
+
width,
|
|
42
|
+
height
|
|
43
|
+
} = e.nativeEvent.layout;
|
|
44
|
+
const totalSize = vertical ? height - 4 : width - 4;
|
|
45
|
+
const itemSize = totalSize / options.length;
|
|
46
|
+
itemSizeSV.value = itemSize;
|
|
47
|
+
|
|
48
|
+
// Fix initial position on layout
|
|
49
|
+
if (currentIndex >= 0 && itemSize > 0) {
|
|
50
|
+
translate.value = currentIndex * itemSize;
|
|
51
|
+
}
|
|
52
|
+
}, [vertical, options.length, currentIndex, itemSizeSV, translate]);
|
|
53
|
+
|
|
54
|
+
// Sync with external value changes
|
|
55
|
+
(0, _react.useEffect)(() => {
|
|
56
|
+
if (currentIndex >= 0 && itemSizeSV.value > 0) {
|
|
57
|
+
indexSV.value = currentIndex;
|
|
58
|
+
translate.value = (0, _reactNativeReanimated.withTiming)(currentIndex * itemSizeSV.value, animationConfig);
|
|
59
|
+
}
|
|
60
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
|
+
}, [currentIndex, animationConfig]);
|
|
62
|
+
const emitChange = (0, _react.useCallback)(index => {
|
|
63
|
+
// Clamp index to safe bounds
|
|
64
|
+
const safeIndex = Math.max(0, Math.min(index, options.length - 1));
|
|
65
|
+
if (options[safeIndex]) {
|
|
66
|
+
onChange(options[safeIndex].value);
|
|
67
|
+
}
|
|
68
|
+
}, [onChange, options]);
|
|
69
|
+
const handlePress = index => {
|
|
70
|
+
if (disabled || itemSizeSV.value === 0) return;
|
|
71
|
+
translate.value = (0, _reactNativeReanimated.withTiming)(index * itemSizeSV.value, animationConfig);
|
|
72
|
+
emitChange(index);
|
|
73
|
+
};
|
|
74
|
+
const panGesture = (0, _react.useMemo)(() => _reactNativeGestureHandler.Gesture.Pan().enabled(!disabled).onUpdate(e => {
|
|
75
|
+
if (itemSizeSV.value === 0) return;
|
|
76
|
+
const term = vertical ? e.translationY : e.translationX;
|
|
77
|
+
const startPos = indexSV.value * itemSizeSV.value;
|
|
78
|
+
const pos = startPos + term;
|
|
79
|
+
const max = (options.length - 1) * itemSizeSV.value;
|
|
80
|
+
translate.value = Math.min(Math.max(0, pos), max);
|
|
81
|
+
}).onEnd(() => {
|
|
82
|
+
if (itemSizeSV.value === 0) return;
|
|
83
|
+
const index = Math.round(translate.value / itemSizeSV.value);
|
|
84
|
+
indexSV.value = index;
|
|
85
|
+
translate.value = (0, _reactNativeReanimated.withSpring)(index * itemSizeSV.value, animationConfig);
|
|
86
|
+
(0, _reactNativeWorklets.scheduleOnRN)(emitChange, index);
|
|
87
|
+
}),
|
|
88
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
89
|
+
[disabled]);
|
|
90
|
+
const animatedThumbStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
91
|
+
// If layout not ready, hide thumb or show nothing
|
|
92
|
+
if (itemSizeSV.value === 0) return {
|
|
93
|
+
opacity: 0
|
|
94
|
+
};
|
|
95
|
+
const transform = vertical ? [{
|
|
96
|
+
translateY: translate.value
|
|
97
|
+
}] : [{
|
|
98
|
+
translateX: translate.value
|
|
99
|
+
}];
|
|
100
|
+
const sizeStyle = vertical ? {
|
|
101
|
+
height: itemSizeSV.value,
|
|
102
|
+
width: '100%'
|
|
103
|
+
} : {
|
|
104
|
+
width: itemSizeSV.value,
|
|
105
|
+
height: '100%'
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
position: 'absolute',
|
|
109
|
+
left: 2,
|
|
110
|
+
top: 2,
|
|
111
|
+
...sizeStyle,
|
|
112
|
+
transform,
|
|
113
|
+
opacity: 1
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
const content = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
117
|
+
onLayout: onLayout,
|
|
118
|
+
style: [styles.container, vertical ? styles.vertical : styles.horizontal, disabled && styles.disabled, style],
|
|
119
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
120
|
+
style: [styles.thumb, thumbStyle, animatedThumbStyle]
|
|
121
|
+
}), options.map((opt, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(OptionItem, {
|
|
122
|
+
label: opt.label,
|
|
123
|
+
onPress: () => handlePress(index),
|
|
124
|
+
index: index,
|
|
125
|
+
translate: translate,
|
|
126
|
+
itemSizeSV: itemSizeSV,
|
|
127
|
+
textStyle: textStyle,
|
|
128
|
+
activeTextStyle: activeTextStyle,
|
|
129
|
+
inactiveTextStyle: inactiveTextStyle,
|
|
130
|
+
disabled: disabled
|
|
131
|
+
}, String(opt.value)))]
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// disabled 时不挂载 GestureDetector
|
|
135
|
+
return disabled ? content : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector, {
|
|
136
|
+
gesture: panGesture,
|
|
137
|
+
children: content
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Sub-component for individual options to isolate animated styles
|
|
142
|
+
const OptionItem = ({
|
|
143
|
+
label,
|
|
144
|
+
onPress,
|
|
145
|
+
index,
|
|
146
|
+
translate,
|
|
147
|
+
itemSizeSV,
|
|
148
|
+
textStyle,
|
|
149
|
+
activeTextStyle,
|
|
150
|
+
inactiveTextStyle,
|
|
151
|
+
disabled
|
|
152
|
+
}) => {
|
|
153
|
+
const activeColor = _reactNative.StyleSheet.flatten(activeTextStyle)?.color ?? '#000';
|
|
154
|
+
const inactiveColor = _reactNative.StyleSheet.flatten(inactiveTextStyle)?.color ?? '#999';
|
|
155
|
+
const textAnimatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
156
|
+
const center = index * itemSizeSV.value;
|
|
157
|
+
const color = (0, _reactNativeReanimated.interpolateColor)(translate.value, [center - itemSizeSV.value, center, center + itemSizeSV.value], [inactiveColor, activeColor, inactiveColor]);
|
|
158
|
+
return {
|
|
159
|
+
color
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
|
|
163
|
+
style: styles.option,
|
|
164
|
+
onPress: onPress,
|
|
165
|
+
disabled: disabled,
|
|
166
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.Text, {
|
|
167
|
+
style: [styles.text, textStyle, textAnimatedStyle],
|
|
168
|
+
numberOfLines: 1,
|
|
169
|
+
children: label
|
|
170
|
+
})
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
const styles = _reactNative.StyleSheet.create({
|
|
174
|
+
container: {
|
|
175
|
+
borderRadius: 16,
|
|
176
|
+
overflow: 'hidden',
|
|
177
|
+
padding: 2,
|
|
178
|
+
position: 'relative'
|
|
179
|
+
},
|
|
180
|
+
disabled: {
|
|
181
|
+
opacity: 0.5
|
|
182
|
+
},
|
|
183
|
+
horizontal: {
|
|
184
|
+
flexDirection: 'row'
|
|
185
|
+
},
|
|
186
|
+
vertical: {
|
|
187
|
+
flexDirection: 'column'
|
|
188
|
+
},
|
|
189
|
+
thumb: {
|
|
190
|
+
borderRadius: 16,
|
|
191
|
+
shadowColor: '#000',
|
|
192
|
+
shadowOffset: {
|
|
193
|
+
width: 0,
|
|
194
|
+
height: 1
|
|
195
|
+
},
|
|
196
|
+
shadowOpacity: 0.1,
|
|
197
|
+
shadowRadius: 1,
|
|
198
|
+
elevation: 1
|
|
199
|
+
},
|
|
200
|
+
option: {
|
|
201
|
+
flex: 1,
|
|
202
|
+
alignItems: 'center',
|
|
203
|
+
justifyContent: 'center'
|
|
204
|
+
// zIndex: 1
|
|
205
|
+
},
|
|
206
|
+
text: {
|
|
207
|
+
fontSize: 14,
|
|
208
|
+
fontWeight: '500'
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
//# sourceMappingURL=AnimatedSwitch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_reactNativeGestureHandler","_reactNativeWorklets","_reactNativeReanimated","_interopRequireWildcard","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","DEFAULT_ANIMATION","duration","damping","stiffness","AnimatedSwitch","options","value","onChange","vertical","style","thumbStyle","textStyle","activeTextStyle","inactiveTextStyle","animationConfig","disabled","console","log","itemSizeSV","useSharedValue","translate","indexSV","currentIndex","findIndex","onLayout","useCallback","width","height","nativeEvent","layout","totalSize","itemSize","length","useEffect","withTiming","emitChange","index","safeIndex","Math","max","min","handlePress","panGesture","useMemo","Gesture","Pan","enabled","onUpdate","term","translationY","translationX","startPos","pos","onEnd","round","withSpring","scheduleOnRN","animatedThumbStyle","useAnimatedStyle","opacity","transform","translateY","translateX","sizeStyle","position","left","top","content","jsxs","View","styles","container","horizontal","children","jsx","thumb","map","opt","OptionItem","label","onPress","String","GestureDetector","gesture","activeColor","StyleSheet","flatten","color","inactiveColor","textAnimatedStyle","center","interpolateColor","Pressable","option","Text","text","numberOfLines","create","borderRadius","overflow","padding","flexDirection","shadowColor","shadowOffset","shadowOpacity","shadowRadius","elevation","flex","alignItems","justifyContent","fontSize","fontWeight"],"sourceRoot":"../../src","sources":["AnimatedSwitch.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AASA,IAAAE,0BAAA,GAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAC,uBAAA,CAAAL,OAAA;AASiC,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAK,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC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AM;IACnBC,YAAY,EAAE;MAAE7E,KAAK,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAE,CAAC;IACrC6E,aAAa,EAAE,GAAG;IAClBC,YAAY,EAAE,CAAC;IACfC,SAAS,EAAE;EACb,CAAC;EACDb,MAAM,EAAE;IACNc,IAAI,EAAE,CAAC;IACPC,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE;IAChB;EACF,CAAC;EACDd,IAAI,EAAE;IACJe,QAAQ,EAAE,EAAE;IACZC,UAAU,EAAE;EACd;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "AnimatedSwitch", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _AnimatedSwitch.AnimatedSwitch;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.default = void 0;
|
|
13
|
+
var _AnimatedSwitch = require("./AnimatedSwitch");
|
|
14
|
+
var _default = exports.default = _AnimatedSwitch.AnimatedSwitch;
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_AnimatedSwitch","require","_default","exports","default","AnimatedSwitch"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAA4E,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAE7DC,8BAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,190 +1,206 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { useCallback, useEffect } from
|
|
4
|
-
import { Pressable, StyleSheet, View } from
|
|
5
|
-
import { Gesture, GestureDetector } from
|
|
6
|
-
import
|
|
3
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
4
|
+
import { Pressable, StyleSheet, View } from 'react-native';
|
|
5
|
+
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
6
|
+
import { scheduleOnRN } from 'react-native-worklets';
|
|
7
|
+
import Animated, { interpolateColor, useAnimatedStyle, useSharedValue, withSpring, withTiming } from 'react-native-reanimated';
|
|
7
8
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
-
const
|
|
9
|
-
|
|
9
|
+
const DEFAULT_ANIMATION = {
|
|
10
|
+
duration: 150,
|
|
11
|
+
damping: 5,
|
|
12
|
+
stiffness: 100
|
|
13
|
+
};
|
|
10
14
|
export function AnimatedSwitch({
|
|
11
15
|
options,
|
|
12
16
|
value,
|
|
13
17
|
onChange,
|
|
14
|
-
height = 36,
|
|
15
18
|
vertical = false,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
duration: 100,
|
|
24
|
-
damping: 50,
|
|
25
|
-
stiffness: 200
|
|
26
|
-
}
|
|
19
|
+
style,
|
|
20
|
+
thumbStyle,
|
|
21
|
+
textStyle,
|
|
22
|
+
activeTextStyle,
|
|
23
|
+
inactiveTextStyle,
|
|
24
|
+
animationConfig = DEFAULT_ANIMATION,
|
|
25
|
+
disabled = false
|
|
27
26
|
}) {
|
|
28
|
-
|
|
27
|
+
console.log('disabled ---->', disabled);
|
|
29
28
|
const itemSizeSV = useSharedValue(0);
|
|
30
29
|
const translate = useSharedValue(0);
|
|
31
30
|
const indexSV = useSharedValue(0);
|
|
32
31
|
const currentIndex = options.findIndex(o => o.value === value);
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
// Measure container layout
|
|
34
|
+
const onLayout = useCallback(e => {
|
|
35
|
+
const {
|
|
36
|
+
width,
|
|
37
|
+
height
|
|
38
|
+
} = e.nativeEvent.layout;
|
|
39
|
+
const totalSize = vertical ? height - 4 : width - 4;
|
|
40
|
+
const itemSize = totalSize / options.length;
|
|
41
|
+
itemSizeSV.value = itemSize;
|
|
42
|
+
|
|
43
|
+
// Fix initial position on layout
|
|
44
|
+
if (currentIndex >= 0 && itemSize > 0) {
|
|
45
|
+
translate.value = currentIndex * itemSize;
|
|
46
|
+
}
|
|
47
|
+
}, [vertical, options.length, currentIndex, itemSizeSV, translate]);
|
|
48
|
+
|
|
49
|
+
// Sync with external value changes
|
|
37
50
|
useEffect(() => {
|
|
38
|
-
if (currentIndex >= 0) {
|
|
51
|
+
if (currentIndex >= 0 && itemSizeSV.value > 0) {
|
|
39
52
|
indexSV.value = currentIndex;
|
|
40
|
-
|
|
41
|
-
if (itemSizeSV.value > 0) {
|
|
42
|
-
translate.value = withTiming(currentIndex * itemSizeSV.value, {
|
|
43
|
-
duration: animationConfig.duration
|
|
44
|
-
});
|
|
45
|
-
}
|
|
53
|
+
translate.value = withTiming(currentIndex * itemSizeSV.value, animationConfig);
|
|
46
54
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/** ===== JS 回调 ===== */
|
|
55
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
56
|
+
}, [currentIndex, animationConfig]);
|
|
50
57
|
const emitChange = useCallback(index => {
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
// Clamp index to safe bounds
|
|
59
|
+
const safeIndex = Math.max(0, Math.min(index, options.length - 1));
|
|
60
|
+
if (options[safeIndex]) {
|
|
61
|
+
onChange(options[safeIndex].value);
|
|
53
62
|
}
|
|
54
63
|
}, [onChange, options]);
|
|
55
|
-
|
|
56
|
-
/** ===== Tap 点击切换 ===== */
|
|
57
64
|
const handlePress = index => {
|
|
58
|
-
|
|
59
|
-
translate.value = withTiming(index * itemSizeSV.value,
|
|
60
|
-
duration: animationConfig.duration ?? 150
|
|
61
|
-
});
|
|
65
|
+
if (disabled || itemSizeSV.value === 0) return;
|
|
66
|
+
translate.value = withTiming(index * itemSizeSV.value, animationConfig);
|
|
62
67
|
emitChange(index);
|
|
63
68
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
const pos = delta + indexSV.value * itemSizeSV.value;
|
|
69
|
+
const panGesture = useMemo(() => Gesture.Pan().enabled(!disabled).onUpdate(e => {
|
|
70
|
+
if (itemSizeSV.value === 0) return;
|
|
71
|
+
const term = vertical ? e.translationY : e.translationX;
|
|
72
|
+
const startPos = indexSV.value * itemSizeSV.value;
|
|
73
|
+
const pos = startPos + term;
|
|
70
74
|
const max = (options.length - 1) * itemSizeSV.value;
|
|
71
75
|
translate.value = Math.min(Math.max(0, pos), max);
|
|
72
76
|
}).onEnd(() => {
|
|
77
|
+
if (itemSizeSV.value === 0) return;
|
|
73
78
|
const index = Math.round(translate.value / itemSizeSV.value);
|
|
74
79
|
indexSV.value = index;
|
|
75
|
-
translate.value = withSpring(index * itemSizeSV.value,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
/** ===== Thumb 动画样式 ===== */
|
|
80
|
+
translate.value = withSpring(index * itemSizeSV.value, animationConfig);
|
|
81
|
+
scheduleOnRN(emitChange, index);
|
|
82
|
+
}),
|
|
83
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
84
|
+
[disabled]);
|
|
83
85
|
const animatedThumbStyle = useAnimatedStyle(() => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
// If layout not ready, hide thumb or show nothing
|
|
87
|
+
if (itemSizeSV.value === 0) return {
|
|
88
|
+
opacity: 0
|
|
89
|
+
};
|
|
90
|
+
const transform = vertical ? [{
|
|
91
|
+
translateY: translate.value
|
|
92
|
+
}] : [{
|
|
93
|
+
translateX: translate.value
|
|
94
|
+
}];
|
|
95
|
+
const sizeStyle = vertical ? {
|
|
96
|
+
height: itemSizeSV.value,
|
|
97
|
+
width: '100%'
|
|
98
|
+
} : {
|
|
99
|
+
width: itemSizeSV.value,
|
|
100
|
+
height: '100%'
|
|
101
|
+
};
|
|
95
102
|
return {
|
|
96
|
-
|
|
97
|
-
left:
|
|
98
|
-
top:
|
|
99
|
-
|
|
100
|
-
transform
|
|
101
|
-
|
|
102
|
-
}]
|
|
103
|
+
position: 'absolute',
|
|
104
|
+
left: 2,
|
|
105
|
+
top: 2,
|
|
106
|
+
...sizeStyle,
|
|
107
|
+
transform,
|
|
108
|
+
opacity: 1
|
|
103
109
|
};
|
|
104
110
|
});
|
|
111
|
+
const content = /*#__PURE__*/_jsxs(View, {
|
|
112
|
+
onLayout: onLayout,
|
|
113
|
+
style: [styles.container, vertical ? styles.vertical : styles.horizontal, disabled && styles.disabled, style],
|
|
114
|
+
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
115
|
+
style: [styles.thumb, thumbStyle, animatedThumbStyle]
|
|
116
|
+
}), options.map((opt, index) => /*#__PURE__*/_jsx(OptionItem, {
|
|
117
|
+
label: opt.label,
|
|
118
|
+
onPress: () => handlePress(index),
|
|
119
|
+
index: index,
|
|
120
|
+
translate: translate,
|
|
121
|
+
itemSizeSV: itemSizeSV,
|
|
122
|
+
textStyle: textStyle,
|
|
123
|
+
activeTextStyle: activeTextStyle,
|
|
124
|
+
inactiveTextStyle: inactiveTextStyle,
|
|
125
|
+
disabled: disabled
|
|
126
|
+
}, String(opt.value)))]
|
|
127
|
+
});
|
|
105
128
|
|
|
106
|
-
|
|
107
|
-
|
|
129
|
+
// disabled 时不挂载 GestureDetector
|
|
130
|
+
return disabled ? content : /*#__PURE__*/_jsx(GestureDetector, {
|
|
131
|
+
gesture: panGesture,
|
|
132
|
+
children: content
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Sub-component for individual options to isolate animated styles
|
|
137
|
+
const OptionItem = ({
|
|
138
|
+
label,
|
|
139
|
+
onPress,
|
|
140
|
+
index,
|
|
141
|
+
translate,
|
|
142
|
+
itemSizeSV,
|
|
143
|
+
textStyle,
|
|
144
|
+
activeTextStyle,
|
|
145
|
+
inactiveTextStyle,
|
|
146
|
+
disabled
|
|
147
|
+
}) => {
|
|
148
|
+
const activeColor = StyleSheet.flatten(activeTextStyle)?.color ?? '#000';
|
|
149
|
+
const inactiveColor = StyleSheet.flatten(inactiveTextStyle)?.color ?? '#999';
|
|
150
|
+
const textAnimatedStyle = useAnimatedStyle(() => {
|
|
108
151
|
const center = index * itemSizeSV.value;
|
|
109
|
-
const color = interpolateColor(translate.value, [center - itemSizeSV.value, center, center + itemSizeSV.value], [
|
|
152
|
+
const color = interpolateColor(translate.value, [center - itemSizeSV.value, center, center + itemSizeSV.value], [inactiveColor, activeColor, inactiveColor]);
|
|
110
153
|
return {
|
|
111
154
|
color
|
|
112
155
|
};
|
|
113
156
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// 核心修复:在获取到尺寸的第一时间,根据 currentIndex 强行同步 translate 的值
|
|
124
|
-
if (currentIndex >= 0) {
|
|
125
|
-
translate.value = currentIndex * newItemSize;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
return /*#__PURE__*/_jsx(GestureDetector, {
|
|
129
|
-
gesture: panGesture,
|
|
130
|
-
children: /*#__PURE__*/_jsxs(View, {
|
|
131
|
-
onLayout: onLayout,
|
|
132
|
-
style: [styles.container, {
|
|
133
|
-
backgroundColor: colors.bgBack
|
|
134
|
-
}, vertical ? {
|
|
135
|
-
height: height * options.length,
|
|
136
|
-
width: VERTICAL_WIDTH,
|
|
137
|
-
flexDirection: "column"
|
|
138
|
-
} : {
|
|
139
|
-
height,
|
|
140
|
-
flexDirection: "row"
|
|
141
|
-
}],
|
|
142
|
-
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
143
|
-
pointerEvents: "none",
|
|
144
|
-
style: [styles.thumbBase, {
|
|
145
|
-
backgroundColor: colors.bgFront
|
|
146
|
-
}, animatedThumbStyle]
|
|
147
|
-
}), options.map((opt, index) => {
|
|
148
|
-
const labelStyle = getLabelAnimatedStyle(index);
|
|
149
|
-
return /*#__PURE__*/_jsx(Pressable, {
|
|
150
|
-
style: styles.item,
|
|
151
|
-
onPress: () => handlePress(index),
|
|
152
|
-
children: /*#__PURE__*/_jsx(Animated.Text, {
|
|
153
|
-
style: [styles.label, labelStyle],
|
|
154
|
-
children: opt.label
|
|
155
|
-
})
|
|
156
|
-
}, opt.value);
|
|
157
|
-
})]
|
|
157
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
158
|
+
style: styles.option,
|
|
159
|
+
onPress: onPress,
|
|
160
|
+
disabled: disabled,
|
|
161
|
+
children: /*#__PURE__*/_jsx(Animated.Text, {
|
|
162
|
+
style: [styles.text, textStyle, textAnimatedStyle],
|
|
163
|
+
numberOfLines: 1,
|
|
164
|
+
children: label
|
|
158
165
|
})
|
|
159
166
|
});
|
|
160
|
-
}
|
|
167
|
+
};
|
|
161
168
|
const styles = StyleSheet.create({
|
|
162
169
|
container: {
|
|
163
170
|
borderRadius: 16,
|
|
164
|
-
overflow:
|
|
165
|
-
|
|
171
|
+
overflow: 'hidden',
|
|
172
|
+
padding: 2,
|
|
173
|
+
position: 'relative'
|
|
174
|
+
},
|
|
175
|
+
disabled: {
|
|
176
|
+
opacity: 0.5
|
|
166
177
|
},
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
178
|
+
horizontal: {
|
|
179
|
+
flexDirection: 'row'
|
|
180
|
+
},
|
|
181
|
+
vertical: {
|
|
182
|
+
flexDirection: 'column'
|
|
183
|
+
},
|
|
184
|
+
thumb: {
|
|
185
|
+
borderRadius: 16,
|
|
170
186
|
shadowColor: '#000',
|
|
171
|
-
shadowOpacity: 0.3,
|
|
172
187
|
shadowOffset: {
|
|
173
188
|
width: 0,
|
|
174
189
|
height: 1
|
|
175
190
|
},
|
|
191
|
+
shadowOpacity: 0.1,
|
|
176
192
|
shadowRadius: 1,
|
|
177
|
-
elevation:
|
|
193
|
+
elevation: 1
|
|
178
194
|
},
|
|
179
|
-
|
|
195
|
+
option: {
|
|
180
196
|
flex: 1,
|
|
181
|
-
alignItems:
|
|
182
|
-
justifyContent:
|
|
183
|
-
zIndex: 1
|
|
197
|
+
alignItems: 'center',
|
|
198
|
+
justifyContent: 'center'
|
|
199
|
+
// zIndex: 1
|
|
184
200
|
},
|
|
185
|
-
|
|
186
|
-
fontSize:
|
|
187
|
-
fontWeight:
|
|
201
|
+
text: {
|
|
202
|
+
fontSize: 14,
|
|
203
|
+
fontWeight: '500'
|
|
188
204
|
}
|
|
189
205
|
});
|
|
190
206
|
//# sourceMappingURL=AnimatedSwitch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useEffect","Pressable","StyleSheet","View","Gesture","GestureDetector","
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useMemo","Pressable","StyleSheet","View","Gesture","GestureDetector","scheduleOnRN","Animated","interpolateColor","useAnimatedStyle","useSharedValue","withSpring","withTiming","jsx","_jsx","jsxs","_jsxs","DEFAULT_ANIMATION","duration","damping","stiffness","AnimatedSwitch","options","value","onChange","vertical","style","thumbStyle","textStyle","activeTextStyle","inactiveTextStyle","animationConfig","disabled","console","log","itemSizeSV","translate","indexSV","currentIndex","findIndex","o","onLayout","e","width","height","nativeEvent","layout","totalSize","itemSize","length","emitChange","index","safeIndex","Math","max","min","handlePress","panGesture","Pan","enabled","onUpdate","term","translationY","translationX","startPos","pos","onEnd","round","animatedThumbStyle","opacity","transform","translateY","translateX","sizeStyle","position","left","top","content","styles","container","horizontal","children","thumb","map","opt","OptionItem","label","onPress","String","gesture","activeColor","flatten","color","inactiveColor","textAnimatedStyle","center","option","Text","text","numberOfLines","create","borderRadius","overflow","padding","flexDirection","shadowColor","shadowOffset","shadowOpacity","shadowRadius","elevation","flex","alignItems","justifyContent","fontSize","fontWeight"],"sourceRoot":"../../src","sources":["AnimatedSwitch.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AACvD,SAEEC,SAAS,EACTC,UAAU,EACVC,IAAI,QAIC,cAAc;AACrB,SAASC,OAAO,EAAEC,eAAe,QAAQ,8BAA8B;AACvE,SAASC,YAAY,QAAQ,uBAAuB;AACpD,OAAOC,QAAQ,IACbC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,EACVC,UAAU,QAIL,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AA+CjC,MAAMC,iBAAiB,GAAG;EACxBC,QAAQ,EAAE,GAAG;EACbC,OAAO,EAAE,CAAC;EACVC,SAAS,EAAE;AACb,CAAC;AAED,OAAO,SAASC,cAAcA,CAAC;EAC7BC,OAAO;EACPC,KAAK;EACLC,QAAQ;EACRC,QAAQ,GAAG,KAAK;EAChBC,KAAK;EACLC,UAAU;EACVC,SAAS;EACTC,eAAe;EACfC,iBAAiB;EACjBC,eAAe,GAAGd,iBAAiB;EACnCe,QAAQ,GAAG;AACQ,CAAC,EAAE;EACtBC,OAAO,CAACC,GAAG,CAAC,gBAAgB,EAAEF,QAAQ,CAAC;EACvC,MAAMG,UAAU,GAAGzB,cAAc,CAAC,CAAC,CAAC;EACpC,MAAM0B,SAAS,GAAG1B,cAAc,CAAC,CAAC,CAAC;EACnC,MAAM2B,OAAO,GAAG3B,cAAc,CAAC,CAAC,CAAC;EAEjC,MAAM4B,YAAY,GAAGhB,OAAO,CAACiB,SAAS,CAAEC,CAAC,IAAKA,CAAC,CAACjB,KAAK,KAAKA,KAAK,CAAC;;EAEhE;EACA,MAAMkB,QAAQ,GAA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