@devries-cameron20 / t3code Mirror · read-only / commits / 760cdecd05
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, 23:15 UTC

fix(mobile): preserve Home row content across recycling (#14004)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

AKolenda committed Oct 19, 2026 at 23:06 UTC 760cdecd05d52d542d328f97b3ebbe86c24508b5
3 files changed +125 -111
apps/mobile/src/features/home/HomeScreen.tsx
+1 -1
@@ -137,7 +137,7 @@ interface HomeScreenProps {
137 }
138
139 const ESTIMATED_THREAD_LIST_V2_ROW_HEIGHT = 72;
140 -// Rows away from the viewport are cheap dormant frames (see
140 +// Rows away from the viewport skip their swipe actions (see
141 // swipe-row-activation), so render further ahead: a fast fling then reaches
142 // rows that are already built instead of rows still being rebuilt.
143 const THREAD_LIST_V2_DRAW_DISTANCE = 1_000;
apps/mobile/src/features/home/swipe-row-activation.ts
+4 -7
@@ -1,16 +1,13 @@
1 import { createContext, use, useSyncExternalStore } from "react";
2
3 /**
4 - * Full swipe rows (pan gesture, animated actions, hidden action buttons) only
5 - * exist around the viewport. Every other Home row renders a dormant frame that
6 - * paints the same content with a fraction of the native views, so a row the
7 - * list rebuilds while scrolling is cheap.
4 + * Only rows around the viewport enable swipe gestures and render actions.
5 + * Dormant rows keep the same child views so waking them preserves touches.
6 */
7 export function createSwipeRowActivation() {
8 let activeKeys = new Set<string>();
11 - // Swapping a row's frame remounts it, which would cancel a press or long
12 - // press in progress, so changes wait until every finger that started on the
13 - // list has lifted.
9 + // Turning a row's swipe gesture off ends a swipe in progress, so changes
10 + // wait until every finger that started on the list has lifted.
11 const listTouches = new Set<string>();
12 let pendingKeys: ReadonlyArray<string> | null = null;
13 const listeners = new Set<() => void>();
apps/mobile/src/features/home/thread-swipe-actions.tsx
+120 -103
@@ -8,6 +8,7 @@ import {
8 useCallback,
9 useEffect,
10 useLayoutEffect,
11 + useMemo,
12 useRef,
13 useState,
14 type ComponentProps,
@@ -249,31 +250,8 @@ interface ThreadSwipeableProps {
250 readonly threadTitle: string;
251 }
252
252 -const closeDormant = () => {};
253 -
253 export function ThreadSwipeable(props: ThreadSwipeableProps) {
255 - if (props.dormant) {
256 - return (
257 - <View
258 - style={[
259 - { overflow: "hidden", backgroundColor: props.backgroundColor },
260 - props.containerStyle,
261 - ]}
262 - >
263 - <View style={{ backgroundColor: props.backgroundColor }}>
264 - {props.children(closeDormant)}
265 - </View>
266 - </View>
267 - );
268 - }
269 - // Recycled content gets fresh native and animation state. Late callbacks
270 - // from the previous row retain its action, never the replacement's action.
271 - return <ThreadSwipeableRow key={props.resetKey} {...props} />;
272 -}
273 -
274 -function ThreadSwipeableRow(props: ThreadSwipeableProps) {
254 const swipeableRef = useRef<SwipeableMethods | null>(null);
276 - const fullSwipeArmedRef = useRef(false);
255 const hasSecondaryAction = props.secondaryAction !== null;
256 const actionsWidth = swipeActionsWidth(hasSecondaryAction);
257 const fullSwipeThreshold = Math.max(actionsWidth + 44, props.fullSwipeWidth * 0.58);
@@ -283,8 +261,14 @@ function ThreadSwipeableRow(props: ThreadSwipeableProps) {
261 const gateEnabled = use(SwipeableScrollGateContext);
262 const mountedRef = useRef(true);
263 const dismissalRef = useRef<{ finished: Promise<void>; restore: () => void } | null>(null);
286 - const pendingDismissRef = useRef<(() => void) | null>(null);
264 + const pendingDismissRef = useRef<{ id: number; resolve: () => void } | null>(null);
265 + const dismissalIdRef = useRef(0);
266 const activeTranslationRef = useRef<SharedValue<number> | null>(null);
267 + const content = useMemo(
268 + () => ({ resetKey: props.resetKey, threadKey: props.threadKey }),
269 + [props.resetKey, props.threadKey],
270 + );
271 + const contentRef = useRef(content);
272 const [isDismissing, setIsDismissing] = useState(false);
273 const dismissing = useSharedValue(false);
274 const rowHeight = useSharedValue(0);
@@ -293,23 +277,31 @@ function ThreadSwipeableRow(props: ThreadSwipeableProps) {
277 const fallbackTranslation = useSharedValue(0);
278 const actionOpacity = useSharedValue(1);
279 const primaryAction = props.primaryAction;
280 + const onDelete = props.onDelete;
281 const onSwipeableClose = props.onSwipeableClose;
282
283 const restoreRow = useCallback(() => {
284 if (!mountedRef.current) return;
285 dismissalRef.current = null;
301 - swipeableRef.current?.reset();
302 - fallbackTranslation.set(0);
303 - collapse.set(0);
304 - actionOpacity.set(1);
305 - dismissing.set(false);
286 + // RN-to-UI jobs run in order, so this also resets a queued dismissal.
287 + runOnUI((methods: SwipeableMethods | null) => {
288 + "worklet";
289 + methods?.reset();
290 + // RNGH reset() leaves tap-to-close enabled; close() clears it.
291 + methods?.close();
292 + fallbackTranslation.set(0);
293 + collapse.set(0);
294 + actionOpacity.set(1);
295 + dismissing.set(false);
296 + })(swipeableRef.current);
297 setIsDismissing(false);
298 }, [actionOpacity, collapse, dismissing, fallbackTranslation]);
299
309 - const finishDismiss = useCallback(() => {
310 - const finish = pendingDismissRef.current;
300 + const finishDismiss = useCallback((id?: number) => {
301 + const pending = pendingDismissRef.current;
302 + if (!pending || (id !== undefined && pending.id !== id)) return;
303 pendingDismissRef.current = null;
312 - finish?.();
304 + pending.resolve();
305 }, []);
306
307 useLayoutEffect(() => {
@@ -324,8 +316,22 @@ function ThreadSwipeableRow(props: ThreadSwipeableProps) {
316 };
317 }, [actionOpacity, collapse, fallbackTranslation, finishDismiss]);
318
319 + // Reset recycled rows in place so their child views stay mounted.
320 + useLayoutEffect(() => {
321 + if (contentRef.current === content) return;
322 + contentRef.current = content;
323 + finishDismiss();
324 + restoreRow();
325 + }, [content, finishDismiss, restoreRow]);
326 +
327 + useLayoutEffect(() => {
328 + if (props.dormant && activeTranslationRef.current && dismissalRef.current === null) {
329 + restoreRow();
330 + }
331 + }, [props.dormant, restoreRow]);
332 +
333 const dismiss = useCallback(
328 - (translation: SharedValue<number>) => {
334 + (translation: SharedValue<number>, id: number) => {
335 "worklet";
336 if (dismissing.value) return;
337 dismissing.set(true);
@@ -340,7 +346,7 @@ function ThreadSwipeableRow(props: ThreadSwipeableProps) {
346 if (!finished) return;
347 collapse.set(
348 withTiming(1, { ...timing, duration: 180 }, (collapsed) => {
343 - if (collapsed) runOnJS(finishDismiss)();
349 + if (collapsed) runOnJS(finishDismiss)(id);
350 }),
351 );
352 }),
@@ -350,49 +356,75 @@ function ThreadSwipeableRow(props: ThreadSwipeableProps) {
356 );
357 useLayoutEffect(
358 () =>
353 - registerThreadDismissal(props.threadKey, () => {
354 - if (dismissalRef.current) return dismissalRef.current;
355 - const finished = new Promise<void>((resolve) => {
356 - pendingDismissRef.current = resolve;
357 - });
358 - fullSwipeArmedRef.current = false;
359 - setIsDismissing(true);
360 - if (swipeableRef.current) onSwipeableClose?.(swipeableRef.current);
361 - runOnUI(dismiss)(activeTranslationRef.current ?? fallbackTranslation);
362 - dismissalRef.current = { finished, restore: restoreRow };
363 - return dismissalRef.current;
364 - }),
365 - [dismiss, fallbackTranslation, onSwipeableClose, props.threadKey, restoreRow],
359 + props.dormant
360 + ? undefined
361 + : registerThreadDismissal(props.threadKey, () => {
362 + if (dismissalRef.current) return dismissalRef.current;
363 + const id = ++dismissalIdRef.current;
364 + const finished = new Promise<void>((resolve) => {
365 + pendingDismissRef.current = { id, resolve };
366 + });
367 + setIsDismissing(true);
368 + if (swipeableRef.current) onSwipeableClose?.(swipeableRef.current);
369 + runOnUI(dismiss)(activeTranslationRef.current ?? fallbackTranslation, id);
370 + const dismissal = {
371 + finished,
372 + restore: () => {
373 + if (dismissalRef.current === dismissal) restoreRow();
374 + },
375 + };
376 + dismissalRef.current = dismissal;
377 + return dismissal;
378 + }),
379 + [dismiss, fallbackTranslation, onSwipeableClose, props.dormant, props.threadKey, restoreRow],
380 );
381 const dismissStyle = useAnimatedStyle(() => ({
368 - height: dismissing.value ? rowHeight.value * (1 - collapse.value) : undefined,
382 + // Native prop updates omit undefined, leaving a collapsed height in place.
383 + height: dismissing.value ? rowHeight.value * (1 - collapse.value) : "auto",
384 pointerEvents: dismissing.value ? "none" : "auto",
385 overflow: "hidden",
386 transform: [{ translateX: fallbackTranslation.value }],
387 }));
388 const actionStyle = useAnimatedStyle(() => ({ opacity: actionOpacity.value, height: "100%" }));
389 const commitPrimaryAction = useCallback(() => {
390 + if (!mountedRef.current || contentRef.current !== content) return;
391 primaryAction.onPress();
392 if (!pendingDismissRef.current) swipeableRef.current?.close();
377 - }, [primaryAction]);
393 + }, [content, primaryAction]);
394 + // RNGH lifecycle events call the latest handler, so commit from this release.
395 + const commitFullSwipe = useCallback(() => {
396 + if (!mountedRef.current || contentRef.current !== content) return;
397 + if (fullSwipeAction === "primary") commitPrimaryAction();
398 + else {
399 + swipeableRef.current?.close();
400 + onDelete();
401 + }
402 + }, [commitPrimaryAction, content, fullSwipeAction, onDelete]);
403 const handleRelease = useCallback(
404 (translation: SharedValue<number>) => {
405 "worklet";
406 if (dismissing.value) return true;
382 - if (fullSwipeAction === "primary" && -translation.value >= fullSwipeThreshold) {
383 - runOnJS(commitPrimaryAction)();
407 + if (-translation.value >= fullSwipeThreshold) {
408 + runOnJS(commitFullSwipe)();
409 return true;
410 }
411 return false;
412 },
388 - [commitPrimaryAction, dismissing, fullSwipeAction, fullSwipeThreshold],
413 + [commitFullSwipe, dismissing, fullSwipeThreshold],
414 + );
415 + const handleFullSwipeArmedChange = useCallback(
416 + (armed: boolean) => {
417 + if (mountedRef.current && contentRef.current === content && armed) {
418 + void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
419 + }
420 + },
421 + [content],
422 );
390 - const handleFullSwipeArmedChange = useCallback((armed: boolean) => {
391 - if (armed && !fullSwipeArmedRef.current) {
392 - void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
423 + const handleWillOpen = () => {
424 + if (!props.dormant && !dismissalRef.current && swipeableRef.current) {
425 + props.onSwipeableWillOpen?.(swipeableRef.current);
426 }
394 - fullSwipeArmedRef.current = armed;
395 - }, []);
427 + };
428
429 return (
430 <Animated.View style={dismissStyle}>
@@ -408,7 +440,7 @@ function ThreadSwipeableRow(props: ThreadSwipeableProps) {
440 childrenContainerStyle={{ backgroundColor: props.backgroundColor }}
441 containerStyle={[{ backgroundColor: props.backgroundColor }, props.containerStyle]}
442 dragOffsetFromRight={-8}
411 - enabled={!isDismissing && props.enabled !== false && gateEnabled}
443 + enabled={!props.dormant && !isDismissing && props.enabled !== false && gateEnabled}
444 enableTrackpadTwoFingerGesture={props.enableTrackpadSwipe ?? true}
445 // Fail the swipe once the pan is vertically dominant (patched-in RNGH
446 // prop) — otherwise trackpad scrolls with ~8px of horizontal drift
@@ -417,59 +449,44 @@ function ThreadSwipeableRow(props: ThreadSwipeableProps) {
449 failOffsetY={[-10, 10]}
450 friction={1}
451 onSwipeableClose={() => {
420 - fullSwipeArmedRef.current = false;
452 if (swipeableRef.current) {
453 props.onSwipeableClose?.(swipeableRef.current);
454 }
455 }}
456 onSwipeableRelease={handleRelease}
426 - onSwipeableOpenStartDrag={() => {
427 - if (swipeableRef.current) {
428 - props.onSwipeableWillOpen?.(swipeableRef.current);
429 - }
430 - }}
431 - onSwipeableWillOpen={() => {
432 - const methods = swipeableRef.current;
433 - if (!methods) {
434 - return;
435 - }
436 -
437 - props.onSwipeableWillOpen?.(methods);
438 - if (fullSwipeArmedRef.current && fullSwipeAction !== "primary") {
439 - fullSwipeArmedRef.current = false;
440 - methods.close();
441 - props.onDelete();
442 - }
443 - }}
457 + onSwipeableOpenStartDrag={handleWillOpen}
458 + onSwipeableWillOpen={handleWillOpen}
459 overshootFriction={1}
460 overshootRight
446 - renderRightActions={(_progress, translation, methods) => (
447 - <Animated.View
448 - ref={() => {
449 - activeTranslationRef.current = translation;
450 - }}
451 - style={actionStyle}
452 - >
453 - <ThreadSwipeActions
454 - backgroundColor={props.backgroundColor}
455 - compact={props.compactActions === true}
456 - fullSwipeAction={fullSwipeAction}
457 - fullSwipeThreshold={fullSwipeThreshold}
458 - onFullSwipeArmedChange={handleFullSwipeArmedChange}
459 - primaryAction={{
460 - ...primaryAction,
461 - onPress: commitPrimaryAction,
461 + renderRightActions={(_progress, translation, methods) =>
462 + props.dormant ? null : (
463 + <Animated.View
464 + ref={() => {
465 + activeTranslationRef.current = translation;
466 }}
463 - secondaryAction={resolveSecondaryAction({
464 - close: () => methods.close(),
465 - onDelete: props.onDelete,
466 - secondaryAction: props.secondaryAction,
467 - threadTitle: props.threadTitle,
468 - })}
469 - translation={translation}
470 - />
471 - </Animated.View>
472 - )}
467 + style={actionStyle}
468 + >
469 + <ThreadSwipeActions
470 + backgroundColor={props.backgroundColor}
471 + compact={props.compactActions === true}
472 + fullSwipeAction={fullSwipeAction}
473 + fullSwipeThreshold={fullSwipeThreshold}
474 + onFullSwipeArmedChange={handleFullSwipeArmedChange}
475 + primaryAction={{
476 + ...primaryAction,
477 + onPress: commitPrimaryAction,
478 + }}
479 + secondaryAction={resolveSecondaryAction({
480 + close: () => methods.close(),
481 + onDelete: props.onDelete,
482 + secondaryAction: props.secondaryAction,
483 + threadTitle: props.threadTitle,
484 + })}
485 + translation={translation}
486 + />
487 + </Animated.View>
488 + )
489 + }
490 rightThreshold={actionsWidth * 0.42}
491 simultaneousWith={props.simultaneousWith}
492 >