Skip to content

Improve VoiceOver, and make the view safe to call off the main thread - #39

Merged
servercimen merged 16 commits into
feature/tagsfrom
feature/accessibility
Nov 24, 2026
Merged

servercimen merged 16 commits into
feature/tagsfrom
feature/accessibility

Conversation

@servercimen

Copy link
Copy Markdown
Owner

Part 9 of a stack of 13 pull requests. The base is #38 (feature/tags). #31 (part 1) tells how to merge the stack.

On this stacked branch, swift test passes (330 tests), and the iOS build and build-for-testing pass.

Summary

Assistive technologies need all of the text, elements that stay the same while text streams in, and answers on any thread. Before this change, a line limit cut what VoiceOver read and what Copy copied. Each layout made new elements. A call from a background thread stopped the app.

  • Line limit. VoiceOver reads all of the text. A selection that reaches the end of the shown text, such as Select All, also covers the text that the limit leaves out, in Copy, selectedRange and selectedText.
  • Stable elements. Each block keeps one element, by its block id. A new layout updates it in place, and a block whose layout did not change keeps its words. The view posts a layout-changed notification only after a client asked for the elements, and only when elements come or go, move or change size.
  • Lists, tables and formulas. A list item tells its position, such as "Item 2 of 3". A table is a data table with one element for each cell. The new TranscriptTextView.mathAccessibilityLabel and TranscriptText.mathAccessibilityLabel(_:) give the words for a formula. Without them, VoiceOver reads the LaTeX, as before. The new string "Item %1$ld of %2$ld" comes from the app's Localizable.strings.
  • Any thread. The accessibility getters, the UITextInput members, the element types, point(inside:with:), canBecomeFirstResponder, inputView, canPerformAction(_:withSender:), copy(_:) and selectAll(_:) are now nonisolated. Their signatures do not change. Off the main thread, they do their work with DispatchQueue.main.sync. The main thread never waits for another thread.

Tests

  • swift test on macOS: 202 tests pass.
  • Mac Catalyst (-only-testing:TranscriptKitTests): 211 tests pass, with the UIKit tests. The first call of OffMainThreadTests stops the process on main, in _checkExpectedExecutor.
  • iOS build: xcodebuild build and build-for-testing with -scheme TranscriptKit -destination 'generic/platform=iOS' (Xcode 27.2) succeed with no warnings. The last commit makes the test delegate build with the iOS 27.2 SDK.

Checked on an iPhone 12 mini

A check screen in a local test app ran with VoiceOver off, at the commit before the last one. The last commit changes only a test file. Each check ran on main first and showed the problem. The cost check is a comparison.

  • Line limit: main copies 86 of 317 UTF-16 units. The branch copies all of the text, and the label has all 317 units.
  • Streaming: main made new element objects in 46 of 49 polls, and a kept element kept its old label. On the branch, all elements stayed the same objects, and the view posted one layout change for each new paragraph.
  • Structure: main reads a table as one string and a formula as TeX. The branch gives list positions, table cells with headers, and the app's words for the formula.
  • Threads: each of 10 view members traps on main when a background thread calls it. The branch answers 26 such calls, and 4 s of calls from two threads, with no trap and no deadlock.
  • Cost: a client asks for the elements every 0.2 s on a 301-block transcript while text streams in. A request takes 6.2 to 6.3 ms (median) on the branch, against 3.2 to 8.0 ms on main. The first request takes 13 to 15 ms, against 3 to 8 ms.

Stand-ins: calls from a background thread take the place of a real client. The check reads the accessibility properties and does not hear them.

Not checked

  • The on-screen position of the frames. With VoiceOver off, convertToScreenCoordinates returns its input.
  • VoiceOver speech, focus and the focus ring while text streams in.
  • Real assistive clients on other threads.

Known limits

  • The column header of the first cell of a table that starts a list item includes the marker, for example "2. C".
  • Under a line limit, Share, Translate and Look Up get only the shown text.

🤖 Generated with Claude Code

servercimen and others added 15 commits November 23, 2026 17:15
Under a line limit, VoiceOver now reads the whole text of the block
that the limit cuts. The last element also reads the blocks that the
limit leaves out, as a label that is cut short does.

A selection that reaches the end of the text shown now also covers the
text that the limit leaves out. Select All followed by Copy copies all
of the text. The selection highlight still covers only the text shown.
selectedRange and selectedText give the same range that Copy uses.

The accessibility text now comes from a model without UIKit, so that
the tests on macOS cover it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each block now keeps its accessibility element from one layout to the
next, by its block id. A new layout updates the label, frame, traits
and link actions of the element in place. VoiceOver focus thus stays on
its block while text streams in.

The view posts a layout-changed notification only after an assistive
technology asked for the elements, and only when elements come or go,
or when the layout is not an append. Text that streams into the last
block posts nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first block of a list item now gives its position in its list and
the number of items as its accessibility value, such as "Item 2 of 3".
A list ends at a block outside its containers, or at an item with
another kind of marker. The count includes items that a line limit
leaves out.

A table is now a data table container with one element for each cell.
VoiceOver reads the row, the column and the column header. A link in a
cell is an action of that cell.

The new mathAccessibilityLabel closure on TranscriptTextView, and the
mathAccessibilityLabel modifier on TranscriptText, give the words for a
formula. Without them, VoiceOver reads the LaTeX, as before.

The new string "Item %1$ld of %2$ld" comes from the app's
Localizable.strings, as the other spoken strings do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In the Swift 6 language mode, a main actor method that Objective-C
calls from another thread stops the process. VoiceOver, Speak Screen,
Voice Control and the text rotor can call accessibility getters and
UITextInput methods from another thread. A test that called
isAccessibilityElement on the view from a background thread stopped
in _checkExpectedExecutor.

These methods are now nonisolated:

- The view's isAccessibilityElement and accessibilityElements.
- Every UITextInput method and property of the view, its tokenizer,
  its input delegate and writingToolsBehavior.
- The getters of the text position, text range and selection rect
  types. They read values that never change.
- The label, value, traits, frame and custom actions of the block and
  cell elements, which now keep these values in Swift properties.
- The data table methods of the table element and the row and column
  ranges of the cell elements.
- The link actions.

A method that needs the view's state does its work on the main thread
with onMainThread: at once on the main thread, and otherwise with
DispatchQueue.main.sync from the thread that called. The main thread
never waits for another thread.

The new tests call each of these methods from a background thread
through the Objective-C runtime. They run in the Mac Catalyst variant,
because swift test on macOS does not build the UIKit code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The elements now give their screen frame from a nonisolated getter.
UIKit can also use the frame in container coordinates, for example to
scroll an element into view. The update on the main thread now sets
that frame too: the block's frame in the view, and a cell's frame in
its table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An assistive technology can keep an element, such as the element that
has VoiceOver focus, and read it again later. An update that only adds
text to the last block posts no notification, so the client does not
ask the view for its elements again. The element then gave its old
text.

Each getter of a block, cell or table element now first brings the
elements up to date with the layout on screen. When the elements
already match that layout, this costs nothing more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A layout that is not an append, such as a layout after new colors for
code, posted a layout-changed notification every time. Now such a
layout posts only when its items differ from the items that the
elements were last made with. An append posts only when its shape
changes.

The shape now also tells whether the text that a line limit leaves out
has an item of its own. Before, a paragraph that streamed in after a
table under a line limit added an element and posted nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A table that starts a list item lost the list marker, the task state
and the position. Now its first cell reads the marker before its text,
and has the position as its value.

An element key was the block id with "#" and a count, so the ids
"same", "same" and "same#1" gave the same key twice. A key is now a
struct of the id and the number of blocks before it with that id.

A table cell now brings the elements up to date before it gives its row
or column, as its other getters do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With an assistive technology on, the elements were made from the whole
document for each new layout. Each block was read again, and the app's
formula closure ran again for each formula. Now the view keeps the words
of each block with the block layout that they came from. A block whose
layout is the same object as before uses its words again. New link
definitions or a new mathAccessibilityLabel make all words again.

A table cell read all of the spans of its table, so a table cost its
spans times its cells. Now each span goes to the cell that holds its
start, by binary search.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
point(inside:with:), canBecomeFirstResponder, inputView,
canPerformAction(_:withSender:), copy(_:) and selectAll(_:) were still
main actor overrides. The accessibility hit test reaches
point(inside:with:), so an assistive client that hit-tests from another
thread stopped the app. These overrides are now nonisolated and do
their work on the main thread, as the UITextInput methods do.

New tests call these overrides, the inputDelegate setter,
writingToolsBehavior and a link action from a background thread. Other
new tests check that Select All under a line limit selects and copies
all of the text, that the selection grows and is reported again while
text streams in after the cut, and that the element reads all of the
text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The decision to post a layout change compared a new layout with the
items that the elements were last made with. An append that posted
nothing did not make the items again, so they grew old. While a code
block streamed in, the next color result then found a longer label and
posted.

Now the view keeps the geometry of each layout that it installs, once
an assistive technology has asked for the elements: the blocks, the
number of elements of each, their frames, and whether the text that a
line limit leaves out has an item. The geometry does not read the text
of the blocks. An append posts when elements come or go. Another layout
also posts when an element moved or changed its size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The iOS 27.2 SDK makes conversationContext(_:didChange:) a required
method of UITextInputDelegate, so the test delegate did not build for
iOS. Two calls also used main actor API in a closure that runs off the
main thread, which gave warnings. They now go through the Objective-C
runtime, as the other calls in the file do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TranscriptText: the view keeps both mathCache and mathAccessibilityLabel, and sets the cache before the renderer.
TranscriptTextView: the view keeps mathCache and contentSettled(), and then mathAccessibilityLabel.
TranscriptTextView.point(inside:with:): the check runs on the main thread from any thread, and a block that scrolls sideways takes touches.
TranscriptTextView: the UITextInput methods run on the main thread, and every geometry call uses the side scroll of the blocks.
TranscriptTextView+Accessibility: the elements come from the layout items, and a block element that scrolls sideways answers a three-finger swipe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@servercimen
servercimen added this pull request to stack #44 November 24, 2026 20:57
@servercimen
servercimen removed this pull request from stack #44 November 24, 2026 21:01
@servercimen
servercimen added this pull request to stack #45 November 24, 2026 21:01
@servercimen
servercimen merged commit 2451443 into main Nov 24, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant