react-native-directional-toggle 0.1.0 → 0.1.2
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 +237 -37
- package/README.md +237 -37
- package/lib/commonjs/AnimatedSwitch.js +204 -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 +135 -126
- 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 +43 -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 +43 -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 +200 -146
- 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,204 @@
|
|
|
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
|
+
}) {
|
|
31
|
+
const itemSizeSV = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
32
|
+
const translate = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
33
|
+
const indexSV = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
34
|
+
const currentIndex = options.findIndex(o => o.value === value);
|
|
35
|
+
|
|
36
|
+
// Measure container layout
|
|
37
|
+
const onLayout = (0, _react.useCallback)(e => {
|
|
38
|
+
const {
|
|
39
|
+
width,
|
|
40
|
+
height
|
|
41
|
+
} = e.nativeEvent.layout;
|
|
42
|
+
const totalSize = vertical ? height - 4 : width - 4;
|
|
43
|
+
const itemSize = totalSize / options.length;
|
|
44
|
+
itemSizeSV.value = itemSize;
|
|
45
|
+
|
|
46
|
+
// Fix initial position on layout
|
|
47
|
+
if (currentIndex >= 0 && itemSize > 0) {
|
|
48
|
+
translate.value = currentIndex * itemSize;
|
|
49
|
+
}
|
|
50
|
+
}, [vertical, options.length, currentIndex, itemSizeSV, translate]);
|
|
51
|
+
|
|
52
|
+
// Sync with external value changes
|
|
53
|
+
(0, _react.useEffect)(() => {
|
|
54
|
+
if (currentIndex >= 0 && itemSizeSV.value > 0) {
|
|
55
|
+
indexSV.value = currentIndex;
|
|
56
|
+
translate.value = (0, _reactNativeReanimated.withTiming)(currentIndex * itemSizeSV.value, animationConfig);
|
|
57
|
+
}
|
|
58
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
|
+
}, [currentIndex, animationConfig]);
|
|
60
|
+
const emitChange = (0, _react.useCallback)(index => {
|
|
61
|
+
// Clamp index to safe bounds
|
|
62
|
+
const safeIndex = Math.max(0, Math.min(index, options.length - 1));
|
|
63
|
+
if (options[safeIndex]) {
|
|
64
|
+
onChange(options[safeIndex].value);
|
|
65
|
+
}
|
|
66
|
+
}, [onChange, options]);
|
|
67
|
+
const handlePress = index => {
|
|
68
|
+
if (itemSizeSV.value === 0) return;
|
|
69
|
+
indexSV.value = index;
|
|
70
|
+
translate.value = (0, _reactNativeReanimated.withTiming)(index * itemSizeSV.value, animationConfig);
|
|
71
|
+
emitChange(index);
|
|
72
|
+
};
|
|
73
|
+
const panGesture = _reactNativeGestureHandler.Gesture.Pan().onUpdate(e => {
|
|
74
|
+
if (itemSizeSV.value === 0) return;
|
|
75
|
+
const term = vertical ? e.translationY : e.translationX;
|
|
76
|
+
const startPos = indexSV.value * itemSizeSV.value;
|
|
77
|
+
const pos = startPos + term;
|
|
78
|
+
const max = (options.length - 1) * itemSizeSV.value;
|
|
79
|
+
translate.value = Math.min(Math.max(0, pos), max);
|
|
80
|
+
}).onEnd(() => {
|
|
81
|
+
if (itemSizeSV.value === 0) return;
|
|
82
|
+
const index = Math.round(translate.value / itemSizeSV.value);
|
|
83
|
+
indexSV.value = index;
|
|
84
|
+
translate.value = (0, _reactNativeReanimated.withSpring)(index * itemSizeSV.value, animationConfig);
|
|
85
|
+
(0, _reactNativeWorklets.scheduleOnRN)(emitChange, index);
|
|
86
|
+
});
|
|
87
|
+
const animatedThumbStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
88
|
+
// If layout not ready, hide thumb or show nothing
|
|
89
|
+
if (itemSizeSV.value === 0) return {
|
|
90
|
+
opacity: 0
|
|
91
|
+
};
|
|
92
|
+
const transform = vertical ? [{
|
|
93
|
+
translateY: translate.value
|
|
94
|
+
}] : [{
|
|
95
|
+
translateX: translate.value
|
|
96
|
+
}];
|
|
97
|
+
const sizeStyle = vertical ? {
|
|
98
|
+
height: itemSizeSV.value,
|
|
99
|
+
width: '100%'
|
|
100
|
+
} : {
|
|
101
|
+
width: itemSizeSV.value,
|
|
102
|
+
height: '100%'
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
position: 'absolute',
|
|
106
|
+
left: 2,
|
|
107
|
+
top: 2,
|
|
108
|
+
...sizeStyle,
|
|
109
|
+
transform,
|
|
110
|
+
opacity: 1
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector, {
|
|
114
|
+
gesture: panGesture,
|
|
115
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
116
|
+
onLayout: onLayout,
|
|
117
|
+
style: [styles.container, vertical ? styles.vertical : styles.horizontal, style // User override
|
|
118
|
+
],
|
|
119
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
|
|
120
|
+
style: [styles.thumb, thumbStyle, animatedThumbStyle]
|
|
121
|
+
}), options.map((opt, index) => {
|
|
122
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(OptionItem, {
|
|
123
|
+
label: opt.label,
|
|
124
|
+
onPress: () => handlePress(index),
|
|
125
|
+
index: index,
|
|
126
|
+
translate: translate,
|
|
127
|
+
itemSizeSV: itemSizeSV,
|
|
128
|
+
textStyle: textStyle,
|
|
129
|
+
activeTextStyle: activeTextStyle,
|
|
130
|
+
inactiveTextStyle: inactiveTextStyle
|
|
131
|
+
}, opt.value);
|
|
132
|
+
})]
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Sub-component for individual options to isolate animated styles
|
|
138
|
+
const OptionItem = ({
|
|
139
|
+
label,
|
|
140
|
+
onPress,
|
|
141
|
+
index,
|
|
142
|
+
translate,
|
|
143
|
+
itemSizeSV,
|
|
144
|
+
textStyle,
|
|
145
|
+
activeTextStyle,
|
|
146
|
+
inactiveTextStyle
|
|
147
|
+
}) => {
|
|
148
|
+
const activeColor = _reactNative.StyleSheet.flatten(activeTextStyle)?.color ?? '#000';
|
|
149
|
+
const inactiveColor = _reactNative.StyleSheet.flatten(inactiveTextStyle)?.color ?? '#999';
|
|
150
|
+
const textAnimatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
151
|
+
const center = index * itemSizeSV.value;
|
|
152
|
+
const color = (0, _reactNativeReanimated.interpolateColor)(translate.value, [center - itemSizeSV.value, center, center + itemSizeSV.value], [inactiveColor, activeColor, inactiveColor]);
|
|
153
|
+
return {
|
|
154
|
+
color
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
|
|
158
|
+
style: styles.option,
|
|
159
|
+
onPress: onPress,
|
|
160
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.Text, {
|
|
161
|
+
style: [styles.text, textStyle, textAnimatedStyle],
|
|
162
|
+
numberOfLines: 1,
|
|
163
|
+
children: label
|
|
164
|
+
})
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const styles = _reactNative.StyleSheet.create({
|
|
168
|
+
container: {
|
|
169
|
+
// backgroundColor: '#f0f0f0',
|
|
170
|
+
borderRadius: 16,
|
|
171
|
+
overflow: 'hidden',
|
|
172
|
+
padding: 2
|
|
173
|
+
// position: 'relative',
|
|
174
|
+
},
|
|
175
|
+
horizontal: {
|
|
176
|
+
flexDirection: 'row'
|
|
177
|
+
},
|
|
178
|
+
vertical: {
|
|
179
|
+
flexDirection: 'column'
|
|
180
|
+
},
|
|
181
|
+
thumb: {
|
|
182
|
+
// backgroundColor: '#fff',
|
|
183
|
+
borderRadius: 16,
|
|
184
|
+
shadowColor: '#000',
|
|
185
|
+
shadowOffset: {
|
|
186
|
+
width: 0,
|
|
187
|
+
height: 1
|
|
188
|
+
},
|
|
189
|
+
shadowOpacity: 0.1,
|
|
190
|
+
shadowRadius: 1,
|
|
191
|
+
elevation: 1
|
|
192
|
+
},
|
|
193
|
+
option: {
|
|
194
|
+
flex: 1,
|
|
195
|
+
alignItems: 'center',
|
|
196
|
+
justifyContent: 'center'
|
|
197
|
+
// zIndex: 1
|
|
198
|
+
},
|
|
199
|
+
text: {
|
|
200
|
+
fontSize: 14,
|
|
201
|
+
fontWeight: '500'
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
//# 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","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","Gesture","Pan","onUpdate","term","translationY","translationX","startPos","pos","onEnd","round","withSpring","scheduleOnRN","animatedThumbStyle","useAnimatedStyle","opacity","transform","translateY","translateX","sizeStyle","position","left","top","jsx","GestureDetector","gesture","children","jsxs","View","styles","container","horizontal","thumb","map","opt","OptionItem","label","onPress","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,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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AAA,CAAAkF,GAAA,EAACpF,sBAAA,CAAAa,OAAQ,CAACgG,IAAI;MACZ9E,KAAK,EAAE,CAAC2D,MAAM,CAACoB,IAAI,EAAE7E,SAAS,EAAEuE,iBAAiB,CAAE;MACnDO,aAAa,EAAE,CAAE;MAAAxB,QAAA,EAEhBU;IAAK,CACO;EAAC,CACP,CAAC;AAEhB,CAAC;AAED,MAAMP,MAAM,GAAGU,uBAAU,CAACY,MAAM,CAAC;EAC/BrB,SAAS,EAAE;IACT;IACAsB,YAAY,EAAE,EAAE;IAChBC,QAAQ,EAAE,QAAQ;IAClBC,OAAO,EAAE;IACT;EACF,CAAC;EACDvB,UAAU,EAAE;IACVwB,aAAa,EAAE;EACjB,CAAC;EACDtF,QAAQ,EAAE;IACRsF,aAAa,EAAE;EACjB,CAAC;EACDvB,KAAK,EAAE;IACL;IACAoB,YAAY,EAAE,EAAE;IAChBI,WAAW,EAAE,MAAM;IACnBC,YAAY,EAAE;MAAEzE,KAAK,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAE,CAAC;IACrCyE,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,199 @@
|
|
|
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 } 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 = 40,
|
|
15
18
|
vertical = false,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
animationConfig = {
|
|
23
|
-
duration: 100,
|
|
24
|
-
damping: 50,
|
|
25
|
-
stiffness: 200
|
|
26
|
-
}
|
|
19
|
+
style,
|
|
20
|
+
thumbStyle,
|
|
21
|
+
textStyle,
|
|
22
|
+
activeTextStyle,
|
|
23
|
+
inactiveTextStyle,
|
|
24
|
+
animationConfig = DEFAULT_ANIMATION
|
|
27
25
|
}) {
|
|
28
|
-
/** ===== SharedValues ===== */
|
|
29
26
|
const itemSizeSV = useSharedValue(0);
|
|
30
27
|
const translate = useSharedValue(0);
|
|
31
28
|
const indexSV = useSharedValue(0);
|
|
32
29
|
const currentIndex = options.findIndex(o => o.value === value);
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
// Measure container layout
|
|
32
|
+
const onLayout = useCallback(e => {
|
|
33
|
+
const {
|
|
34
|
+
width,
|
|
35
|
+
height
|
|
36
|
+
} = e.nativeEvent.layout;
|
|
37
|
+
const totalSize = vertical ? height - 4 : width - 4;
|
|
38
|
+
const itemSize = totalSize / options.length;
|
|
39
|
+
itemSizeSV.value = itemSize;
|
|
40
|
+
|
|
41
|
+
// Fix initial position on layout
|
|
42
|
+
if (currentIndex >= 0 && itemSize > 0) {
|
|
43
|
+
translate.value = currentIndex * itemSize;
|
|
44
|
+
}
|
|
45
|
+
}, [vertical, options.length, currentIndex, itemSizeSV, translate]);
|
|
46
|
+
|
|
47
|
+
// Sync with external value changes
|
|
37
48
|
useEffect(() => {
|
|
38
|
-
if (currentIndex >= 0) {
|
|
49
|
+
if (currentIndex >= 0 && itemSizeSV.value > 0) {
|
|
39
50
|
indexSV.value = currentIndex;
|
|
40
|
-
|
|
41
|
-
if (itemSizeSV.value > 0) {
|
|
42
|
-
translate.value = withTiming(currentIndex * itemSizeSV.value, {
|
|
43
|
-
duration: animationConfig.duration
|
|
44
|
-
});
|
|
45
|
-
}
|
|
51
|
+
translate.value = withTiming(currentIndex * itemSizeSV.value, animationConfig);
|
|
46
52
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/** ===== JS 回调 ===== */
|
|
53
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
+
}, [currentIndex, animationConfig]);
|
|
50
55
|
const emitChange = useCallback(index => {
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
// Clamp index to safe bounds
|
|
57
|
+
const safeIndex = Math.max(0, Math.min(index, options.length - 1));
|
|
58
|
+
if (options[safeIndex]) {
|
|
59
|
+
onChange(options[safeIndex].value);
|
|
53
60
|
}
|
|
54
61
|
}, [onChange, options]);
|
|
55
|
-
|
|
56
|
-
/** ===== Tap 点击切换 ===== */
|
|
57
62
|
const handlePress = index => {
|
|
63
|
+
if (itemSizeSV.value === 0) return;
|
|
58
64
|
indexSV.value = index;
|
|
59
|
-
translate.value = withTiming(index * itemSizeSV.value,
|
|
60
|
-
duration: animationConfig.duration ?? 150
|
|
61
|
-
});
|
|
65
|
+
translate.value = withTiming(index * itemSizeSV.value, animationConfig);
|
|
62
66
|
emitChange(index);
|
|
63
67
|
};
|
|
64
|
-
|
|
65
|
-
/** ===== Drag 手势 ===== */
|
|
66
68
|
const panGesture = Gesture.Pan().onUpdate(e => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
69
|
+
if (itemSizeSV.value === 0) return;
|
|
70
|
+
const term = vertical ? e.translationY : e.translationX;
|
|
71
|
+
const startPos = indexSV.value * itemSizeSV.value;
|
|
72
|
+
const pos = startPos + term;
|
|
70
73
|
const max = (options.length - 1) * itemSizeSV.value;
|
|
71
74
|
translate.value = Math.min(Math.max(0, pos), max);
|
|
72
75
|
}).onEnd(() => {
|
|
76
|
+
if (itemSizeSV.value === 0) return;
|
|
73
77
|
const index = Math.round(translate.value / itemSizeSV.value);
|
|
74
78
|
indexSV.value = index;
|
|
75
|
-
translate.value = withSpring(index * itemSizeSV.value,
|
|
76
|
-
|
|
77
|
-
stiffness: animationConfig.stiffness ?? 200
|
|
78
|
-
});
|
|
79
|
-
runOnJS(emitChange)(index);
|
|
79
|
+
translate.value = withSpring(index * itemSizeSV.value, animationConfig);
|
|
80
|
+
scheduleOnRN(emitChange, index);
|
|
80
81
|
});
|
|
81
|
-
|
|
82
|
-
/** ===== Thumb 动画样式 ===== */
|
|
83
82
|
const animatedThumbStyle = useAnimatedStyle(() => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
bottom: THUMB_INSET,
|
|
100
|
-
transform: [{
|
|
101
|
-
translateX: translate.value
|
|
102
|
-
}]
|
|
83
|
+
// If layout not ready, hide thumb or show nothing
|
|
84
|
+
if (itemSizeSV.value === 0) return {
|
|
85
|
+
opacity: 0
|
|
86
|
+
};
|
|
87
|
+
const transform = vertical ? [{
|
|
88
|
+
translateY: translate.value
|
|
89
|
+
}] : [{
|
|
90
|
+
translateX: translate.value
|
|
91
|
+
}];
|
|
92
|
+
const sizeStyle = vertical ? {
|
|
93
|
+
height: itemSizeSV.value,
|
|
94
|
+
width: '100%'
|
|
95
|
+
} : {
|
|
96
|
+
width: itemSizeSV.value,
|
|
97
|
+
height: '100%'
|
|
103
98
|
};
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
/** ===== Label 动画样式 ===== */
|
|
107
|
-
const getLabelAnimatedStyle = index => useAnimatedStyle(() => {
|
|
108
|
-
const center = index * itemSizeSV.value;
|
|
109
|
-
const color = interpolateColor(translate.value, [center - itemSizeSV.value, center, center + itemSizeSV.value], [colors.inactiveText, colors.activeText, colors.inactiveText]);
|
|
110
99
|
return {
|
|
111
|
-
|
|
100
|
+
position: 'absolute',
|
|
101
|
+
left: 2,
|
|
102
|
+
top: 2,
|
|
103
|
+
...sizeStyle,
|
|
104
|
+
transform,
|
|
105
|
+
opacity: 1
|
|
112
106
|
};
|
|
113
107
|
});
|
|
114
|
-
|
|
115
|
-
/** * 2. Layout 初始化
|
|
116
|
-
* 这是修复初始显示问题的关键
|
|
117
|
-
*/
|
|
118
|
-
const onLayout = e => {
|
|
119
|
-
const size = vertical ? e.nativeEvent.layout.height : e.nativeEvent.layout.width;
|
|
120
|
-
const newItemSize = size / options.length;
|
|
121
|
-
itemSizeSV.value = newItemSize;
|
|
122
|
-
|
|
123
|
-
// 核心修复:在获取到尺寸的第一时间,根据 currentIndex 强行同步 translate 的值
|
|
124
|
-
if (currentIndex >= 0) {
|
|
125
|
-
translate.value = currentIndex * newItemSize;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
108
|
return /*#__PURE__*/_jsx(GestureDetector, {
|
|
129
109
|
gesture: panGesture,
|
|
130
110
|
children: /*#__PURE__*/_jsxs(View, {
|
|
131
111
|
onLayout: onLayout,
|
|
132
|
-
style: [styles.container,
|
|
133
|
-
|
|
134
|
-
}, vertical ? {
|
|
135
|
-
height: height * options.length,
|
|
136
|
-
width: VERTICAL_WIDTH,
|
|
137
|
-
flexDirection: "column"
|
|
138
|
-
} : {
|
|
139
|
-
height,
|
|
140
|
-
flexDirection: "row"
|
|
141
|
-
}],
|
|
112
|
+
style: [styles.container, vertical ? styles.vertical : styles.horizontal, style // User override
|
|
113
|
+
],
|
|
142
114
|
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
143
|
-
|
|
144
|
-
style: [styles.thumbBase, {
|
|
145
|
-
backgroundColor: colors.bgFront
|
|
146
|
-
}, animatedThumbStyle]
|
|
115
|
+
style: [styles.thumb, thumbStyle, animatedThumbStyle]
|
|
147
116
|
}), options.map((opt, index) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
style: styles.item,
|
|
117
|
+
return /*#__PURE__*/_jsx(OptionItem, {
|
|
118
|
+
label: opt.label,
|
|
151
119
|
onPress: () => handlePress(index),
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
120
|
+
index: index,
|
|
121
|
+
translate: translate,
|
|
122
|
+
itemSizeSV: itemSizeSV,
|
|
123
|
+
textStyle: textStyle,
|
|
124
|
+
activeTextStyle: activeTextStyle,
|
|
125
|
+
inactiveTextStyle: inactiveTextStyle
|
|
156
126
|
}, opt.value);
|
|
157
127
|
})]
|
|
158
128
|
})
|
|
159
129
|
});
|
|
160
130
|
}
|
|
131
|
+
|
|
132
|
+
// Sub-component for individual options to isolate animated styles
|
|
133
|
+
const OptionItem = ({
|
|
134
|
+
label,
|
|
135
|
+
onPress,
|
|
136
|
+
index,
|
|
137
|
+
translate,
|
|
138
|
+
itemSizeSV,
|
|
139
|
+
textStyle,
|
|
140
|
+
activeTextStyle,
|
|
141
|
+
inactiveTextStyle
|
|
142
|
+
}) => {
|
|
143
|
+
const activeColor = StyleSheet.flatten(activeTextStyle)?.color ?? '#000';
|
|
144
|
+
const inactiveColor = StyleSheet.flatten(inactiveTextStyle)?.color ?? '#999';
|
|
145
|
+
const textAnimatedStyle = useAnimatedStyle(() => {
|
|
146
|
+
const center = index * itemSizeSV.value;
|
|
147
|
+
const color = interpolateColor(translate.value, [center - itemSizeSV.value, center, center + itemSizeSV.value], [inactiveColor, activeColor, inactiveColor]);
|
|
148
|
+
return {
|
|
149
|
+
color
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
153
|
+
style: styles.option,
|
|
154
|
+
onPress: onPress,
|
|
155
|
+
children: /*#__PURE__*/_jsx(Animated.Text, {
|
|
156
|
+
style: [styles.text, textStyle, textAnimatedStyle],
|
|
157
|
+
numberOfLines: 1,
|
|
158
|
+
children: label
|
|
159
|
+
})
|
|
160
|
+
});
|
|
161
|
+
};
|
|
161
162
|
const styles = StyleSheet.create({
|
|
162
163
|
container: {
|
|
164
|
+
// backgroundColor: '#f0f0f0',
|
|
163
165
|
borderRadius: 16,
|
|
164
|
-
overflow:
|
|
165
|
-
|
|
166
|
+
overflow: 'hidden',
|
|
167
|
+
padding: 2
|
|
168
|
+
// position: 'relative',
|
|
166
169
|
},
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
+
horizontal: {
|
|
171
|
+
flexDirection: 'row'
|
|
172
|
+
},
|
|
173
|
+
vertical: {
|
|
174
|
+
flexDirection: 'column'
|
|
175
|
+
},
|
|
176
|
+
thumb: {
|
|
177
|
+
// backgroundColor: '#fff',
|
|
178
|
+
borderRadius: 16,
|
|
170
179
|
shadowColor: '#000',
|
|
171
|
-
shadowOpacity: 0.3,
|
|
172
180
|
shadowOffset: {
|
|
173
181
|
width: 0,
|
|
174
182
|
height: 1
|
|
175
183
|
},
|
|
176
|
-
|
|
177
|
-
|
|
184
|
+
shadowOpacity: 0.1,
|
|
185
|
+
shadowRadius: 1,
|
|
186
|
+
elevation: 1
|
|
178
187
|
},
|
|
179
|
-
|
|
188
|
+
option: {
|
|
180
189
|
flex: 1,
|
|
181
|
-
alignItems:
|
|
182
|
-
justifyContent:
|
|
183
|
-
zIndex: 1
|
|
190
|
+
alignItems: 'center',
|
|
191
|
+
justifyContent: 'center'
|
|
192
|
+
// zIndex: 1
|
|
184
193
|
},
|
|
185
|
-
|
|
194
|
+
text: {
|
|
186
195
|
fontSize: 14,
|
|
187
|
-
fontWeight:
|
|
196
|
+
fontWeight: '500'
|
|
188
197
|
}
|
|
189
198
|
});
|
|
190
199
|
//# sourceMappingURL=AnimatedSwitch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useEffect","Pressable","StyleSheet","View","Gesture","GestureDetector","
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","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","itemSizeSV","translate","indexSV","currentIndex","findIndex","o","onLayout","e","width","height","nativeEvent","layout","totalSize","itemSize","length","emitChange","index","safeIndex","Math","max","min","handlePress","panGesture","Pan","onUpdate","term","translationY","translationX","startPos","pos","onEnd","round","animatedThumbStyle","opacity","transform","translateY","translateX","sizeStyle","position","left","top","gesture","children","styles","container","horizontal","thumb","map","opt","OptionItem","label","onPress","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,QAAQ,OAAO;AAC9C,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;AA0CjC,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;AACC,CAAC,EAAE;EACtB,MAAMe,UAAU,GAAGtB,cAAc,CAAC,CAAC,CAAC;EACpC,MAAMuB,SAAS,GAAGvB,cAAc,CAAC,CAAC,CAAC;EACnC,MAAMwB,OAAO,GAAGxB,cAAc,CAAC,CAAC,CAAC;EAEjC,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AK,EAAEiD,MAAM,CAACe,MAAO;IAACP,OAAO,EAAEA,OAAQ;IAAAT,QAAA,eAChD5D,IAAA,CAACP,QAAQ,CAACoF,IAAI;MACZjE,KAAK,EAAE,CAACiD,MAAM,CAACiB,IAAI,EAAEhE,SAAS,EAAE4D,iBAAiB,CAAE;MACnDK,aAAa,EAAE,CAAE;MAAAnB,QAAA,EAEhBQ;IAAK,CACO;EAAC,CACP,CAAC;AAEhB,CAAC;AAED,MAAMP,MAAM,GAAGzE,UAAU,CAAC4F,MAAM,CAAC;EAC/BlB,SAAS,EAAE;IACT;IACAmB,YAAY,EAAE,EAAE;IAChBC,QAAQ,EAAE,QAAQ;IAClBC,OAAO,EAAE;IACT;EACF,CAAC;EACDpB,UAAU,EAAE;IACVqB,aAAa,EAAE;EACjB,CAAC;EACDzE,QAAQ,EAAE;IACRyE,aAAa,EAAE;EACjB,CAAC;EACDpB,KAAK,EAAE;IACL;IACAiB,YAAY,EAAE,EAAE;IAChBI,WAAW,EAAE,MAAM;IACnBC,YAAY,EAAE;MAAE5D,KAAK,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAE,CAAC;IACrC4D,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":[]}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AnimatedSwitch"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,cAAc,
|
|
1
|
+
{"version":3,"names":["AnimatedSwitch"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,cAAc,QAAkC,qBAAkB;AAE3E,eAAeA,cAAc;AAC7B,SAASA,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|