@multiplatform.one/forms 7.35.0 → 7.37.0
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/dist/cjs/Wheel/{WheelEdgeFade.cjs → NativeWheel.cjs} +5 -5
- package/dist/cjs/Wheel/NativeWheel.native.js +408 -0
- package/dist/cjs/Wheel/NativeWheel.native.js.map +1 -0
- package/dist/cjs/Wheel/haptic.cjs +3 -4
- package/dist/cjs/Wheel/haptic.native.js +4 -5
- package/dist/cjs/Wheel/haptic.native.js.map +1 -1
- package/dist/cjs/Wheel/index.cjs +62 -218
- package/dist/cjs/Wheel/index.native.js +54 -228
- package/dist/cjs/Wheel/index.native.js.map +1 -1
- package/dist/cjs/Wheel/wheelShared.cjs +156 -0
- package/dist/cjs/Wheel/wheelShared.native.js +169 -0
- package/dist/cjs/Wheel/wheelShared.native.js.map +1 -0
- package/dist/cjs/shared/TimeColumn.cjs +0 -9
- package/dist/cjs/shared/TimeColumn.native.js +0 -9
- package/dist/cjs/shared/TimeColumn.native.js.map +1 -1
- package/dist/esm/Wheel/NativeWheel.mjs +5 -0
- package/dist/esm/Wheel/NativeWheel.mjs.map +1 -0
- package/dist/esm/Wheel/NativeWheel.native.js +380 -0
- package/dist/esm/Wheel/NativeWheel.native.js.map +1 -0
- package/dist/esm/Wheel/haptic.mjs +3 -4
- package/dist/esm/Wheel/haptic.mjs.map +1 -1
- package/dist/esm/Wheel/haptic.native.js +4 -5
- package/dist/esm/Wheel/haptic.native.js.map +1 -1
- package/dist/esm/Wheel/index.mjs +49 -205
- package/dist/esm/Wheel/index.mjs.map +1 -1
- package/dist/esm/Wheel/index.native.js +41 -215
- package/dist/esm/Wheel/index.native.js.map +1 -1
- package/dist/esm/Wheel/wheelShared.mjs +119 -0
- package/dist/esm/Wheel/wheelShared.mjs.map +1 -0
- package/dist/esm/Wheel/wheelShared.native.js +129 -0
- package/dist/esm/Wheel/wheelShared.native.js.map +1 -0
- package/dist/esm/shared/TimeColumn.mjs +0 -9
- package/dist/esm/shared/TimeColumn.mjs.map +1 -1
- package/dist/esm/shared/TimeColumn.native.js +0 -9
- package/dist/esm/shared/TimeColumn.native.js.map +1 -1
- package/dist/jsx/Wheel/NativeWheel.mjs +5 -0
- package/dist/jsx/Wheel/NativeWheel.mjs.map +1 -0
- package/dist/jsx/Wheel/NativeWheel.native.js +408 -0
- package/dist/jsx/Wheel/NativeWheel.native.js.map +1 -0
- package/dist/jsx/Wheel/haptic.mjs +3 -4
- package/dist/jsx/Wheel/haptic.mjs.map +1 -1
- package/dist/jsx/Wheel/haptic.native.js +4 -5
- package/dist/jsx/Wheel/haptic.native.js.map +1 -1
- package/dist/jsx/Wheel/index.mjs +49 -205
- package/dist/jsx/Wheel/index.mjs.map +1 -1
- package/dist/jsx/Wheel/index.native.js +54 -228
- package/dist/jsx/Wheel/index.native.js.map +1 -1
- package/dist/jsx/Wheel/wheelShared.mjs +119 -0
- package/dist/jsx/Wheel/wheelShared.mjs.map +1 -0
- package/dist/jsx/Wheel/wheelShared.native.js +169 -0
- package/dist/jsx/Wheel/wheelShared.native.js.map +1 -0
- package/dist/jsx/shared/TimeColumn.mjs +0 -9
- package/dist/jsx/shared/TimeColumn.mjs.map +1 -1
- package/dist/jsx/shared/TimeColumn.native.js +0 -9
- package/dist/jsx/shared/TimeColumn.native.js.map +1 -1
- package/package.json +8 -8
- package/src/Wheel/NativeWheel.native.spec.tsx +181 -0
- package/src/Wheel/NativeWheel.native.tsx +430 -0
- package/src/Wheel/NativeWheel.tsx +6 -0
- package/src/Wheel/haptic.ts +9 -8
- package/src/Wheel/index.tsx +121 -363
- package/src/Wheel/wheelShared.spec.ts +53 -0
- package/src/Wheel/wheelShared.ts +222 -0
- package/src/shared/TimeColumn.tsx +0 -7
- package/types/Wheel/NativeWheel.d.ts +4 -0
- package/types/Wheel/NativeWheel.d.ts.map +1 -0
- package/types/Wheel/NativeWheel.native.d.ts +9 -0
- package/types/Wheel/NativeWheel.native.d.ts.map +1 -0
- package/types/Wheel/haptic.d.ts +4 -2
- package/types/Wheel/haptic.d.ts.map +1 -1
- package/types/Wheel/index.d.ts +4 -49
- package/types/Wheel/index.d.ts.map +1 -1
- package/types/Wheel/wheelShared.d.ts +87 -0
- package/types/Wheel/wheelShared.d.ts.map +1 -0
- package/types/shared/TimeColumn.d.ts.map +1 -1
- package/dist/cjs/Wheel/WheelEdgeFade.native.js +0 -116
- package/dist/cjs/Wheel/WheelEdgeFade.native.js.map +0 -1
- package/dist/esm/Wheel/WheelEdgeFade.mjs +0 -5
- package/dist/esm/Wheel/WheelEdgeFade.mjs.map +0 -1
- package/dist/esm/Wheel/WheelEdgeFade.native.js +0 -88
- package/dist/esm/Wheel/WheelEdgeFade.native.js.map +0 -1
- package/dist/jsx/Wheel/WheelEdgeFade.mjs +0 -5
- package/dist/jsx/Wheel/WheelEdgeFade.mjs.map +0 -1
- package/dist/jsx/Wheel/WheelEdgeFade.native.js +0 -116
- package/dist/jsx/Wheel/WheelEdgeFade.native.js.map +0 -1
- package/src/Wheel/WheelEdgeFade.native.tsx +0 -67
- package/src/Wheel/WheelEdgeFade.spec.tsx +0 -141
- package/src/Wheel/WheelEdgeFade.tsx +0 -7
- package/types/Wheel/WheelEdgeFade.d.ts +0 -8
- package/types/Wheel/WheelEdgeFade.d.ts.map +0 -1
- package/types/Wheel/WheelEdgeFade.native.d.ts +0 -8
- package/types/Wheel/WheelEdgeFade.native.d.ts.map +0 -1
package/dist/cjs/Wheel/index.cjs
CHANGED
|
@@ -25,29 +25,18 @@ __export(Wheel_exports, {
|
|
|
25
25
|
Wheel: () => Wheel
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(Wheel_exports);
|
|
28
|
-
var import_theme = require("@multiplatform.one/theme");
|
|
29
28
|
var import_react = require("react");
|
|
30
|
-
var import_react_native = require("react-native-web");
|
|
31
|
-
var import_theme2 = require("@multiplatform.one/theme");
|
|
32
29
|
var import_tamagui = require("tamagui");
|
|
33
30
|
var import_t = require("../shared/t.cjs");
|
|
34
31
|
var import_haptic = require("./haptic.cjs");
|
|
35
|
-
var
|
|
32
|
+
var import_NativeWheel = require("./NativeWheel.cjs");
|
|
33
|
+
var import_wheelShared = require("./wheelShared.cjs");
|
|
36
34
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
37
35
|
const friction = 0.95;
|
|
38
36
|
const minVelocity = 0.5;
|
|
39
37
|
const momentumMultiplier = 0.8;
|
|
40
38
|
const rubberBandConstant = 0.55;
|
|
41
39
|
const tapSlopPx = 8;
|
|
42
|
-
const diameterRatio = 1.07;
|
|
43
|
-
const squeeze = 1.45;
|
|
44
|
-
const perspectivePx = 400;
|
|
45
|
-
const defaultColumnWidth = 88;
|
|
46
|
-
const wheelFontByStep = {
|
|
47
|
-
[-1]: "$6",
|
|
48
|
-
0: "$8",
|
|
49
|
-
1: "$9"
|
|
50
|
-
};
|
|
51
40
|
const WHEEL_FOCUS_STYLE_ID = "mp1-wheel-focus";
|
|
52
41
|
function ensureWheelFocusStyles() {
|
|
53
42
|
if (!import_tamagui.isWeb || typeof document === "undefined") return;
|
|
@@ -83,43 +72,15 @@ const SelectionIndicator = (0, import_tamagui.styled)(import_tamagui.View, {
|
|
|
83
72
|
right: 0,
|
|
84
73
|
pointerEvents: "none"
|
|
85
74
|
});
|
|
86
|
-
function normalizeItem(item) {
|
|
87
|
-
if (typeof item === "object" && item !== null && "value" in item) {
|
|
88
|
-
return item;
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
value: item,
|
|
92
|
-
label: String(item)
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function getItemLabel(item) {
|
|
96
|
-
const normalized = normalizeItem(item);
|
|
97
|
-
return normalized.label ?? String(normalized.value);
|
|
98
|
-
}
|
|
99
|
-
function getItemValue(item) {
|
|
100
|
-
const normalized = normalizeItem(item);
|
|
101
|
-
return normalized.value;
|
|
102
|
-
}
|
|
103
|
-
function modIndex(row, n) {
|
|
104
|
-
if (n <= 0) return 0;
|
|
105
|
-
return (row % n + n) % n;
|
|
106
|
-
}
|
|
107
75
|
function equivalentOffsetNear(referenceOffset, targetOffset, n, itemHeight) {
|
|
108
76
|
if (n <= 0 || itemHeight <= 0) return targetOffset;
|
|
109
77
|
const rT = Math.round(targetOffset / itemHeight);
|
|
110
|
-
const m = modIndex(rT, n);
|
|
78
|
+
const m = (0, import_wheelShared.modIndex)(rT, n);
|
|
111
79
|
const span = n * itemHeight;
|
|
112
80
|
const base = m * itemHeight;
|
|
113
81
|
const k = Math.round((referenceOffset - base) / span);
|
|
114
82
|
return base + k * span;
|
|
115
83
|
}
|
|
116
|
-
function nearestRowForDataIndex(currentRow, targetDataIndex, n) {
|
|
117
|
-
const currentMod = modIndex(currentRow, n);
|
|
118
|
-
let delta = targetDataIndex - currentMod;
|
|
119
|
-
if (delta > n / 2) delta -= n;
|
|
120
|
-
if (delta < -n / 2) delta += n;
|
|
121
|
-
return currentRow + delta;
|
|
122
|
-
}
|
|
123
84
|
function rubberBand(offset, dimension) {
|
|
124
85
|
const c = rubberBandConstant;
|
|
125
86
|
const x = Math.abs(offset);
|
|
@@ -127,66 +88,45 @@ function rubberBand(offset, dimension) {
|
|
|
127
88
|
return offset < 0 ? -result : result;
|
|
128
89
|
}
|
|
129
90
|
function getItemTransform(index, scrollOffset, itemHeight, containerHeight) {
|
|
130
|
-
const
|
|
131
|
-
const angle = (index * itemHeight - scrollOffset) / squeeze / Math.max(radius, 1);
|
|
132
|
-
const clamped = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, angle));
|
|
133
|
-
const centerTop = (containerHeight - itemHeight) / 2;
|
|
134
|
-
const translateY = centerTop + radius * Math.sin(clamped);
|
|
135
|
-
const rotateX = -(clamped * 180) / Math.PI;
|
|
136
|
-
const scale = Math.max(0.72, Math.min(1, Math.cos(clamped)));
|
|
91
|
+
const pose = (0, import_wheelShared.drumPose)(index - scrollOffset / itemHeight, itemHeight, containerHeight);
|
|
137
92
|
return {
|
|
138
|
-
translateY,
|
|
139
|
-
rotateX,
|
|
140
|
-
scale,
|
|
93
|
+
translateY: (containerHeight - itemHeight) / 2 + pose.offset,
|
|
94
|
+
rotateX: pose.rotateX,
|
|
95
|
+
scale: pose.scale,
|
|
141
96
|
opacity: 1
|
|
142
97
|
};
|
|
143
98
|
}
|
|
144
|
-
function
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
function highlightBandStyle(edges, radiusToken, pointy) {
|
|
152
|
-
const r = pointy ? 0 : tokenPx(radiusToken, "radius");
|
|
153
|
-
const inset = tokenPx("$2", "space");
|
|
154
|
-
const capStart = edges === "all" || edges === "start";
|
|
155
|
-
const capEnd = edges === "all" || edges === "end";
|
|
156
|
-
return {
|
|
157
|
-
borderStartStartRadius: capStart ? r : 0,
|
|
158
|
-
borderStartEndRadius: capEnd ? r : 0,
|
|
159
|
-
borderEndStartRadius: capStart ? r : 0,
|
|
160
|
-
borderEndEndRadius: capEnd ? r : 0,
|
|
161
|
-
marginInlineStart: capStart ? inset : 0,
|
|
162
|
-
marginInlineEnd: capEnd ? inset : 0
|
|
163
|
-
};
|
|
99
|
+
function Wheel(props) {
|
|
100
|
+
return import_tamagui.isWeb ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(WebWheel, {
|
|
101
|
+
...props
|
|
102
|
+
}) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_NativeWheel.NativeWheel, {
|
|
103
|
+
...props
|
|
104
|
+
});
|
|
164
105
|
}
|
|
165
|
-
function
|
|
166
|
-
items,
|
|
167
|
-
value,
|
|
168
|
-
onChange,
|
|
169
|
-
visibleItems = 5,
|
|
170
|
-
itemHeight: itemHeightProp,
|
|
171
|
-
width: widthProp,
|
|
172
|
-
renderItem,
|
|
173
|
-
disabled = false,
|
|
174
|
-
size: sizeProp,
|
|
175
|
-
loop = false,
|
|
176
|
-
highlightEdges = "all",
|
|
177
|
-
flex,
|
|
178
|
-
onItemCross,
|
|
179
|
-
"aria-label": ariaLabel
|
|
180
|
-
}) {
|
|
106
|
+
function WebWheel(props) {
|
|
181
107
|
const {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
108
|
+
items,
|
|
109
|
+
value,
|
|
110
|
+
onChange,
|
|
111
|
+
visibleItems = 5,
|
|
112
|
+
width: widthProp,
|
|
113
|
+
renderItem,
|
|
114
|
+
disabled = false,
|
|
115
|
+
loop = false,
|
|
116
|
+
flex,
|
|
117
|
+
onItemCross,
|
|
118
|
+
"aria-label": ariaLabel
|
|
119
|
+
} = props;
|
|
120
|
+
const {
|
|
121
|
+
knobProps,
|
|
122
|
+
size,
|
|
123
|
+
itemHeight,
|
|
124
|
+
snapDurationMs,
|
|
125
|
+
highlightStyle,
|
|
126
|
+
highlightClassName
|
|
127
|
+
} = (0, import_wheelShared.useWheelLayout)(props);
|
|
128
|
+
const columnWidth = widthProp ?? import_wheelShared.defaultColumnWidth;
|
|
187
129
|
ensureWheelFocusStyles();
|
|
188
|
-
const motionTransition = knobProps.motion.control.transition;
|
|
189
|
-
const snapDurationMs = (0, import_theme.motionDurationMs)(motionTransition);
|
|
190
130
|
const containerRef = (0, import_react.useRef)(null);
|
|
191
131
|
const [scrollOffset, setScrollOffset] = (0, import_react.useState)(0);
|
|
192
132
|
const [selectedIndex, setSelectedIndex] = (0, import_react.useState)(0);
|
|
@@ -209,7 +149,7 @@ function Wheel({
|
|
|
209
149
|
const paddingItems = Math.floor(visibleItems / 2);
|
|
210
150
|
const minOffset = 0;
|
|
211
151
|
const maxOffset = n > 0 ? (n - 1) * itemHeight : 0;
|
|
212
|
-
const liveDataIndex = n === 0 ? 0 : loopEnabled ? modIndex(Math.round(scrollOffset / itemHeight), n) : Math.max(0, Math.min(Math.round(scrollOffset / itemHeight), n - 1));
|
|
152
|
+
const liveDataIndex = n === 0 ? 0 : loopEnabled ? (0, import_wheelShared.modIndex)(Math.round(scrollOffset / itemHeight), n) : Math.max(0, Math.min(Math.round(scrollOffset / itemHeight), n - 1));
|
|
213
153
|
const lastCrossIndexRef = (0, import_react.useRef)(null);
|
|
214
154
|
const onItemCrossRef = (0, import_react.useRef)(onItemCross);
|
|
215
155
|
onItemCrossRef.current = onItemCross;
|
|
@@ -223,7 +163,7 @@ function Wheel({
|
|
|
223
163
|
lastCrossIndexRef.current = liveDataIndex;
|
|
224
164
|
const item = items[liveDataIndex];
|
|
225
165
|
if (item === void 0) return;
|
|
226
|
-
onItemCrossRef.current?.(getItemValue(item), liveDataIndex);
|
|
166
|
+
onItemCrossRef.current?.((0, import_wheelShared.getItemValue)(item), liveDataIndex);
|
|
227
167
|
(0, import_haptic.fireSelectionHaptic)();
|
|
228
168
|
}, [liveDataIndex, items, n]);
|
|
229
169
|
const runSnapComplete = (0, import_react.useCallback)((finalOffset, dataIndex) => {
|
|
@@ -232,7 +172,7 @@ function Wheel({
|
|
|
232
172
|
scrollOffsetRef.current = settled;
|
|
233
173
|
setScrollOffset(settled);
|
|
234
174
|
setSelectedIndex(safeIdx);
|
|
235
|
-
onChange?.(getItemValue(items[safeIdx]));
|
|
175
|
+
onChange?.((0, import_wheelShared.getItemValue)(items[safeIdx]));
|
|
236
176
|
isAnimatingRef.current = false;
|
|
237
177
|
}, [items, n, onChange, loopEnabled, itemHeight]);
|
|
238
178
|
const animateToOffset = (0, import_react.useCallback)((targetOffset, dataIndex, animated) => {
|
|
@@ -275,14 +215,14 @@ function Wheel({
|
|
|
275
215
|
return;
|
|
276
216
|
}
|
|
277
217
|
const currentR = Math.round(scrollOffsetRef.current / itemHeight);
|
|
278
|
-
const targetR = nearestRowForDataIndex(currentR, clampedData, n);
|
|
218
|
+
const targetR = (0, import_wheelShared.nearestRowForDataIndex)(currentR, clampedData, n);
|
|
279
219
|
const targetOffset = targetR * itemHeight;
|
|
280
|
-
const dataIdx = modIndex(targetR, n);
|
|
220
|
+
const dataIdx = (0, import_wheelShared.modIndex)(targetR, n);
|
|
281
221
|
animateToOffset(targetOffset, dataIdx, animated);
|
|
282
222
|
}, [n, itemHeight, loopEnabled, animateToOffset]);
|
|
283
223
|
(0, import_react.useEffect)(() => {
|
|
284
224
|
if (value === void 0) return;
|
|
285
|
-
const index = items.findIndex(item => getItemValue(item) === value);
|
|
225
|
+
const index = items.findIndex(item => (0, import_wheelShared.getItemValue)(item) === value);
|
|
286
226
|
if (index === -1) return;
|
|
287
227
|
if (!hasMountedRef.current) {
|
|
288
228
|
hasMountedRef.current = true;
|
|
@@ -307,7 +247,7 @@ function Wheel({
|
|
|
307
247
|
const r = Math.round(scrollOffsetRef.current / itemHeight);
|
|
308
248
|
if (loopEnabled) {
|
|
309
249
|
const targetOffset = r * itemHeight;
|
|
310
|
-
const dataIdx = modIndex(r, n);
|
|
250
|
+
const dataIdx = (0, import_wheelShared.modIndex)(r, n);
|
|
311
251
|
animateToOffset(targetOffset, dataIdx, animated);
|
|
312
252
|
} else {
|
|
313
253
|
const dataIdx = Math.max(0, Math.min(r, n - 1));
|
|
@@ -322,7 +262,7 @@ function Wheel({
|
|
|
322
262
|
let best = null;
|
|
323
263
|
for (let vr = centerRow - rowBuffer; vr <= centerRow + rowBuffer; vr++) {
|
|
324
264
|
if (!loopEnabled && (vr < 0 || vr >= n)) continue;
|
|
325
|
-
const dataIndex = loopEnabled ? modIndex(vr, n) : vr;
|
|
265
|
+
const dataIndex = loopEnabled ? (0, import_wheelShared.modIndex)(vr, n) : vr;
|
|
326
266
|
const {
|
|
327
267
|
translateY
|
|
328
268
|
} = getItemTransform(vr, offset, itemHeight, containerHeight);
|
|
@@ -441,51 +381,6 @@ function Wheel({
|
|
|
441
381
|
snapToNearestRow(true);
|
|
442
382
|
}
|
|
443
383
|
}, [snapToNearestRow, startMomentum, hitTestDataIndex, snapToIndex, disabled]);
|
|
444
|
-
const disabledRef = (0, import_react.useRef)(disabled);
|
|
445
|
-
disabledRef.current = disabled;
|
|
446
|
-
const pointerDownRef = (0, import_react.useRef)(handlePointerDown);
|
|
447
|
-
pointerDownRef.current = handlePointerDown;
|
|
448
|
-
const pointerMoveRef = (0, import_react.useRef)(handlePointerMove);
|
|
449
|
-
pointerMoveRef.current = handlePointerMove;
|
|
450
|
-
const pointerUpRef = (0, import_react.useRef)(handlePointerUp);
|
|
451
|
-
pointerUpRef.current = handlePointerUp;
|
|
452
|
-
const panResponder = (0, import_react.useMemo)(() => {
|
|
453
|
-
if (import_tamagui.isWeb) return {
|
|
454
|
-
panHandlers: {}
|
|
455
|
-
};
|
|
456
|
-
return import_react_native.PanResponder.create({
|
|
457
|
-
onStartShouldSetPanResponder: () => !disabledRef.current,
|
|
458
|
-
onMoveShouldSetPanResponder: (_, gesture) => Math.abs(gesture.dy) > 1,
|
|
459
|
-
onPanResponderTerminationRequest: () => false,
|
|
460
|
-
onShouldBlockNativeResponder: () => true,
|
|
461
|
-
onPanResponderGrant: evt => {
|
|
462
|
-
pointerDownRef.current({
|
|
463
|
-
clientY: evt.nativeEvent.pageY,
|
|
464
|
-
pointerId: 1
|
|
465
|
-
});
|
|
466
|
-
},
|
|
467
|
-
onPanResponderMove: evt => {
|
|
468
|
-
pointerMoveRef.current({
|
|
469
|
-
clientY: evt.nativeEvent.pageY,
|
|
470
|
-
pointerId: 1
|
|
471
|
-
});
|
|
472
|
-
},
|
|
473
|
-
onPanResponderRelease: evt => {
|
|
474
|
-
pointerUpRef.current({
|
|
475
|
-
clientY: evt.nativeEvent.pageY,
|
|
476
|
-
pointerId: 1,
|
|
477
|
-
locationY: evt.nativeEvent.locationY
|
|
478
|
-
});
|
|
479
|
-
},
|
|
480
|
-
onPanResponderTerminate: evt => {
|
|
481
|
-
pointerUpRef.current({
|
|
482
|
-
clientY: evt.nativeEvent.pageY,
|
|
483
|
-
pointerId: 1,
|
|
484
|
-
locationY: evt.nativeEvent.locationY
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
}, []);
|
|
489
384
|
const handleWheel = (0, import_react.useCallback)(e => {
|
|
490
385
|
if (disabled) return;
|
|
491
386
|
e.preventDefault();
|
|
@@ -545,7 +440,7 @@ function Wheel({
|
|
|
545
440
|
}
|
|
546
441
|
e.preventDefault();
|
|
547
442
|
if (loopEnabled) {
|
|
548
|
-
const newIndex = modIndex(selectedIndex + delta, n);
|
|
443
|
+
const newIndex = (0, import_wheelShared.modIndex)(selectedIndex + delta, n);
|
|
549
444
|
snapToIndex(newIndex);
|
|
550
445
|
} else {
|
|
551
446
|
const newIndex = Math.max(0, Math.min(selectedIndex + delta, n - 1));
|
|
@@ -573,37 +468,23 @@ function Wheel({
|
|
|
573
468
|
}, []);
|
|
574
469
|
const renderRows = (0, import_react.useMemo)(() => {
|
|
575
470
|
if (n === 0) return [];
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
586
|
-
return list;
|
|
471
|
+
const span = Math.ceil((0, import_wheelShared.drumReachRows)(itemHeight, containerHeight));
|
|
472
|
+
const centerRow = Math.round(scrollOffset / itemHeight);
|
|
473
|
+
const first = loopEnabled ? centerRow - span : Math.max(0, centerRow - span);
|
|
474
|
+
const last = loopEnabled ? centerRow + span : Math.min(n - 1, centerRow + span);
|
|
475
|
+
const list = [];
|
|
476
|
+
for (let vr = first; vr <= last; vr++) {
|
|
477
|
+
list.push({
|
|
478
|
+
virtualRow: vr,
|
|
479
|
+
dataIndex: (0, import_wheelShared.modIndex)(vr, n)
|
|
480
|
+
});
|
|
587
481
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return Array.from({
|
|
591
|
-
length: end - start + 1
|
|
592
|
-
}, (_, i) => {
|
|
593
|
-
const virtualRow = start + i;
|
|
594
|
-
return {
|
|
595
|
-
virtualRow,
|
|
596
|
-
dataIndex: virtualRow
|
|
597
|
-
};
|
|
598
|
-
});
|
|
599
|
-
}, [n, loopEnabled, scrollOffset, itemHeight, paddingItems, containerHeight]);
|
|
482
|
+
return list;
|
|
483
|
+
}, [n, loopEnabled, scrollOffset, itemHeight, containerHeight]);
|
|
600
484
|
const itemColor = isSelected => disabled ? "$color10" : isSelected ? "$color12" : "$color11";
|
|
601
|
-
const radiusToken = knobProps.borderRadius.borderRadius;
|
|
602
|
-
const highlightStyle = highlightBandStyle(highlightEdges, radiusToken, Boolean(knobProps.pointy));
|
|
603
|
-
const highlightSmoothClass = "className" in knobProps.borderRadius && typeof knobProps.borderRadius.className === "string" ? knobProps.borderRadius.className : void 0;
|
|
604
485
|
const renderItemNode = (dataIndex, isSelected) => {
|
|
605
486
|
const item = items[dataIndex];
|
|
606
|
-
const itemValue = getItemValue(item);
|
|
487
|
+
const itemValue = (0, import_wheelShared.getItemValue)(item);
|
|
607
488
|
if (renderItem) return renderItem(itemValue, dataIndex, isSelected);
|
|
608
489
|
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
|
|
609
490
|
...knobProps.body,
|
|
@@ -613,7 +494,7 @@ function Wheel({
|
|
|
613
494
|
ellipsizeMode: "tail",
|
|
614
495
|
maxWidth: "100%",
|
|
615
496
|
paddingHorizontal: "$2",
|
|
616
|
-
children: getItemLabel(item)
|
|
497
|
+
children: (0, import_wheelShared.getItemLabel)(item)
|
|
617
498
|
});
|
|
618
499
|
};
|
|
619
500
|
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(WheelContainer, {
|
|
@@ -626,13 +507,13 @@ function Wheel({
|
|
|
626
507
|
"aria-disabled": disabled || void 0,
|
|
627
508
|
opacity: 1,
|
|
628
509
|
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectionIndicator, {
|
|
629
|
-
className:
|
|
510
|
+
className: highlightClassName,
|
|
630
511
|
backgroundColor: "$color4",
|
|
631
512
|
top: paddingItems * itemHeight,
|
|
632
513
|
height: itemHeight,
|
|
633
514
|
style: highlightStyle,
|
|
634
515
|
"data-testid": "wheel-selection"
|
|
635
|
-
}),
|
|
516
|
+
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)("div", {
|
|
636
517
|
ref: containerRef,
|
|
637
518
|
className: "mp1-wheel-wrapper",
|
|
638
519
|
tabIndex: disabled ? -1 : 0,
|
|
@@ -642,14 +523,14 @@ function Wheel({
|
|
|
642
523
|
"aria-valuemin": 0,
|
|
643
524
|
"aria-valuemax": Math.max(0, n - 1),
|
|
644
525
|
"aria-valuenow": selectedIndex,
|
|
645
|
-
"aria-valuetext": items[selectedIndex] !== void 0 ? getItemLabel(items[selectedIndex]) : void 0,
|
|
526
|
+
"aria-valuetext": items[selectedIndex] !== void 0 ? (0, import_wheelShared.getItemLabel)(items[selectedIndex]) : void 0,
|
|
646
527
|
"aria-disabled": disabled || void 0,
|
|
647
528
|
"data-disabled": disabled ? true : void 0,
|
|
648
529
|
style: {
|
|
649
530
|
width: "100%",
|
|
650
531
|
height: containerHeight,
|
|
651
532
|
position: "relative",
|
|
652
|
-
perspective: `${
|
|
533
|
+
perspective: `${containerHeight * 4}px`,
|
|
653
534
|
perspectiveOrigin: "center center",
|
|
654
535
|
overflow: "hidden",
|
|
655
536
|
userSelect: "none",
|
|
@@ -693,43 +574,6 @@ function Wheel({
|
|
|
693
574
|
children: renderItemNode(dataIndex, isSelected)
|
|
694
575
|
}, `${dataIndex}-${virtualRow}`);
|
|
695
576
|
})
|
|
696
|
-
}) : /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.View, {
|
|
697
|
-
width: "100%",
|
|
698
|
-
height: containerHeight,
|
|
699
|
-
position: "relative",
|
|
700
|
-
overflow: "hidden",
|
|
701
|
-
cursor: disabled ? "not-allowed" : "grab",
|
|
702
|
-
"data-testid": "wheel-wrapper",
|
|
703
|
-
"data-disabled": disabled ? true : void 0,
|
|
704
|
-
"aria-disabled": disabled || void 0,
|
|
705
|
-
...panResponder.panHandlers,
|
|
706
|
-
children: [renderRows.map(({
|
|
707
|
-
virtualRow,
|
|
708
|
-
dataIndex
|
|
709
|
-
}) => {
|
|
710
|
-
const isSelected = dataIndex === liveDataIndex;
|
|
711
|
-
const transform = getItemTransform(virtualRow, scrollOffset, itemHeight, containerHeight);
|
|
712
|
-
if (Math.abs(transform.rotateX) > 85) return null;
|
|
713
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
|
|
714
|
-
position: "absolute",
|
|
715
|
-
left: 0,
|
|
716
|
-
right: 0,
|
|
717
|
-
height: itemHeight,
|
|
718
|
-
alignItems: "center",
|
|
719
|
-
justifyContent: "center",
|
|
720
|
-
opacity: transform.opacity,
|
|
721
|
-
pointerEvents: "none",
|
|
722
|
-
y: transform.translateY,
|
|
723
|
-
scale: transform.scale,
|
|
724
|
-
rotateX: `${transform.rotateX}deg`,
|
|
725
|
-
"data-testid": "wheel-item",
|
|
726
|
-
"data-index": dataIndex,
|
|
727
|
-
"data-selected": isSelected ? true : void 0,
|
|
728
|
-
children: renderItemNode(dataIndex, isSelected)
|
|
729
|
-
}, `${dataIndex}-${virtualRow}`);
|
|
730
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_WheelEdgeFade.WheelEdgeFade, {
|
|
731
|
-
height: paddingItems * itemHeight
|
|
732
|
-
})]
|
|
733
577
|
})]
|
|
734
578
|
});
|
|
735
579
|
}
|