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