The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useGT } from "gt-react-native"; |
| 2 | import { useEffectEvent, useState } from "react"; |
| 3 | import { View } from "react-native"; |
| 4 | import { Gesture, GestureDetector } from "react-native-gesture-handler"; |
| 5 | |
| 6 | import { SymbolView } from "../../../components/ui/AppSymbol"; |
| 7 | |
| 8 | export function SettingsDragHandle(props: { |
| 9 | readonly title: string; |
| 10 | readonly canMoveUp: boolean; |
| 11 | readonly canMoveDown: boolean; |
| 12 | readonly onStart: () => void; |
| 13 | readonly onMove: (translation: number) => void; |
| 14 | readonly onEnd: (translation: number, cancelled: boolean) => void; |
| 15 | readonly onStep: (direction: "up" | "down") => void; |
| 16 | }) { |
| 17 | const gt = useGT(); |
| 18 | const onStart = useEffectEvent(() => props.onStart()); |
| 19 | const onMove = useEffectEvent((translation: number) => props.onMove(translation)); |
| 20 | const onEnd = useEffectEvent((translation: number, cancelled: boolean) => |
| 21 | props.onEnd(translation, cancelled), |
| 22 | ); |
| 23 | // The worklets plugin copies the values these callbacks close over when the gesture is built, |
| 24 | // so the drop reads its translation from the final event rather than a tracked variable. |
| 25 | const [gesture] = useState(() => |
| 26 | Gesture.Pan() |
| 27 | .minDistance(0) |
| 28 | .shouldCancelWhenOutside(false) |
| 29 | .runOnJS(true) |
| 30 | .onStart(() => onStart()) |
| 31 | .onUpdate((event) => onMove(event.translationY)) |
| 32 | .onFinalize((event, success) => onEnd(event.translationY, !success)), |
| 33 | ); |
| 34 | return ( |
| 35 | <GestureDetector gesture={gesture}> |
| 36 | <View |
| 37 | collapsable={false} |
| 38 | accessible |
| 39 | accessibilityRole="adjustable" |
| 40 | accessibilityLabel={gt("Reorder {item}", { item: props.title })} |
| 41 | accessibilityActions={[ |
| 42 | ...(props.canMoveUp ? [{ name: "decrement", label: gt("Move up") }] : []), |
| 43 | ...(props.canMoveDown ? [{ name: "increment", label: gt("Move down") }] : []), |
| 44 | ]} |
| 45 | onAccessibilityAction={({ nativeEvent }) => { |
| 46 | if (nativeEvent.actionName === "decrement" && props.canMoveUp) props.onStep("up"); |
| 47 | if (nativeEvent.actionName === "increment" && props.canMoveDown) props.onStep("down"); |
| 48 | }} |
| 49 | style={{ width: 48, alignSelf: "stretch", alignItems: "center", justifyContent: "center" }} |
| 50 | > |
| 51 | <SymbolView |
| 52 | name="line.3.horizontal" |
| 53 | size={20} |
| 54 | tintColorClassName="accent-foreground-muted" |
| 55 | /> |
| 56 | </View> |
| 57 | </GestureDetector> |
| 58 | ); |
| 59 | } |