@devries-cameron20 / t3code Mirror · read-only / commits / fe0e8d4ee1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 14:30 UTC

fix(mobile): dragging a microphone or environment route now saves its new place (#26096)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 14:46 UTC fe0e8d4ee12e4759ef1cc49155885afc1f5fce3c
5 files changed +132 -67
apps/mobile/src/features/settings/SettingsMicrophoneRouteScreen.tsx
+47 -53
@@ -1,14 +1,13 @@
1 -import { Button } from "../../components/ui/Button";
1 import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
2 import { useAtomSet, useAtomValue } from "@effect/atom-react";
3 import { AsyncResult } from "effect/reactivity";
4 import { getRecordingPermissionsAsync, requestRecordingPermissionsAsync } from "expo-audio";
5 import { useState } from "react";
7 -import { Linking, Pressable, View } from "react-native";
6 +import { Linking, useWindowDimensions, View } from "react-native";
7 import Reanimated, { ReduceMotion, useAnimatedStyle, withTiming } from "react-native-reanimated";
8 import { useSafeAreaInsets } from "react-native-safe-area-context";
9
11 -import { type AppSymbolName, SymbolView } from "../../components/ui/AppSymbol";
10 +import { type AppSymbolName } from "../../components/ui/AppSymbol";
11 import { AppText as Text } from "../../components/ui/AppText";
12 import { cn } from "../../lib/cn";
13 import { makePermissionStatusAtom } from "../../lib/permissionStatusAtom";
@@ -21,12 +20,11 @@ import {
20 } from "../../lib/microphonePriority";
21 import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
22 import { ListRowLayout } from "../../components/ui/ListRowLayout";
23 +import { ThreadSwipeable } from "../home/thread-swipe-actions";
24 import { SettingsActionRow } from "./components/SettingsActionRow";
25 import { SettingsDragHandle } from "./components/SettingsDragHandle";
26 import { SettingsSection } from "./components/SettingsSection";
27
28 -const REMOVE_SIZE = 20;
29 -
28 type MicrophonePermission = "checking" | "granted" | "ask" | "denied";
29
30 function toMicrophonePermission(response: {
@@ -98,9 +96,7 @@ export function SettingsMicrophoneRouteScreen() {
96 const entries = microphoneOrder(
97 AsyncResult.isSuccess(preferencesResult) ? preferencesResult.value.microphones : undefined,
98 );
101 - const hasDevices = entries.some(isMicrophoneDevice);
99 const { permission, request: requestPermission } = useMicrophonePermission();
103 - const [editing, setEditing] = useState(false);
100 const [drag, setDrag] = useState<{ readonly key: string; readonly translation: number } | null>(
101 null,
102 );
@@ -166,18 +162,7 @@ export function SettingsMicrophoneRouteScreen() {
162 </Text>
163 </>
164 ) : null}
169 - <SettingsSection
170 - title="Preferred order"
171 - trailing={
172 - hasDevices ? (
173 - <Button
174 - label={editing ? "Done" : "Edit"}
175 - tone="text"
176 - onPress={() => setEditing((value) => !value)}
177 - />
178 - ) : undefined
179 - }
180 - >
165 + <SettingsSection title="Preferred order">
166 {entries.map((entry, index) => {
167 const key = microphoneEntryKey(entry);
168 const shift =
@@ -195,7 +180,6 @@ export function SettingsMicrophoneRouteScreen() {
180 position={index + 1}
181 count={entries.length}
182 reorderable={ready}
198 - editing={editing && hasDevices}
183 offset={index === dragFrom ? (drag?.translation ?? 0) : shift}
184 lifted={index === dragFrom}
185 onHeight={setRowHeight}
@@ -215,7 +199,7 @@ export function SettingsMicrophoneRouteScreen() {
199 <Text className="px-2 text-sm text-foreground-muted">
200 Voice input records from the first connected microphone in this list. Wired and Bluetooth
201 devices are added by name after you use voice input with them connected; until then, the
218 - Other row ranks them.
202 + Other row ranks them. Swipe a device left to forget it.
203 </Text>
204 </ScrollView>
205 </View>
@@ -227,7 +211,6 @@ function MicrophoneRow(props: {
211 readonly position: number;
212 readonly count: number;
213 readonly reorderable: boolean;
230 - readonly editing: boolean;
214 readonly offset: number;
215 readonly lifted: boolean;
216 readonly onHeight: (height: number) => void;
@@ -237,9 +220,10 @@ function MicrophoneRow(props: {
220 readonly onStep: (direction: "up" | "down") => void;
221 readonly onForget: (() => void) | undefined;
222 }) {
240 - const { lifted, offset, entry } = props;
223 + const { lifted, offset, entry, onForget } = props;
224 const kind = KINDS[entry.kind];
225 const title = isMicrophoneDevice(entry) ? entry.name : kind.row;
226 + const { width: windowWidth } = useWindowDimensions();
227 const style = useAnimatedStyle(() => ({
228 transform: [
229 {
@@ -250,39 +234,16 @@ function MicrophoneRow(props: {
234 ],
235 zIndex: lifted ? 1 : 0,
236 }));
253 - return (
254 - <Reanimated.View
255 - style={style}
256 - onLayout={(event) => props.onHeight(event.nativeEvent.layout.height)}
257 - className={cn(
258 - "flex-row items-center",
259 - props.position > 1 && !lifted && "border-t border-border-subtle",
260 - lifted && "bg-grouped-card shadow-md",
261 - )}
262 - >
263 - {props.editing && props.onForget ? (
264 - <Pressable
265 - accessibilityRole="button"
266 - accessibilityLabel={`Forget ${title}`}
267 - hitSlop={8}
268 - onPress={props.onForget}
269 - className="pl-4 active:opacity-70"
270 - >
271 - <SymbolView
272 - name="xmark.circle.fill"
273 - size={REMOVE_SIZE}
274 - tintColorClassName="accent-danger-foreground"
275 - type="monochrome"
276 - />
277 - </Pressable>
278 - ) : props.editing ? (
279 - <View className="pl-4">
280 - <View style={{ width: REMOVE_SIZE }} />
281 - </View>
282 - ) : null}
237 + const row = (
238 + // Opaque so the swipe actions stay hidden until the row slides over them.
239 + <View className="flex-row items-center bg-grouped-card">
240 <View
241 accessible
242 accessibilityLabel={`${title}, ${kind.label}, ${props.position} of ${props.count}`}
243 + accessibilityActions={onForget ? [{ name: "forget", label: "Forget" }] : undefined}
244 + onAccessibilityAction={({ nativeEvent }) => {
245 + if (nativeEvent.actionName === "forget") onForget?.();
246 + }}
247 className="min-w-0 flex-1"
248 >
249 <ListRowLayout
@@ -302,6 +263,39 @@ function MicrophoneRow(props: {
263 onStep={props.onStep}
264 />
265 ) : null}
266 + </View>
267 + );
268 + return (
269 + <Reanimated.View
270 + style={style}
271 + onLayout={(event) => props.onHeight(event.nativeEvent.layout.height)}
272 + className={cn(
273 + props.position > 1 && !lifted && "border-t border-border-subtle",
274 + lifted && "bg-grouped-card shadow-md",
275 + )}
276 + >
277 + {onForget ? (
278 + <ThreadSwipeable
279 + backgroundColor="transparent"
280 + fullSwipeAction="primary"
281 + fullSwipeWidth={windowWidth - 40}
282 + onDelete={onForget}
283 + primaryAction={{
284 + accessibilityLabel: `Forget ${title}`,
285 + destructive: true,
286 + icon: "trash",
287 + label: "Forget",
288 + onPress: onForget,
289 + }}
290 + secondaryAction={null}
291 + threadKey={`microphone:${microphoneEntryKey(entry)}`}
292 + threadTitle={title}
293 + >
294 + {() => row}
295 + </ThreadSwipeable>
296 + ) : (
297 + row
298 + )}
299 </Reanimated.View>
300 );
301 }
apps/mobile/src/features/settings/components/SettingsDragHandle.test.tsx new
+75
@@ -0,0 +1,75 @@
1 +import type { ReactNode } from "react";
2 +import { act } from "react";
3 +import { createRoot } from "react-dom/client";
4 +import { describe, expect, it, vi } from "vite-plus/test";
5 +
6 +type PanEvent = { readonly translationY: number };
7 +type PanHandlers = {
8 + onStart?: () => void;
9 + onUpdate?: (event: PanEvent) => void;
10 + onFinalize?: (event: PanEvent, success: boolean) => void;
11 +};
12 +
13 +const pans = vi.hoisted(() => [] as PanHandlers[]);
14 +
15 +vi.mock("react-native", () => ({
16 + View: ({ children }: { children?: ReactNode }) => <div>{children}</div>,
17 +}));
18 +vi.mock("react-native-gesture-handler", () => ({
19 + GestureDetector: ({ children }: { children?: ReactNode }) => children,
20 + Gesture: {
21 + Pan: () => {
22 + const handlers: PanHandlers = {};
23 + pans.push(handlers);
24 + const pan = {
25 + minDistance: () => pan,
26 + shouldCancelWhenOutside: () => pan,
27 + runOnJS: () => pan,
28 + onStart: (callback: PanHandlers["onStart"]) => ((handlers.onStart = callback), pan),
29 + onUpdate: (callback: PanHandlers["onUpdate"]) => ((handlers.onUpdate = callback), pan),
30 + onFinalize: (callback: PanHandlers["onFinalize"]) => (
31 + (handlers.onFinalize = callback),
32 + pan
33 + ),
34 + };
35 + return pan;
36 + },
37 + },
38 +}));
39 +vi.mock("../../../components/ui/AppSymbol", () => ({ SymbolView: () => null }));
40 +
41 +import { SettingsDragHandle } from "./SettingsDragHandle";
42 +
43 +describe("SettingsDragHandle", () => {
44 + // The worklets Babel plugin copies values a gesture callback closes over when the gesture is
45 + // built, so a drop must not read a translation tracked in a local variable.
46 + it("reports the released translation when the pan ends", () => {
47 + pans.length = 0;
48 + const onEnd = vi.fn();
49 + const root = createRoot(document.createElement("div"));
50 + act(() =>
51 + root.render(
52 + <SettingsDragHandle
53 + title="Built-in microphone"
54 + canMoveUp
55 + canMoveDown
56 + onStart={() => {}}
57 + onMove={() => {}}
58 + onEnd={onEnd}
59 + onStep={() => {}}
60 + />,
61 + ),
62 + );
63 + const pan = pans.at(-1)!;
64 +
65 + act(() => {
66 + pan.onStart?.();
67 + pan.onUpdate?.({ translationY: 64 });
68 + pan.onUpdate?.({ translationY: 130 });
69 + pan.onFinalize?.({ translationY: 130 }, true);
70 + });
71 +
72 + expect(onEnd).toHaveBeenCalledWith(130, false);
73 + act(() => root.unmount());
74 + });
75 +});
apps/mobile/src/features/settings/components/SettingsDragHandle.tsx
+8 -13
@@ -18,22 +18,17 @@ export function SettingsDragHandle(props: {
18 const onEnd = useEffectEvent((translation: number, cancelled: boolean) =>
19 props.onEnd(translation, cancelled),
20 );
21 - const [gesture] = useState(() => {
22 - let translation = 0;
23 - return Gesture.Pan()
21 + // The worklets plugin copies the values these callbacks close over when the gesture is built,
22 + // so the drop reads its translation from the final event rather than a tracked variable.
23 + const [gesture] = useState(() =>
24 + Gesture.Pan()
25 .minDistance(0)
26 .shouldCancelWhenOutside(false)
27 .runOnJS(true)
27 - .onStart(() => {
28 - translation = 0;
29 - onStart();
30 - })
31 - .onUpdate((event) => {
32 - translation = event.translationY;
33 - onMove(event.translationY);
34 - })
35 - .onFinalize((_, success) => onEnd(translation, !success));
36 - });
28 + .onStart(() => onStart())
29 + .onUpdate((event) => onMove(event.translationY))
30 + .onFinalize((event, success) => onEnd(event.translationY, !success)),
31 + );
32 return (
33 <GestureDetector gesture={gesture}>
34 <View
apps/mobile/vite.config.ts
+1
@@ -17,6 +17,7 @@ const reactTests = [
17 "src/features/pull-requests/guide/useReviewGuide.test.tsx",
18 "src/features/settings/SettingsServerControlsRouteScreen.test.tsx",
19 "src/features/settings/components/BranchNamingSettings.test.tsx",
20 + "src/features/settings/components/SettingsDragHandle.test.tsx",
21 "src/features/threads/ThreadMarkdownImage.test.tsx",
22 "src/features/threads/UsageLimitRecoveryCard.test.tsx",
23 "src/features/threads/NewTaskDraftRouteScreen.test.tsx",
docs/user/composer.md
+1 -1
@@ -190,7 +190,7 @@ The list mixes kinds (built-in, other wired, other Bluetooth, CarPlay) with wire
190 Bluetooth devices you have dictated with, listed by name. Drag to rank them together:
191 for example, put **Other Bluetooth** above your AirPods so a new headset is preferred
192 while the AirPods microphone stays low. By default, CarPlay comes after the built-in
193 -microphone.
193 +microphone. Swipe a device left to forget it.
194
195 Transcription runs on your device. T3 Code deletes the temporary audio after
196 transcription or cancellation; only the message text is sent when you submit.