Open History to see the last commit
1import { type StaticScreenProps, useNavigation } from "@react-navigation/native";
2import { useAtomValue } from "@effect/atom-react";
3import {
4 makeQueuedRunsAtom,
5 queuedRunEditBlockedReason,
6} from "@t3tools/client-runtime/queued-run-edit";
7import type { ChatAttachment, EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
8import { Atom } from "effect/reactivity";
9import { Image } from "expo-image";
10import * as Haptics from "expo-haptics";
11import { useEffect, useEffectEvent, useRef, useState } from "react";
12import { Animated, Platform, Pressable, ScrollView, View } from "react-native";
13import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
14import ReanimatedSwipeable, {
15 type SwipeableMethods,
16} from "react-native-gesture-handler/ReanimatedSwipeable";
17import { Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";
18import { useSafeAreaInsets } from "react-native-safe-area-context";
19import Reanimated, { ReduceMotion, useAnimatedStyle, withTiming } from "react-native-reanimated";
20
21import { Button } from "../../components/ui/Button";
22import { AndroidSheetHeader } from "../../components/ui/AndroidScreenHeader";
23import { AppText as Text } from "../../components/ui/AppText";
24import { SymbolView } from "../../components/ui/AppSymbol";
25import { Menu } from "../../components/ui/Menu";
26import { ScreenContent } from "../../components/ui/ScreenContent";
27import { scopedThreadKey } from "../../lib/scopedEntities";
28import { useUniwindTheme } from "../../lib/useUniwindTheme";
29import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
30import { useAssetUrl } from "../../state/assets";
31import { assetImageSource } from "../../lib/assetImageSource";
32import { beginQueuedRunEdit, useQueuedRunEdit } from "../../state/queued-run-edit";
33import { environmentThreadDetails, threadEnvironment } from "../../state/threads";
34import { useAtomCommand } from "../../state/use-atom-command";
35import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
36import {
37 REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
38 buildCancelQueuedRunCommand,
39 resolveQueueDragBeforeRunId,
40 resolveQueueDropBeforeRunId,
41 resolveThreadQueueRowControls,
42} from "./threadQueueControlPresentation";
43import { threadDragGapOffset } from "./threadDragGap";
44
45const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
46const REMOVE_ACTION_WIDTH = 76;
47const THUMBNAIL_LIMIT = 3;
48const EMPTY_QUEUED_COUNT_ATOM = Atom.make(0).pipe(
49 Atom.withLabel("mobile-thread-queue-count:empty"),
50);
51
52type QueueTarget = { readonly environmentId: EnvironmentId; readonly threadId: ThreadId };
53type QueueAction = "steer" | "edit" | "up" | "down" | "remove";
54type QueueRowLayout = { readonly id: RunId; readonly y?: number; readonly height?: number };
55type QueueDrag = {
56 readonly runId: RunId;
57 readonly order: string;
58 beforeRunId: RunId | null | undefined;
59 readonly rows: ReadonlyArray<QueueRowLayout>;
60};
61
62export function useThreadQueueWorkflow(target: QueueTarget) {
63 return useAtomValue(environmentThreadDetails.queueWorkflowAtom(target));
64}
65
66export function useThreadQueuedCount(target: QueueTarget | null) {
67 return useAtomValue(
68 target === null ? EMPTY_QUEUED_COUNT_ATOM : environmentThreadDetails.queuedCountAtom(target),
69 );
70}
71
72export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
73 const { layout } = useAdaptiveWorkspaceLayout();
74 const target = route.params;
75 const navigation = useNavigation();
76 const insets = useSafeAreaInsets();
77 const theme = useUniwindTheme();
78 const workflow = useThreadQueueWorkflow(target);
79 const threadKey = scopedThreadKey(target.environmentId, target.threadId);
80 const editing = useQueuedRunEdit(threadKey);
81 const pendingRequests = useAtomValue(environmentThreadDetails.pendingRequestsAtom(target));
82 const editBlockedReason = queuedRunEditBlockedReason({
83 openQuestionCount: pendingRequests?.userInputs.length ?? 0,
84 });
85 const reorder = useAtomCommand(threadEnvironment.reorderQueuedRun, "reorder queued message");
86 const promote = useAtomCommand(threadEnvironment.promoteQueuedRun, "promote queued message");
87 const cancel = useAtomCommand(threadEnvironment.cancelQueuedRun, "remove queued message");
88 const resume = useAtomCommand(threadEnvironment.resumeThreadQueue, "resume queue");
89 const [resuming, setResuming] = useState(false);
90 const [busyRunId, setBusyRunId] = useState<RunId | null>(null);
91 const busyRef = useRef(false);
92 const [dragState, setDragState] = useState<QueueDrag | null>(null);
93 const rowLayouts = useRef(new Map<RunId, { y: number; height: number }>());
94 const drag = useRef<QueueDrag | null>(null);
95 const [translation] = useState(() => new Animated.Value(0));
96 const queuedRuns = workflow?.queuedRuns ?? [];
97 const order = queuedRuns.map(({ run }) => run.id).join(",");
98 // A queue that changed under the drag (delivery, another client) ends it:
99 // the gesture handlers ignore it from then on and its preview disappears.
100 const visibleDrag = dragState?.order === order ? dragState : null;
101 const draggedRunId = visibleDrag?.runId ?? null;
102 const previewBeforeRunId = visibleDrag?.beforeRunId;
103 const dragRows = visibleDrag?.rows ?? null;
104
105 const hadQueuedRuns = useRef(queuedRuns.length > 0);
106 useEffect(() => {
107 if (queuedRuns.length > 0) {
108 hadQueuedRuns.current = true;
109 return;
110 }
111 if (hadQueuedRuns.current) navigation.goBack();
112 }, [navigation, queuedRuns.length]);
113
114 const move = async (runId: RunId, beforeRunId: RunId | null) => {
115 if (busyRef.current || !workflow?.canReorder) return;
116 busyRef.current = true;
117 setBusyRunId(runId);
118 void Haptics.selectionAsync();
119 await reorder({ ...target, input: { threadId: target.threadId, runId, beforeRunId } });
120 busyRef.current = false;
121 setBusyRunId(null);
122 };
123
124 const act = async (runId: RunId, action: QueueAction) => {
125 if (busyRef.current) return;
126 const index = queuedRuns.findIndex(({ run }) => run.id === runId);
127 if (index < 0) return;
128 if (action === "up" && index > 0) {
129 await move(runId, queuedRuns[index - 1]!.run.id);
130 return;
131 }
132 if (action === "down" && index < queuedRuns.length - 1) {
133 await move(runId, queuedRuns[index + 2]?.run.id ?? null);
134 return;
135 }
136 if (action === "edit") {
137 if (editBlockedReason !== null) return;
138 const entry = queuedRuns[index]!;
139 void Haptics.selectionAsync();
140 beginQueuedRunEdit(
141 threadKey,
142 {
143 runId,
144 messageId: entry.messageId,
145 originalText: entry.text,
146 existingAttachments: entry.attachments,
147 ...(entry.context ? { context: entry.context } : {}),
148 },
149 makeQueuedRunsAtom({
150 threadId: target.threadId,
151 snapshot: threadEnvironment.snapshotAtom(target.environmentId),
152 detailStatus: environmentThreadDetails.statusAtom(target),
153 runs: Atom.make(
154 (get) => get(environmentThreadDetails.quietThreadAtom(target))?.projection.runs ?? null,
155 ),
156 }),
157 );
158 navigation.goBack();
159 return;
160 }
161 if (action !== "steer" && action !== "remove") return;
162 busyRef.current = true;
163 setBusyRunId(runId);
164 void Haptics.selectionAsync();
165 if (action === "remove") {
166 await cancel(buildCancelQueuedRunCommand({ ...target, runId }));
167 } else if (workflow?.canSendNow) {
168 await resume({ ...target, input: { threadId: target.threadId, runId } });
169 } else if (workflow?.activeRun && workflow.canPromoteToSteer) {
170 await promote({
171 ...target,
172 input: {
173 threadId: target.threadId,
174 queuedRunId: runId,
175 targetRunId: workflow.activeRun.id,
176 },
177 });
178 }
179 busyRef.current = false;
180 setBusyRunId(null);
181 };
182
183 const canReorder = workflow?.canReorder === true && queuedRuns.length > 1;
184 const sourceLayout = dragRows?.find((row) => row.id === draggedRunId);
185 const lastLayout = dragRows?.at(-1);
186 const insertionOffset =
187 previewBeforeRunId === undefined
188 ? undefined
189 : previewBeforeRunId === null
190 ? lastLayout?.y === undefined || lastLayout.height === undefined
191 ? undefined
192 : lastLayout.y + lastLayout.height
193 : dragRows?.find((row) => row.id === previewBeforeRunId)?.y;
194 const queueRows = () =>
195 queuedRuns.map(({ run }) => ({ id: run.id, ...rowLayouts.current.get(run.id) }));
196 const content = (
197 <ScrollView
198 nestedScrollEnabled
199 className="flex-1"
200 scrollEnabled={draggedRunId === null}
201 // UIKit must inset content beneath the floating translucent iOS header.
202 contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
203 contentContainerClassName="px-5 pb-6"
204 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 16) + 8 }}
205 >
206 {workflow?.isHeld && queuedRuns.length > 0 ? (
207 <View className="gap-2 py-3">
208 <Text className="text-sm text-foreground-muted">Queue paused</Text>
209 <Button
210 label="Resume queue"
211 disabled={resuming || busyRunId !== null}
212 onPress={async () => {
213 if (busyRef.current) return;
214 busyRef.current = true;
215 setResuming(true);
216 await resume({ ...target, input: { threadId: target.threadId } });
217 busyRef.current = false;
218 setResuming(false);
219 }}
220 />
221 </View>
222 ) : null}
223 {editBlockedReason !== null && queuedRuns.length > 0 ? (
224 <Text className="py-3 text-sm text-foreground-muted">{editBlockedReason}</Text>
225 ) : null}
226 {queuedRuns.length === 0 ? (
227 <Text className="pt-6 text-center text-sm text-foreground-muted">
228 No messages waiting in this queue.
229 </Text>
230 ) : null}
231 {queuedRuns.map(({ run, text, attachments, context }, index) => {
232 const layout = dragRows?.find((row) => row.id === run.id);
233 const offset =
234 sourceLayout?.y !== undefined &&
235 sourceLayout.height !== undefined &&
236 layout?.y !== undefined &&
237 insertionOffset !== undefined
238 ? threadDragGapOffset(layout.y, sourceLayout.y, sourceLayout.height, insertionOffset)
239 : 0;
240 const controls = resolveThreadQueueRowControls({
241 busy: busyRunId !== null || draggedRunId !== null,
242 canPromoteToSteer: workflow?.canPromoteToSteer ?? false,
243 canSendNow: workflow?.canSendNow ?? false,
244 canReorder: workflow?.canReorder ?? false,
245 editBlocked: editBlockedReason !== null,
246 index,
247 isEditing: editing?.runId === run.id,
248 isGuestMessage: context?.guest !== undefined,
249 queuedCount: queuedRuns.length,
250 text,
251 });
252 const title =
253 controls.displayText || (attachments.length > 0 ? "Attachments" : "Queued message");
254 return (
255 <QueueShiftedRow
256 key={run.id}
257 offset={offset}
258 dragging={draggedRunId !== null}
259 lifted={draggedRunId === run.id}
260 onLayout={({ nativeEvent }) => rowLayouts.current.set(run.id, nativeEvent.layout)}
261 >
262 <Animated.View
263 className="flex-row items-center border-b border-border bg-sheet"
264 style={
265 draggedRunId === run.id
266 ? { transform: [{ translateY: translation }], zIndex: 1, opacity: 0.85 }
267 : undefined
268 }
269 >
270 {canReorder ? (
271 // Keep the vertical handle outside the sideways swipeable so their pans do not race.
272 <QueueDragHandle
273 disabled={busyRunId !== null}
274 title={title}
275 canMoveUp={controls.canMoveUp}
276 canMoveDown={controls.canMoveDown}
277 onStep={(action) => void act(run.id, action)}
278 onStart={() => {
279 const rows = queueRows();
280 const beforeRunId = resolveQueueDragBeforeRunId(rows, run.id, 0);
281 drag.current = { runId: run.id, order, beforeRunId, rows };
282 translation.setValue(0);
283 setDragState({ ...drag.current });
284 void Haptics.selectionAsync();
285 }}
286 onMove={(y) => {
287 const current = drag.current;
288 if (current?.runId !== run.id || current.order !== order) return;
289 translation.setValue(y);
290 const before = resolveQueueDragBeforeRunId(current.rows, run.id, y);
291 if (current.beforeRunId !== before) {
292 current.beforeRunId = before;
293 setDragState({ ...current });
294 }
295 }}
296 onEnd={(y, success) => {
297 const started = drag.current;
298 const stop = () => {
299 if (drag.current !== started) return;
300 drag.current = null;
301 setDragState(null);
302 translation.setValue(0);
303 };
304 if (!success || started?.order !== order || started.runId !== run.id) {
305 stop();
306 return;
307 }
308 const before = resolveQueueDropBeforeRunId(started.rows, run.id, y);
309 if (before === undefined) {
310 stop();
311 return;
312 }
313 const source = started.rows.find((row) => row.id === run.id);
314 const tail = started.rows.at(-1);
315 const insertion =
316 before === null
317 ? tail?.y !== undefined && tail.height !== undefined
318 ? tail.y + tail.height
319 : undefined
320 : started.rows.find((row) => row.id === before)?.y;
321 if (
322 source?.y !== undefined &&
323 source.height !== undefined &&
324 insertion !== undefined
325 ) {
326 Animated.timing(translation, {
327 toValue: insertion - source.y - (insertion > source.y ? source.height : 0),
328 duration: 160,
329 useNativeDriver: true,
330 }).start();
331 }
332 started.beforeRunId = before;
333 setDragState({ ...started });
334 void move(run.id, before).finally(stop);
335 }}
336 />
337 ) : null}
338 <QueueRowSwipeable
339 enabled={draggedRunId === null && busyRunId === null && controls.canDismiss}
340 background={theme["--color-sheet"]}
341 onRemove={() => void act(run.id, "remove")}
342 >
343 <View className="flex-row items-center">
344 <Menu
345 accessibilityLabel={`Actions for queued message ${index + 1}`}
346 shouldOpenOnLongPress
347 style={{ flex: 1 }}
348 actions={[
349 ...(workflow?.canPromoteToSteer || workflow?.canSendNow
350 ? [
351 {
352 id: "steer",
353 title: workflow?.canSendNow ? "Send now" : "Steer now",
354 attributes: { disabled: !controls.canSend },
355 image: Platform.OS === "ios" ? "arrow.turn.left.up" : "arrow_upward",
356 },
357 ]
358 : []),
359 {
360 id: "edit",
361 title: "Edit",
362 attributes: { disabled: !controls.canEdit },
363 image: Platform.OS === "ios" ? "pencil" : "edit",
364 },
365 { id: "up", title: "Move up", attributes: { disabled: !controls.canMoveUp } },
366 {
367 id: "down",
368 title: "Move down",
369 attributes: { disabled: !controls.canMoveDown },
370 },
371 {
372 id: "remove",
373 title: "Remove",
374 attributes: { disabled: !controls.canDismiss, destructive: true },
375 },
376 ]}
377 onPressAction={({ nativeEvent }) =>
378 void act(run.id, nativeEvent.event as QueueAction)
379 }
380 >
381 <Pressable
382 accessibilityRole="button"
383 accessibilityLabel={title}
384 accessibilityHint={
385 controls.canEdit
386 ? "Opens this message in the composer for editing"
387 : (editBlockedReason ?? undefined)
388 }
389 disabled={!controls.canEdit}
390 onPress={() => void act(run.id, "edit")}
391 className="min-h-14 flex-row items-center gap-2.5 py-2.5 active:opacity-70"
392 >
393 <QueueAttachmentThumbnails
394 environmentId={target.environmentId}
395 attachments={attachments}
396 />
397 <Text
398 className={
399 controls.isEditing
400 ? "min-w-0 flex-1 text-sm text-foreground-muted"
401 : "min-w-0 flex-1 text-sm text-foreground"
402 }
403 numberOfLines={1}
404 >
405 {context?.guest === undefined ? null : (
406 <Text className="font-t3-medium text-adaptive-fuchsia-600-300">
407 {`${context.guest.name} `}
408 </Text>
409 )}
410 {title}
411 </Text>
412 {controls.isEditing ? (
413 <Text className="shrink-0 text-2xs uppercase tracking-wide text-primary">
414 Editing
415 </Text>
416 ) : null}
417 </Pressable>
418 </Menu>
419 {workflow?.canPromoteToSteer || workflow?.canSendNow ? (
420 // Outside the edit row and full row height, so a near miss never opens the editor.
421 <Pressable
422 accessibilityRole="button"
423 accessibilityLabel={
424 workflow?.canSendNow
425 ? `Send message ${index + 1} now`
426 : `Steer with message ${index + 1} now`
427 }
428 disabled={!controls.canSend}
429 onPress={() => void act(run.id, "steer")}
430 className="shrink-0 justify-center self-stretch pl-4 active:opacity-70 disabled:opacity-40"
431 >
432 <View className="min-h-9 flex-row items-center gap-1.5 rounded-full bg-primary px-4">
433 <SymbolView
434 name={workflow?.canSendNow ? "arrow.up" : "arrow.turn.left.up"}
435 size={13}
436 tintColorClassName="accent-primary-foreground"
437 />
438 <Text className="font-t3-medium text-sm text-primary-foreground">
439 {workflow?.canSendNow ? "Send now" : "Steer"}
440 </Text>
441 </View>
442 </Pressable>
443 ) : null}
444 </View>
445 </QueueRowSwipeable>
446 </Animated.View>
447 </QueueShiftedRow>
448 );
449 })}
450 </ScrollView>
451 );
452
453 if (Platform.OS === "ios") {
454 // Plain formSheets lack stack headers; host one in a nested native stack.
455 return (
456 <GestureHandlerRootView style={{ flex: 1 }}>
457 <View collapsable={false} className="flex-1 bg-sheet">
458 <ScreenStack style={{ flex: 1 }}>
459 <Screen
460 activityState={2}
461 enabled
462 isNativeStack
463 screenId="thread-queue-sheet-native"
464 scrollEdgeEffects={HEADER_SCROLL_EDGE_EFFECTS}
465 style={{ backgroundColor: theme["--color-sheet"], flex: 1 }}
466 >
467 {content}
468 <ScreenStackHeaderConfig
469 backgroundColor="rgba(0,0,0,0)"
470 color={theme["--color-foreground"]}
471 hideBackButton
472 hideShadow={false}
473 title="Queued"
474 titleColor={theme["--color-foreground"]}
475 titleFontSize={18}
476 titleFontWeight="800"
477 translucent
478 />
479 </Screen>
480 </ScreenStack>
481 </View>
482 </GestureHandlerRootView>
483 );
484 }
485
486 return (
487 <GestureHandlerRootView style={{ flex: 1 }}>
488 <View collapsable={false} className="flex-1 bg-sheet">
489 <NativeStackScreenOptions options={{ sheetCornerRadius: 28 }} />
490 <AndroidSheetHeader title="Queued" onBack={() => navigation.goBack()} />
491 <ScreenContent insetHorizontal={layout.usesSplitView}>{content}</ScreenContent>
492 </View>
493 </GestureHandlerRootView>
494 );
495}
496
497function QueueShiftedRow(props: {
498 readonly offset: number;
499 readonly dragging: boolean;
500 readonly lifted: boolean;
501 readonly onLayout: React.ComponentProps<typeof View>["onLayout"];
502 readonly children: React.ReactNode;
503}) {
504 const { dragging, offset } = props;
505 const style = useAnimatedStyle(() => ({
506 transform: [
507 {
508 translateY: dragging
509 ? withTiming(offset, { duration: 160, reduceMotion: ReduceMotion.System })
510 : offset,
511 },
512 ],
513 }));
514 return (
515 <Reanimated.View onLayout={props.onLayout} style={[style, { zIndex: props.lifted ? 1 : 0 }]}>
516 {props.children}
517 </Reanimated.View>
518 );
519}
520
521function QueueRowSwipeable(props: {
522 readonly enabled: boolean;
523 readonly background: string;
524 readonly onRemove: () => void;
525 readonly children: React.ReactNode;
526}) {
527 const swipeableRef = useRef<SwipeableMethods | null>(null);
528 return (
529 <ReanimatedSwipeable
530 ref={swipeableRef}
531 enabled={props.enabled}
532 friction={2}
533 rightThreshold={40}
534 overshootRight={false}
535 // Require a clearly sideways swipe to avoid competing with sheet scroll and drag handles.
536 failOffsetY={[-12, 12]}
537 containerStyle={{ backgroundColor: props.background, flex: 1 }}
538 childrenContainerStyle={{ backgroundColor: props.background }}
539 onSwipeableOpen={(direction) => {
540 if (direction !== "right") return;
541 swipeableRef.current?.close();
542 props.onRemove();
543 }}
544 renderRightActions={() => (
545 <Pressable
546 accessibilityRole="button"
547 accessibilityLabel={REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL}
548 disabled={!props.enabled}
549 onPress={() => {
550 swipeableRef.current?.close();
551 props.onRemove();
552 }}
553 className="items-center justify-center bg-danger active:opacity-70 disabled:opacity-40"
554 style={{ width: REMOVE_ACTION_WIDTH }}
555 >
556 <SymbolView name="trash" size={16} tintColorClassName="accent-danger-foreground" />
557 <Text className="pt-1 text-2xs font-t3-medium text-danger-foreground">Remove</Text>
558 </Pressable>
559 )}
560 >
561 {props.children}
562 </ReanimatedSwipeable>
563 );
564}
565
566function QueueAttachmentThumbnails(props: {
567 readonly environmentId: EnvironmentId;
568 readonly attachments: ReadonlyArray<ChatAttachment>;
569}) {
570 const images = props.attachments.filter((attachment) => attachment.mimeType.startsWith("image/"));
571 const shown = images.slice(0, THUMBNAIL_LIMIT);
572 const overflow = props.attachments.length - shown.length;
573 if (props.attachments.length === 0) return null;
574 return (
575 <View className="shrink-0 flex-row items-center gap-1">
576 {shown.map((attachment) => (
577 <QueueAttachmentThumbnail
578 key={attachment.id}
579 environmentId={props.environmentId}
580 attachment={attachment}
581 />
582 ))}
583 {overflow > 0 ? (
584 <View className="h-6 min-w-6 items-center justify-center rounded bg-subtle px-1">
585 <Text className="text-2xs tabular-nums text-foreground-muted">
586 {shown.length === 0 ? `${overflow}` : `+${overflow}`}
587 </Text>
588 </View>
589 ) : null}
590 </View>
591 );
592}
593
594function QueueAttachmentThumbnail(props: {
595 readonly environmentId: EnvironmentId;
596 readonly attachment: ChatAttachment;
597}) {
598 const resource = {
599 _tag: "attachment",
600 attachmentId: props.attachment.id,
601 fileName: props.attachment.name,
602 mimeType: props.attachment.mimeType,
603 disposition: "inline",
604 } as const;
605 const url = useAssetUrl(props.environmentId, resource);
606 if (url === null) {
607 return <View className="h-6 w-6 rounded bg-subtle" />;
608 }
609 return (
610 <Image
611 source={assetImageSource(props.environmentId, resource, url)}
612 cachePolicy="memory-disk"
613 contentFit="cover"
614 style={{ width: 24, height: 24, borderRadius: 4 }}
615 accessibilityIgnoresInvertColors
616 />
617 );
618}
619
620function QueueDragHandle(props: {
621 disabled: boolean;
622 title: string;
623 canMoveUp: boolean;
624 canMoveDown: boolean;
625 onStep: (action: "up" | "down") => void;
626 onStart: () => void;
627 onMove: (y: number) => void;
628 onEnd: (y: number, success: boolean) => void;
629}) {
630 const onStart = useEffectEvent(() => props.onStart());
631 const onMove = useEffectEvent((y: number) => props.onMove(y));
632 const onEnd = useEffectEvent((y: number, success: boolean) => props.onEnd(y, success));
633 // oxlint-disable-next-line react/capitalized-calls -- Gesture.Pan is a gesture factory, not a React component.
634 const gesture = Gesture.Pan()
635 .enabled(!props.disabled)
636 .minDistance(0)
637 .shouldCancelWhenOutside(false)
638 .runOnJS(true)
639 .onStart(() => onStart())
640 .onUpdate((event) => onMove(event.translationY))
641 .onFinalize((event, success) => onEnd(event.translationY, success));
642 return (
643 <GestureDetector gesture={gesture}>
644 <View
645 collapsable={false}
646 accessible
647 accessibilityRole="adjustable"
648 accessibilityLabel={`Reorder ${props.title}`}
649 accessibilityState={{ disabled: props.disabled }}
650 accessibilityActions={[
651 ...(props.canMoveUp ? [{ name: "decrement", label: "Move up" }] : []),
652 ...(props.canMoveDown ? [{ name: "increment", label: "Move down" }] : []),
653 ]}
654 onAccessibilityAction={({ nativeEvent }) => {
655 if (props.disabled) return;
656 if (nativeEvent.actionName === "decrement" && props.canMoveUp) props.onStep("up");
657 if (nativeEvent.actionName === "increment" && props.canMoveDown) props.onStep("down");
658 }}
659 className="h-12 w-8 items-center justify-center"
660 >
661 <SymbolView
662 name="line.3.horizontal"
663 size={16}
664 tintColorClassName="accent-foreground-muted"
665 />
666 </View>
667 </GestureDetector>
668 );
669}