Open History to see the last commit
1import type { SubagentPillSegment } from "@t3tools/client-runtime/state/thread-subagents";
2import { formatDuration } from "@t3tools/shared/orchestrationTiming";
3import { GlassContainer, GlassView } from "expo-glass-effect";
4import { type ReactNode, useEffect, useRef, useState } from "react";
5import {
6 type LayoutChangeEvent,
7 Pressable,
8 Text as SystemText,
9 useWindowDimensions,
10 View,
11} from "react-native";
12import Animated, {
13 Easing,
14 FadeIn,
15 FadeOut,
16 ReduceMotion,
17 type SharedValue,
18 useAnimatedStyle,
19 useReducedMotion,
20 useSharedValue,
21 withTiming,
22} from "react-native-reanimated";
23import { withUniwind } from "uniwind";
24
25import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
26import { AppText as Text } from "../../components/ui/AppText";
27import { SymbolView } from "../../components/ui/AppSymbol";
28import { ControlPill } from "../../components/ui/ControlPill";
29import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
30import { BrowserPreviewButton } from "../browser/browser-preview-button";
31import { DevicePreviewButton } from "../devices/device-preview-button";
32import type { FloatingWorkingStatus } from "./floating-working-status";
33import { ShimmeringWorkContent } from "./thread-work-log";
34import { useVisibleSecondClock } from "./use-visible-second-clock";
35
36const CONTROL_HEIGHT = 38.5;
37const CONTROL_GAP = 8;
38const COMPOSER_CAPSULE_INSET = 6;
39const GLASS_MERGE_SPACING = 12;
40const CONTROL_ENTERING = FadeIn.duration(180).reduceMotion(ReduceMotion.System);
41const CONTROL_EXITING = FadeOut.duration(120).reduceMotion(ReduceMotion.System);
42const CONTROL_TIMING = {
43 duration: 240,
44 easing: Easing.out(Easing.cubic),
45 reduceMotion: ReduceMotion.System,
46} as const;
47const CONTROL_ROW_GAP = 14;
48const CONTROL_SEPARATION = (CONTROL_ROW_GAP + CONTROL_HEIGHT) / 2;
49const LABEL_ENTERING = FadeIn.duration(160).delay(80).reduceMotion(ReduceMotion.System);
50const LABEL_EXITING = FadeOut.duration(100).reduceMotion(ReduceMotion.System);
51
52// Expo reapplies glass after layout or reattachment, restoring material UIKit can lose behind visible labels.
53const UniwindGlassView = withUniwind(GlassView, {
54 style: { fromClassName: "className" },
55});
56const UniwindGlassContainer = withUniwind(GlassContainer, {
57 style: { fromClassName: "className" },
58});
59const AnimatedGlassView = Animated.createAnimatedComponent(UniwindGlassView);
60
61// Segment widths feed back into labelWidth; ignore sub-point changes to avoid rounding-driven ellipsis loops.
62function settleWidth(next: number) {
63 return (current: number) => (Math.abs(current - next) < 1 ? current : next);
64}
65
66const CONTROL_OVERLAY_OFFSET = CONTROL_HEIGHT + CONTROL_GAP - COMPOSER_CAPSULE_INSET;
67export const FLOATING_WORKING_CONTROL_COVERAGE = CONTROL_OVERLAY_OFFSET + CONTROL_GAP;
68
69export function FloatingWorkingControl(props: {
70 readonly colorScheme: "light" | "dark";
71 readonly status: FloatingWorkingStatus | null;
72 readonly extensionStatus?: { readonly label: string; readonly onPress: () => void } | null;
73 readonly devicePreview: { readonly count: number; readonly onPress: () => void } | null;
74 readonly browserPreview: { readonly count: number; readonly onPress: () => void } | null;
75 readonly showScrollToEnd: boolean;
76 readonly onScrollToEnd: () => void;
77 readonly agents: SubagentPillSegment | null;
78 readonly onOpenAgents: () => void;
79 readonly queuedCount: number;
80 readonly onOpenQueue: () => void;
81 readonly lift?: SharedValue<number>;
82}) {
83 const { width: windowWidth } = useWindowDimensions();
84 const reducedMotion = useReducedMotion();
85 const [overlayWidth, setOverlayWidth] = useState(windowWidth);
86 const [queueWidth, setQueueWidth] = useState(0);
87 const [actionWidth, setActionWidth] = useState(0);
88 const [extensionWidth, setExtensionWidth] = useState(0);
89 const extensionStatus = props.extensionStatus ?? null;
90 const extensionOnly = props.status?.kind === "extension";
91 const useGlass = NATIVE_LIQUID_GLASS_SUPPORTED && !extensionOnly;
92 const action =
93 props.status?.kind === "background" ||
94 props.status?.kind === "lifecycle" ||
95 props.status?.kind === "stop"
96 ? props.status.action
97 : null;
98 const [agentsWidth, setAgentsWidth] = useState(0);
99 const hasQueue = props.queuedCount > 0;
100 const hasPreview = props.devicePreview !== null || props.browserPreview !== null;
101 const [previewWidth, setPreviewWidth] = useState(0);
102 const agents = props.agents;
103 const hasAgents = agents !== null;
104 const availableLabelWidth = Math.max(
105 0,
106 Math.min(overlayWidth, windowWidth) -
107 CONTROL_HEIGHT -
108 32 -
109 (action !== null ? actionWidth : 0) -
110 (hasQueue ? queueWidth : 0) -
111 (hasAgents ? agentsWidth : 0) -
112 (hasPreview ? previewWidth : 0),
113 );
114 const labelWidth = Math.max(
115 0,
116 availableLabelWidth - (extensionStatus === null ? 0 : extensionWidth),
117 );
118 const separationProgress = useSharedValue(props.showScrollToEnd ? 1 : 0);
119
120 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- animates the Reanimated separation value when scroll-to-end visibility changes
121 useEffect(() => {
122 separationProgress.set(withTiming(props.showScrollToEnd ? 1 : 0, CONTROL_TIMING));
123 }, [props.showScrollToEnd, separationProgress]);
124
125 const lift = props.lift;
126 const liftStyle = useAnimatedStyle(() => ({
127 transform: [{ translateY: -(lift?.value ?? 0) }],
128 }));
129 const arrowTransformStyle = useAnimatedStyle(() => ({
130 transform: [{ translateX: -CONTROL_SEPARATION * (1 - separationProgress.value) }],
131 }));
132 const arrowContentStyle = useAnimatedStyle(() => ({
133 opacity: separationProgress.value,
134 }));
135
136 // Animate an in-flow sizer for native glass layout. Measure labels at fixed width to avoid repeated animation retargeting.
137 const capsuleWidth = useSharedValue<number | null>(null);
138 const measuredWidthRef = useRef<number | null>(null);
139 const handleLabelLayout = (event: LayoutChangeEvent) => {
140 const width = event.nativeEvent.layout.width;
141 if (width === measuredWidthRef.current) {
142 return;
143 }
144 const first = measuredWidthRef.current === null;
145 measuredWidthRef.current = width;
146 capsuleWidth.set(first ? width : withTiming(width, CONTROL_TIMING));
147 };
148 const hasStatus = props.status !== null;
149 const hasCapsule = hasStatus || hasQueue || hasAgents || hasPreview;
150 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- clears the Reanimated capsule width value and measured width when the status goes away
151 useEffect(() => {
152 if (!hasStatus) {
153 measuredWidthRef.current = null;
154 capsuleWidth.set(null);
155 }
156 }, [capsuleWidth, hasStatus]);
157 const capsuleStyle = useAnimatedStyle(() => ({
158 transform: [{ translateX: CONTROL_SEPARATION * (1 - separationProgress.value) }],
159 }));
160 const capsuleSizerStyle = useAnimatedStyle(() => ({
161 width: capsuleWidth.value ?? 0,
162 }));
163
164 if (!hasCapsule && !props.showScrollToEnd) {
165 return null;
166 }
167
168 const previewCompact =
169 hasStatus ||
170 hasAgents ||
171 hasQueue ||
172 (props.devicePreview !== null && props.browserPreview !== null);
173 const statusInteractive =
174 props.status?.kind === "connection" ||
175 props.status?.kind === "extension" ||
176 props.status?.kind === "child-input" ||
177 props.status?.kind === "background";
178 const capsuleInteractive =
179 statusInteractive ||
180 extensionStatus !== null ||
181 action !== null ||
182 hasQueue ||
183 hasAgents ||
184 hasPreview;
185 const statusContent =
186 props.status !== null ? (
187 <View
188 pointerEvents={statusInteractive ? "box-none" : "none"}
189 className="h-11 items-center justify-center"
190 >
191 <Animated.View className="h-11" style={capsuleSizerStyle} />
192 <View
193 pointerEvents={statusInteractive ? "box-none" : "none"}
194 className="absolute h-11 items-center justify-center"
195 style={{ width: labelWidth }}
196 >
197 <FloatingStatusLabel
198 key={
199 props.status.kind === "working" ||
200 props.status.kind === "compacting" ||
201 props.status.kind === "extension"
202 ? props.status.kind
203 : `${props.status.kind}:${props.status.label}`
204 }
205 status={props.status}
206 onLayout={handleLabelLayout}
207 />
208 </View>
209 </View>
210 ) : null;
211
212 const capsuleContent = (
213 <View className="flex-row items-center">
214 {statusContent}
215 {extensionStatus !== null ? (
216 <Pressable
217 accessibilityRole="button"
218 accessibilityLabel={extensionStatus.label}
219 accessibilityHint="Shows the full Pi status"
220 onPress={extensionStatus.onPress}
221 onLayout={(event) => setExtensionWidth(settleWidth(event.nativeEvent.layout.width))}
222 style={{ maxWidth: availableLabelWidth * 0.5 }}
223 className="h-11 flex-row items-center px-3 active:opacity-70"
224 >
225 {hasStatus ? <View className="absolute left-0 h-4 w-px bg-border" /> : null}
226 <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
227 {extensionStatus.label}
228 </Text>
229 </Pressable>
230 ) : null}
231 {action !== null ? (
232 <View
233 onLayout={(event) => setActionWidth(settleWidth(event.nativeEvent.layout.width))}
234 className="h-11 flex-row items-center"
235 >
236 <View className="h-4 w-px bg-border" />
237 <Pressable
238 accessibilityRole="button"
239 accessibilityLabel={action.accessibilityLabel}
240 accessibilityState={{ disabled: action.disabled }}
241 disabled={action.disabled}
242 onPress={action.onPress}
243 className={`h-11 items-center justify-center px-3 active:opacity-70 ${action.disabled ? "opacity-50" : ""}`}
244 >
245 <Text className="font-t3-medium text-xs text-foreground" numberOfLines={1}>
246 {action.label}
247 </Text>
248 </Pressable>
249 </View>
250 ) : null}
251 {hasPreview ? (
252 <View
253 className="h-11 flex-row items-center"
254 onLayout={(event) => setPreviewWidth(settleWidth(event.nativeEvent.layout.width))}
255 >
256 {hasStatus ? <View className="h-4 w-px bg-border" /> : null}
257 {props.devicePreview !== null ? (
258 <DevicePreviewButton {...props.devicePreview} compact={previewCompact} />
259 ) : null}
260 {props.browserPreview !== null ? (
261 <BrowserPreviewButton {...props.browserPreview} compact={previewCompact} />
262 ) : null}
263 </View>
264 ) : null}
265 {agents !== null ? (
266 <Pressable
267 accessibilityRole="button"
268 accessibilityLabel={`Open agents, ${agents.accessibilityLabel}`}
269 accessibilityHint="Opens this turn's subagents"
270 onPress={props.onOpenAgents}
271 onLayout={(event) => setAgentsWidth(settleWidth(event.nativeEvent.layout.width))}
272 className="h-11 flex-row items-center gap-1.5 px-3 active:opacity-70"
273 >
274 {hasStatus || hasPreview ? <View className="absolute left-0 h-4 w-px bg-border" /> : null}
275 <SymbolView name="person.2" size={13} tintColorClassName="accent-foreground-muted" />
276 <Text className="font-t3-medium text-xs tabular-nums" numberOfLines={1}>
277 {agents.label}
278 </Text>
279 </Pressable>
280 ) : null}
281 {hasQueue ? (
282 <Pressable
283 accessibilityRole="button"
284 accessibilityLabel={`Open queue, ${props.queuedCount} messages`}
285 accessibilityHint="Opens queued messages to send now, edit, or remove"
286 onPress={props.onOpenQueue}
287 onLayout={(event) => setQueueWidth(settleWidth(event.nativeEvent.layout.width))}
288 style={{ maxWidth: Math.min(overlayWidth, windowWidth) * 0.45 }}
289 className="h-11 flex-row items-center gap-2 px-3 active:opacity-70"
290 >
291 {hasStatus || hasPreview || hasAgents ? (
292 <View className="absolute left-0 h-4 w-px bg-border" />
293 ) : null}
294 <SymbolView name="list.number" size={13} tintColorClassName="accent-foreground-muted" />
295 <Text className="shrink font-t3-medium text-xs tabular-nums" numberOfLines={1}>
296 {props.queuedCount} queued
297 </Text>
298 </Pressable>
299 ) : null}
300 </View>
301 );
302
303 return (
304 <Animated.View
305 pointerEvents="box-none"
306 className="absolute left-0 right-0 z-20 items-center"
307 style={[{ top: -CONTROL_OVERLAY_OFFSET }, liftStyle]}
308 onLayout={(event) => setOverlayWidth(event.nativeEvent.layout.width)}
309 entering={useGlass || extensionOnly || reducedMotion ? undefined : CONTROL_ENTERING}
310 exiting={useGlass || extensionOnly || reducedMotion ? undefined : CONTROL_EXITING}
311 >
312 {hasCapsule && useGlass ? (
313 <UniwindGlassContainer
314 spacing={GLASS_MERGE_SPACING}
315 pointerEvents="box-none"
316 className="flex-row items-center gap-4"
317 >
318 <AnimatedGlassView
319 colorScheme={props.colorScheme}
320 glassEffectStyle="regular"
321 isInteractive={capsuleInteractive}
322 pointerEvents={capsuleInteractive ? "box-none" : "none"}
323 className="h-11 items-center justify-center overflow-hidden rounded-full"
324 style={capsuleStyle}
325 >
326 {capsuleContent}
327 </AnimatedGlassView>
328
329 <AnimatedGlassView
330 colorScheme={props.colorScheme}
331 glassEffectStyle={{ style: props.showScrollToEnd ? "regular" : "none", animate: true }}
332 isInteractive
333 pointerEvents={props.showScrollToEnd ? "auto" : "none"}
334 accessibilityElementsHidden={!props.showScrollToEnd}
335 importantForAccessibility={props.showScrollToEnd ? "auto" : "no-hide-descendants"}
336 className="h-11 w-11 items-center justify-center overflow-hidden rounded-full"
337 style={arrowTransformStyle}
338 >
339 <Animated.View style={arrowContentStyle}>
340 <ScrollToEndButton disabled={!props.showScrollToEnd} onPress={props.onScrollToEnd} />
341 </Animated.View>
342 </AnimatedGlassView>
343 </UniwindGlassContainer>
344 ) : hasCapsule ? (
345 <View pointerEvents="box-none" className="flex-row items-center gap-4">
346 <Animated.View
347 pointerEvents={capsuleInteractive ? "box-none" : "none"}
348 className="h-11 items-center justify-center overflow-hidden rounded-full border border-border bg-glass-fallback shadow-md shadow-black/10"
349 style={capsuleStyle}
350 >
351 {capsuleContent}
352 </Animated.View>
353
354 <Animated.View
355 pointerEvents={props.showScrollToEnd ? "auto" : "none"}
356 accessibilityElementsHidden={!props.showScrollToEnd}
357 importantForAccessibility={props.showScrollToEnd ? "auto" : "no-hide-descendants"}
358 style={[arrowTransformStyle, arrowContentStyle]}
359 >
360 <ControlPill
361 accessibilityLabel="Scroll to end"
362 activateOnPressIn
363 className="h-11 w-11 border border-border bg-glass-fallback shadow-md shadow-black/10"
364 disabled={!props.showScrollToEnd}
365 icon={{ ios: "chevron.down", android: "keyboard_arrow_down" }}
366 onPress={props.onScrollToEnd}
367 />
368 </Animated.View>
369 </View>
370 ) : NATIVE_LIQUID_GLASS_SUPPORTED ? (
371 <UniwindGlassView
372 colorScheme={props.colorScheme}
373 glassEffectStyle="regular"
374 isInteractive
375 className="h-11 w-11 items-center justify-center overflow-hidden rounded-full"
376 >
377 <ScrollToEndButton onPress={props.onScrollToEnd} />
378 </UniwindGlassView>
379 ) : (
380 <ControlPill
381 accessibilityLabel="Scroll to end"
382 activateOnPressIn
383 className="h-11 w-11 border border-border bg-glass-fallback shadow-md shadow-black/10"
384 icon={{ ios: "chevron.down", android: "keyboard_arrow_down" }}
385 onPress={props.onScrollToEnd}
386 />
387 )}
388 </Animated.View>
389 );
390}
391
392function CompactingLabel(props: { readonly onLayout: (event: LayoutChangeEvent) => void }) {
393 return (
394 <StatusLabelRow accessibilityLabel="Compacting" className="gap-1.5" onLayout={props.onLayout}>
395 <SymbolView
396 name="arrow.down.right.and.arrow.up.left"
397 size={13}
398 tintColorClassName="foreground"
399 type="monochrome"
400 />
401 <Text className="font-t3-medium text-xs text-foreground">Compacting…</Text>
402 </StatusLabelRow>
403 );
404}
405
406function FloatingStatusLabel(props: {
407 readonly status: FloatingWorkingStatus;
408 readonly onLayout: (event: LayoutChangeEvent) => void;
409}) {
410 if (props.status.kind === "extension") {
411 return (
412 <StatusLabelRow
413 accessibilityLabel={props.status.label}
414 accessibilityRole="button"
415 onPress={props.status.onPress}
416 onLayout={props.onLayout}
417 className="gap-1.5"
418 animated={false}
419 >
420 <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
421 {props.status.label}
422 </Text>
423 <SymbolView name="chevron.down" size={10} tintColorClassName="accent-foreground" />
424 </StatusLabelRow>
425 );
426 }
427 if (props.status.kind === "syncing") {
428 return (
429 <StatusLabelRow
430 key="syncing"
431 accessibilityLabel={props.status.label}
432 className="gap-2"
433 onLayout={props.onLayout}
434 >
435 <AppActivityIndicator size="small" colorClassName="accent-icon-muted" />
436 <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
437 {props.status.label}
438 </Text>
439 </StatusLabelRow>
440 );
441 }
442 if (props.status.kind === "compacting") {
443 return <CompactingLabel key="compacting" onLayout={props.onLayout} />;
444 }
445 if (props.status.kind === "child-input") {
446 return (
447 <StatusLabelRow
448 key="child-input"
449 accessibilityLabel={props.status.accessibilityLabel}
450 accessibilityRole="button"
451 className="gap-2"
452 onLayout={props.onLayout}
453 onPress={props.status.onPress}
454 >
455 <SymbolView name="text.bubble" size={13} tintColorClassName="foreground" />
456 <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
457 {props.status.label}
458 </Text>
459 </StatusLabelRow>
460 );
461 }
462 if (props.status.kind === "connection") {
463 return (
464 <StatusLabelRow
465 key="connection"
466 accessibilityLabel={props.status.label}
467 accessibilityRole="button"
468 className="gap-2"
469 onLayout={props.onLayout}
470 onPress={props.status.onPress}
471 >
472 {props.status.tone === "reconnecting" ? (
473 <AppActivityIndicator size="small" colorClassName="accent-icon-muted" />
474 ) : (
475 <View className="h-2 w-2 rounded-full bg-red-500" />
476 )}
477 <Text
478 className="max-w-[260px] shrink font-t3-medium text-xs text-foreground"
479 numberOfLines={1}
480 >
481 {props.status.label}
482 </Text>
483 </StatusLabelRow>
484 );
485 }
486 if (props.status.kind === "lifecycle") {
487 return (
488 <StatusLabelRow
489 key="lifecycle"
490 accessibilityLabel={props.status.label}
491 className="gap-2"
492 onLayout={props.onLayout}
493 >
494 <SymbolView
495 name={props.status.state === "settled" ? "checkmark.circle" : "clock"}
496 size={13}
497 tintColorClassName="foreground"
498 type="monochrome"
499 />
500 <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
501 {props.status.label}
502 </Text>
503 </StatusLabelRow>
504 );
505 }
506 if (props.status.kind === "background") {
507 return (
508 <StatusLabelRow
509 key="background"
510 accessibilityLabel={props.status.accessibilityLabel}
511 accessibilityRole="button"
512 onPress={props.status.onPress}
513 className="gap-2"
514 onLayout={props.onLayout}
515 >
516 <SymbolView
517 name={props.status.waiting ? "person.2" : "terminal"}
518 size={13}
519 tintColorClassName="foreground"
520 type="monochrome"
521 />
522 <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
523 {props.status.label}
524 </Text>
525 </StatusLabelRow>
526 );
527 }
528 if (props.status.kind === "stop") {
529 return (
530 <StatusLabelRow
531 key="stop"
532 accessibilityLabel={props.status.label}
533 className="gap-2"
534 onLayout={props.onLayout}
535 >
536 {props.status.unresponsive ? (
537 <SymbolView
538 name="exclamationmark.triangle"
539 size={13}
540 tintColorClassName="accent-warning-foreground"
541 type="monochrome"
542 />
543 ) : (
544 <AppActivityIndicator size="small" colorClassName="accent-icon-muted" />
545 )}
546 <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
547 {props.status.label}
548 </Text>
549 </StatusLabelRow>
550 );
551 }
552 if (props.status.kind === "goal") {
553 return (
554 <StatusLabelRow
555 key="goal"
556 accessibilityLabel={props.status.accessibilityLabel}
557 className="gap-2"
558 onLayout={props.onLayout}
559 >
560 <SymbolView name="target" size={13} tintColorClassName="foreground" type="monochrome" />
561 <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
562 {props.status.label}
563 </Text>
564 </StatusLabelRow>
565 );
566 }
567 if (props.status.kind === "preparing") {
568 return (
569 <StatusLabelRow
570 key="preparing"
571 accessibilityLabel={props.status.label}
572 className="gap-1.5"
573 onLayout={props.onLayout}
574 >
575 <SymbolView
576 name="arrow.triangle.branch"
577 size={13}
578 tintColorClassName="foreground"
579 type="monochrome"
580 />
581 <ShimmeringWorkContent
582 className="flex-none"
583 textClassName="font-t3-medium"
584 compact
585 icon="arrow.triangle.branch"
586 iconSubtleColor="transparent"
587 label={props.status.label}
588 showIcon={false}
589 />
590 </StatusLabelRow>
591 );
592 }
593 return (
594 <WorkingDuration key="working" startedAt={props.status.startedAt} onLayout={props.onLayout} />
595 );
596}
597
598function StatusLabelRow(props: {
599 readonly animated?: boolean;
600 readonly accessibilityLabel?: string;
601 readonly accessibilityRole?: "button";
602 readonly className?: string;
603 readonly children: ReactNode;
604 readonly onLayout: (event: LayoutChangeEvent) => void;
605 readonly onPress?: () => void;
606}) {
607 const reducedMotion = useReducedMotion();
608 const rowClassName = `h-11 flex-row items-center px-4 ${props.className ?? ""}`;
609 return (
610 <Animated.View
611 className="absolute max-w-full"
612 entering={props.animated === false || reducedMotion ? undefined : LABEL_ENTERING}
613 exiting={props.animated === false || reducedMotion ? undefined : LABEL_EXITING}
614 onLayout={props.onLayout}
615 >
616 {props.onPress ? (
617 <Pressable
618 accessibilityLabel={props.accessibilityLabel}
619 accessibilityRole={props.accessibilityRole}
620 className={`${rowClassName} active:opacity-70`}
621 onPress={props.onPress}
622 >
623 {props.children}
624 </Pressable>
625 ) : (
626 <View accessible accessibilityLabel={props.accessibilityLabel} className={rowClassName}>
627 {props.children}
628 </View>
629 )}
630 </Animated.View>
631 );
632}
633
634function WorkingDuration(props: {
635 readonly startedAt: string;
636 readonly onLayout: (event: LayoutChangeEvent) => void;
637}) {
638 return (
639 <StatusLabelRow onLayout={props.onLayout}>
640 <WorkingTimer startedAt={props.startedAt} />
641 </StatusLabelRow>
642 );
643}
644
645function WorkingTimer(props: { readonly startedAt: string }) {
646 const nowMs = useVisibleSecondClock(true);
647 return (
648 <SystemText
649 className="shrink text-xs text-foreground"
650 numberOfLines={1}
651 style={{ fontVariant: ["tabular-nums"], fontWeight: "500" }}
652 >
653 Working {formatWorkingDuration(props.startedAt, nowMs)}
654 </SystemText>
655 );
656}
657
658function formatWorkingDuration(startedAt: string, nowMs: number): string {
659 const startedAtMs = Date.parse(startedAt);
660 if (!Number.isFinite(startedAtMs) || nowMs <= startedAtMs) {
661 return "0s";
662 }
663
664 const totalSeconds = Math.floor((nowMs - startedAtMs) / 1_000);
665 if (totalSeconds < 60) {
666 return `${totalSeconds}s`;
667 }
668 if (totalSeconds >= 3_600) {
669 return formatDuration(totalSeconds * 1_000);
670 }
671
672 const minutes = Math.floor(totalSeconds / 60);
673 const seconds = String(totalSeconds % 60).padStart(2, "0");
674 return `${minutes}m ${seconds}s`;
675}
676
677function ScrollToEndButton(props: { readonly disabled?: boolean; readonly onPress: () => void }) {
678 return (
679 <ControlPill
680 accessibilityLabel="Scroll to end"
681 activateOnPressIn
682 className="h-11 w-11 bg-transparent"
683 disabled={props.disabled}
684 icon={{ ios: "chevron.down", android: "keyboard_arrow_down" }}
685 onPress={props.onPress}
686 />
687 );
688}