Repository navigation
fix(mobile): screen readers hear when the open thread needs you or finishes #34431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shivamhwp
merged 4 commits into
pingdotgg:main
from
shivamhwp:t3/mobile-screen-reader-status
Nov 12, 2026
+270
−5
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8c1806c
fix(mobile): screen readers hear when the open thread starts, needs y…
shivamhwp 4bd3d26
fix(mobile): an answered question stays answered while the shell lags…
shivamhwp 9b4d3b7
fix(mobile): a thread preview beside its host doesn't announce over it
shivamhwp 015f3c0
fix(mobile): a thread preview beside its host names its thread when i…
shivamhwp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
apps/mobile/src/features/threads/threadStatusAnnouncement.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { | ||
| nextThreadAnnouncement, | ||
| type ThreadAnnouncementMemory, | ||
| } from "@t3tools/client-runtime/state/thread-activity-announcement"; | ||
| import { RunId } from "@t3tools/contracts"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { | ||
| nextThreadActivitySnapshot, | ||
| type ThreadActivityInput, | ||
| type ThreadActivityMemory, | ||
| } from "./threadStatusAnnouncement"; | ||
|
|
||
| const run = RunId.make("run-1"); | ||
|
|
||
| /** A frame of a working turn: what the question card shows and what the shell holds. */ | ||
| function frame(card: string | null, shell: string | null): ThreadActivityInput { | ||
| return { | ||
| approvalRequestId: null, | ||
| userInputRequestId: card, | ||
| shellRequestId: shell, | ||
| shellPendingUserInput: shell !== null, | ||
| working: true, | ||
| run: { runId: run, status: "running" }, | ||
| }; | ||
| } | ||
|
|
||
| const idle: ThreadActivityInput = { ...frame(null, null), working: false, run: null }; | ||
| const done: ThreadActivityInput = { | ||
| ...frame(null, null), | ||
| working: false, | ||
| run: { runId: run, status: "completed" }, | ||
| }; | ||
|
|
||
| function announcements(frames: ReadonlyArray<ThreadActivityInput>): ReadonlyArray<string | null> { | ||
| let activity: ThreadActivityMemory | null = null; | ||
| let memory: ThreadAnnouncementMemory | null = null; | ||
| return frames.map((input) => { | ||
| activity = nextThreadActivitySnapshot(activity, input); | ||
| const next = nextThreadAnnouncement(memory, activity.snapshot); | ||
| memory = next.memory; | ||
| return next.announcement; | ||
| }); | ||
| } | ||
|
|
||
| describe("nextThreadActivitySnapshot", () => { | ||
| it("says each question once while the card and the shell catch up at different times", () => { | ||
| expect( | ||
| announcements([ | ||
| idle, | ||
| frame(null, null), | ||
| // The card shows question A before the shell has it. | ||
| frame("a", null), | ||
| frame("a", "a"), | ||
| // Answered: the card hides A at once, the shell still holds it. | ||
| frame(null, "a"), | ||
| // Question B reaches the card while the shell still holds A, and is answered before the shell has B. | ||
| frame("b", "a"), | ||
| frame(null, "a"), | ||
| frame(null, "b"), | ||
| frame(null, null), | ||
| // A secret request shows only in the shell. | ||
| frame(null, "secret"), | ||
| frame(null, null), | ||
| done, | ||
| ]), | ||
| ).toEqual([ | ||
| null, | ||
| "Working", | ||
| "Needs your input", | ||
| null, | ||
| null, | ||
| "Needs your input", | ||
| null, | ||
| null, | ||
| null, | ||
| "Needs your input", | ||
| null, | ||
| "Done", | ||
| ]); | ||
| }); | ||
| }); |
53 changes: 53 additions & 0 deletions
53
apps/mobile/src/features/threads/threadStatusAnnouncement.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import type { ThreadActivitySnapshot } from "@t3tools/client-runtime/state/thread-activity-announcement"; | ||
| import type { RunId, OrchestrationV2RunStatus } from "@t3tools/contracts"; | ||
|
|
||
| export interface ThreadActivityInput { | ||
| readonly approvalRequestId: string | null; | ||
| readonly userInputRequestId: string | null; | ||
| /** The thread shell's pending request, which secret and link cards have only there. */ | ||
| readonly shellRequestId: string | null; | ||
| readonly shellPendingUserInput: boolean; | ||
| readonly working: boolean; | ||
| readonly run: { readonly runId: RunId; readonly status: OrchestrationV2RunStatus } | null; | ||
| } | ||
|
|
||
| export interface ThreadActivityMemory { | ||
| readonly snapshot: ThreadActivitySnapshot; | ||
| /** Requests the thread screen has shown as a card. */ | ||
| readonly cardRequestIds: ReadonlySet<string>; | ||
| } | ||
|
|
||
| /** What the open thread's screen reader status follows, from the same sources the thread screen shows. */ | ||
| export function nextThreadActivitySnapshot( | ||
| previous: ThreadActivityMemory | null, | ||
| input: ThreadActivityInput, | ||
| ): ThreadActivityMemory { | ||
| const { approvalRequestId, userInputRequestId, shellRequestId } = input; | ||
| const cardRequestId = approvalRequestId ?? userInputRequestId; | ||
| const seen = previous?.cardRequestIds ?? new Set<string>(); | ||
| // A card leaves as soon as it is answered, before the shell; a shell request the card | ||
| // already showed is that answered one, so the request stays the one last announced. | ||
| // Secret and link requests never show as a card and come from the shell alone. | ||
| const requestId = | ||
| cardRequestId ?? | ||
| (shellRequestId !== null && seen.has(shellRequestId) | ||
| ? (previous?.snapshot.requestId ?? null) | ||
| : shellRequestId); | ||
| return { | ||
| snapshot: { | ||
| status: | ||
| approvalRequestId !== null | ||
| ? "approval" | ||
| : userInputRequestId !== null || input.shellPendingUserInput | ||
| ? "input" | ||
| : input.working | ||
| ? "working" | ||
| : "idle", | ||
| requestId, | ||
| runId: input.run?.runId ?? null, | ||
| runStatus: input.run?.status ?? null, | ||
| }, | ||
| cardRequestIds: | ||
| cardRequestId === null || seen.has(cardRequestId) ? seen : new Set([...seen, cardRequestId]), | ||
| }; | ||
| } |
85 changes: 85 additions & 0 deletions
85
apps/mobile/src/features/threads/useThreadStatusAnnouncements.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { useIsFocused } from "@react-navigation/native"; | ||
| import { | ||
| nextThreadAnnouncement, | ||
| type ThreadAnnouncementMemory, | ||
| } from "@t3tools/client-runtime/state/thread-activity-announcement"; | ||
| import { useEffect, useRef } from "react"; | ||
| import { AccessibilityInfo } from "react-native"; | ||
|
|
||
| import { useAppActive } from "../../lib/appState"; | ||
| import { | ||
| nextThreadActivitySnapshot, | ||
| type ThreadActivityInput, | ||
| type ThreadActivityMemory, | ||
| } from "./threadStatusAnnouncement"; | ||
|
|
||
| /** Tells VoiceOver and TalkBack when the open thread starts working, needs the user, or finishes. */ | ||
| export function useThreadStatusAnnouncements({ | ||
| threadKey, | ||
| subject, | ||
| detailBehind, | ||
| approvalRequestId, | ||
| userInputRequestId, | ||
| shellRequestId, | ||
| shellPendingUserInput, | ||
| working, | ||
| run, | ||
| }: ThreadActivityInput & { | ||
| /** Null when nothing should be announced, such as a provider subagent's thread. */ | ||
| readonly threadKey: string | null; | ||
| /** The thread's title, said after each status when another thread is on screen beside it. */ | ||
| readonly subject: string | null; | ||
| /** See isDetailBehindShell. */ | ||
| readonly detailBehind: boolean; | ||
| }) { | ||
| // A retained route stays mounted under the screen above it; it speaks only while shown, | ||
| // and starts from a silent baseline when it is shown again. | ||
| const focused = useIsFocused(); | ||
| const appActive = useAppActive(); | ||
| const activeKey = focused && appActive ? threadKey : null; | ||
| const memoryRef = useRef<{ | ||
| threadKey: string; | ||
| activity: ThreadActivityMemory; | ||
| announcement: ThreadAnnouncementMemory; | ||
| } | null>(null); | ||
| const runId = run?.runId ?? null; | ||
| const runStatus = run?.status ?? null; | ||
|
|
||
| // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- speaks committed status changes through the platform screen reader | ||
| useEffect(() => { | ||
| if (activeKey === null) { | ||
| memoryRef.current = null; | ||
| return; | ||
| } | ||
| if (detailBehind) return; | ||
| const previous = memoryRef.current?.threadKey === activeKey ? memoryRef.current : null; | ||
| const activity = nextThreadActivitySnapshot(previous?.activity ?? null, { | ||
| approvalRequestId, | ||
| userInputRequestId, | ||
| shellRequestId, | ||
| shellPendingUserInput, | ||
| working, | ||
| run: runId === null || runStatus === null ? null : { runId, status: runStatus }, | ||
| }); | ||
| const next = nextThreadAnnouncement(previous?.announcement ?? null, activity.snapshot); | ||
| memoryRef.current = { threadKey: activeKey, activity, announcement: next.memory }; | ||
| // Queued, like the web's polite region, so VoiceOver doesn't cut off what it is reading. | ||
| if (next.announcement !== null) { | ||
| AccessibilityInfo.announceForAccessibilityWithOptions( | ||
| subject === null ? next.announcement : `${next.announcement}: ${subject}`, | ||
| { queue: true }, | ||
| ); | ||
| } | ||
| }, [ | ||
| activeKey, | ||
| subject, | ||
| detailBehind, | ||
| approvalRequestId, | ||
| userInputRequestId, | ||
| shellRequestId, | ||
| shellPendingUserInput, | ||
| working, | ||
| runId, | ||
| runStatus, | ||
| ]); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.