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 { Platform, Pressable, StyleSheet, View, type AccessibilityActionEvent } from "react-native"; |
| 4 | import { Gesture, GestureDetector } from "react-native-gesture-handler"; |
| 5 | import { runOnJS } from "react-native-reanimated"; |
| 6 | import { cn } from "../../lib/cn"; |
| 7 | |
| 8 | const ACCESSIBILITY_RESIZE_STEP = 24; |
| 9 | |
| 10 | interface WorkspacePaneDividerProps { |
| 11 | readonly accessibilityLabel: string; |
| 12 | readonly currentWidth: number; |
| 13 | readonly resizeDirection: 1 | -1; |
| 14 | readonly onResizeStart?: () => void; |
| 15 | readonly onResizeBy: (delta: number) => void; |
| 16 | readonly onResizeEnd?: () => void; |
| 17 | } |
| 18 | |
| 19 | export function WorkspacePaneDivider(props: WorkspacePaneDividerProps) { |
| 20 | const gt = useGT(); |
| 21 | const [dragging, setDragging] = useState(false); |
| 22 | const handleResizeStart = useEffectEvent(() => { |
| 23 | setDragging(true); |
| 24 | props.onResizeStart?.(); |
| 25 | }); |
| 26 | const handleResize = useEffectEvent((translationX: number) => { |
| 27 | props.onResizeBy(translationX * props.resizeDirection); |
| 28 | }); |
| 29 | const handleResizeEnd = useEffectEvent(() => { |
| 30 | setDragging(false); |
| 31 | props.onResizeEnd?.(); |
| 32 | }); |
| 33 | const [resizeGesture] = useState(() => |
| 34 | Gesture.Pan() |
| 35 | .activeOffsetX([-4, 4]) |
| 36 | .failOffsetY([-24, 24]) |
| 37 | .onStart(() => { |
| 38 | runOnJS(handleResizeStart)(); |
| 39 | }) |
| 40 | .onUpdate((event) => { |
| 41 | runOnJS(handleResize)(event.translationX); |
| 42 | }) |
| 43 | .onFinalize(() => { |
| 44 | runOnJS(handleResizeEnd)(); |
| 45 | }), |
| 46 | ); |
| 47 | |
| 48 | const handleAccessibilityAction = (event: AccessibilityActionEvent) => { |
| 49 | props.onResizeStart?.(); |
| 50 | if (event.nativeEvent.actionName === "increment") { |
| 51 | props.onResizeBy(ACCESSIBILITY_RESIZE_STEP); |
| 52 | } else if (event.nativeEvent.actionName === "decrement") { |
| 53 | props.onResizeBy(-ACCESSIBILITY_RESIZE_STEP); |
| 54 | } |
| 55 | props.onResizeEnd?.(); |
| 56 | }; |
| 57 | |
| 58 | return ( |
| 59 | <GestureDetector gesture={resizeGesture}> |
| 60 | <Pressable |
| 61 | className="relative z-[100] -mx-[22px] w-[44px] self-stretch justify-center" |
| 62 | accessibilityActions={[ |
| 63 | { name: "increment", label: gt("Make pane wider") }, |
| 64 | { name: "decrement", label: gt("Make pane narrower") }, |
| 65 | ]} |
| 66 | accessibilityLabel={props.accessibilityLabel} |
| 67 | accessibilityRole="adjustable" |
| 68 | accessibilityValue={{ |
| 69 | now: Math.round(props.currentWidth), |
| 70 | text: gt("{width} points wide", { width: Math.round(props.currentWidth) }), |
| 71 | }} |
| 72 | onAccessibilityAction={handleAccessibilityAction} |
| 73 | > |
| 74 | <View |
| 75 | className={cn( |
| 76 | "h-full self-center bg-border opacity-70", |
| 77 | dragging ? "w-0.5 bg-primary opacity-100" : "w-px", |
| 78 | Platform.OS === "android" && !dragging && "opacity-0", |
| 79 | )} |
| 80 | style={[styles.line, dragging && styles.activeLine]} |
| 81 | /> |
| 82 | </Pressable> |
| 83 | </GestureDetector> |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | const styles = StyleSheet.create({ |
| 88 | line: { |
| 89 | alignSelf: "center", |
| 90 | height: "100%", |
| 91 | width: StyleSheet.hairlineWidth, |
| 92 | }, |
| 93 | activeLine: { |
| 94 | width: 2, |
| 95 | }, |
| 96 | }); |