Skip to content

Animate tags in text that is complete when it shows, and keep pills on one line - #38

Merged
servercimen merged 16 commits into
feature/code-scrollfrom
feature/tags
Nov 24, 2026
Merged

servercimen merged 16 commits into
feature/code-scrollfrom
feature/tags

Conversation

@servercimen

Copy link
Copy Markdown
Owner

Part 8 of a stack of 13 pull requests. The base is #37 (feature/code-scroll). #31 (part 1) tells how to merge the stack.

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

Summary

Apps use custom tags for pills, mentions and other marks in text. Before this change, tags animated only when they closed in streamed text. Waiting tags were dropped when the view left its window, and a hidden view played them. A pill could break across two lines, and a shape above the first line was cut.

  • Add public initializers to InlineSpan.CustomTag: init(_:attributes:) and init(name:attributes:decoration:). Add InlineSpan(range:tagged:), which makes a span as the parser does, with the traits and the link of the decoration.
  • Add animation(for:in:) to TranscriptAnimationRecipe, with TranscriptAnimationGroup: the index of the tag among the tags that start together, and their count. By default it calls animation(for:).
  • Add TranscriptTagImage(showsDuringAnimation:). The image then shows while the tag is open, waits and plays.
  • Add TranscriptDecoration(keepsTogether:). A tag that does not fit at the end of a line goes to the next line as a whole, also in table cells. A tag wider than a line, or with a line break in it, still breaks.
  • Start the first tile TranscriptPath.maximumOverhang (6 pt) above the view, so a pill on the first line is not cut.
  • With .whenVisible or .whenRequested, keep tags waiting while the view is out of its window.
  • With .whenVisible, treat a hidden view, or a view with an alpha of 0, as not visible. This includes the views above it. The view looks again after 0.25 s, 0.5 s, and then each second.
  • Add TranscriptTextView.animatesTagsInFirstText and .animatesTagsInFirstText() on TranscriptText. Each closed tag in the first text plays one time, with the timing of the view.
  • Keep waiting and playing tags through a relayout of the same text. A playing tag whose glyphs move plays again from the start.
  • Fix streamed text in a padded tag at the end of the text. The line above is laid out again, so it can take back the last word.

Tests

  • swift test on macOS: 199 tests pass. 20 new tests cover app-made spans, the group order, the tag image, keep-together lines, the first tile, and the rules for waiting tags.
  • iOS: a local test app builds with this branch for an iPhone (Release), with no warnings in the package sources.

Checked on an iPhone 12 mini

iOS 27.0, in a check screen in a local test app. The check ran on main first. Main showed each problem, except for the spans from code: on main those initializers are internal.

  • First text: main plays 0 tags. With animatesTagsInFirstText, the branch plays 3 tags 0 to 33 ms after the view shows (SwiftUI and UIKit).
  • Window: when the view comes back into its window, main shows the pills at rest. The branch plays 2 after playTagAnimations().
  • Hidden view: main plays while the view is hidden, at alpha 0, or under SwiftUI .opacity(0). The branch plays 0 while hidden, and plays less than 1 s after the view shows.
  • Stagger: on main, all tags move in the same frame. On the branch, they start 0.15 s apart.
  • Tag image: main shows no image while the tag waits and plays. The branch shows it.
  • Spans from code draw the same pixels as parser spans, and their link opens.
  • Keep together: the branch gives 1 rect for a pill, a pill with a word after it, and a table cell. Main gives 2, 2 and 3. Streamed text matches a layout from scratch in 28 of 28 texts (main 26).
  • Above the first line: the branch draws 680 red pixels in the 6 pt band. Main draws 0.
  • Relayout: a playing tag that does not move plays on through 4 width changes. Main ends it at the first change.

Stand-ins: play counts come from the recipe and from debug log lines. Motion times come from Core Animation values, not from a screen recording. A tap is a call to the tap handler of the view. Scrolling sets contentOffset. animatesTags = false stands in for Reduce Motion.

Not checked

  • Whether a person sees flicker while centered text resizes during a tag animation.
  • Reduce Motion itself.
  • A real tap and real scrolling with a finger.

Known limits

  • In centered text, a width change on each frame restarts the animation of a tag on each frame. The tag plays after the resize stops. On the phone, 30 frames of width changes gave 31 starts.

🤖 Generated with Claude Code

servercimen and others added 15 commits November 23, 2026 17:11
An app can now build a tagged document without the parser.
InlineSpan.CustomTag takes a tag definition and its attributes, or a name
and a decoration. A span made with a custom tag gets the decoration's
traits, and its link when the span has no link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A recipe can now implement animation(for:in:) to stagger tags whose
animations start at the same moment, for example when the stream
finishes. The group gives the tag's index in text order and the number
of tags. By default the recipe's animation(for:) is used.

The view orders waiting tags by their block's place in the document. It
no longer compares block ids as text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tag image with showsDuringAnimation shows while the tag is open, while
it waits for its animation, and while the animation plays. By default the
image still shows with the tag's shapes, once the animation has played.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A decoration with keepsTogether does not break across two lines. When
the tag does not fit at the end of a line, the line ends before the tag,
and the tag starts the next line. A tag wider than a line, or with a line
break in it, still breaks. Table cells follow the same rule.

While text streams, a tag that went down a line can grow wider than a
line. Its lines and the line above them are then laid out again, so the
result is the same as a layout from scratch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first tile now starts TranscriptPath.maximumOverhang (6 pt) above
the view. A shape that reaches above the first line, such as a pill on
the first line of a view with no padding, is no longer cut. The bottom of
the first tile stays where it was, so a short text's tile still covers
the glyphs below its last line.

The tail that draws streamed text can also start above the view, so the
shape shows while text streams in too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With a timing that has whenVisible or whenRequested, tags that wait for
their animation now go on waiting when the view leaves its window. They
play when the view is back in a window and the timing lets them. Tags
that close while the view is out of its window wait too. Before, all of
them were drawn at rest.

A view out of its window now plays no animation, for every timing. The
choice of which waiting tags can play moves to WaitingTags, so that it
can be tested on macOS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tag that waits for whenVisible no longer plays while the view, or a
view or layer above it, is hidden or has an alpha of 0. Before, only the
nearest scroll view was checked.

Nothing tells the view when an ancestor shows again. So while tags wait
for a hidden view in a window, the view looks again every 0.25 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With animatesTagsInFirstText on (animatesTagsInFirstText() in SwiftUI),
each closed tag with an animation in the first text that the view shows
plays its animation one time, as if it had just closed. This works for a
document set directly or built with TranscriptDocument(blocks:), whose
blocks are settled. The timing applies, so with whenVisible each tag
plays when it comes on screen. Off by default.

A relayout of the same text, for example when an image arrives or the
width changes, now keeps the waiting tags waiting. Before, they were
drawn at rest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The table cell test now also lays out a plain pill at the same widths.
It breaks at one width or more, so the test shows that keepsTogether
keeps it whole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fit test for a tag that keeps together now measures the width of the
tag's own text. Before, it asked for a line break from the tag's start
over the rest of the text. When text without a space follows the tag,
that break falls inside the tag, so a tag that fits was cut.

A line that starts with such a tag now holds all of it. A tag with a
line break in its text still breaks.

A table column is now at least as wide as a tag in it that keeps
together, as it is at least as wide as its longest word.

A layout that reuses lines now steps back one line only when the line
starts where a tag that keeps together starts. A line that starts
inside such a tag stays, because the tag already breaks there. Before,
each streamed update laid out again every line of a long open tag.

A layout that reuses lines also steps back one line when a padded tag
runs to the end of the text. The padding is on the last character, so
the last word can go down a line for the padding alone. When more text
comes, the line above can take the word back. This also applies to a
padded tag that does not keep together.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tagged:)

InlineSpan.init is the same as before again: it keeps the traits and
the link that the caller gives. Before, it added the custom tag
decoration's traits and link, and the customTag setter did not, so the
two ways to make a span gave different spans.

The new InlineSpan(range:tagged:) makes a span as the parser makes it:
with the tag's decoration, its traits and its link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A relayout of the same text, as for a new width or style, or for an
image, code colors or a formula that arrived, now keeps the tag
animations:

- A playing tag whose glyphs stay where they were goes on playing.
- A playing tag whose glyphs move plays again from the start.
- A waiting tag goes on waiting.

Before, the relayout ended every playing animation. So a first text
with a code block, an image or a formula next to its tags lost its
animation right after it started.

Only the view's own relayout keeps the animations. A new document that
is not an append draws every tag at rest, as the docs say. Before, any
document that extended the old one kept its waiting tags.

animatesTagsInFirstText now also works when the first text comes as an
append to an empty layout while the engine has animations off, for
example while the view is out of its window. The view holds back the
closed tags that the engine did not start or hold.

WaitingTags.carried makes these choices, so that they have tests on
macOS.

The view now remembers where each waiting tag is until the next layout.
A scroll with .whenVisible looked up every waiting tag on each frame.
Tags that start together now find their blocks in one pass.

A view that waits for a hidden ancestor now looks again less often:
after 0.25 s, then 0.5 s, then every second. A scroll or a layout starts
again at 0.25 s. Before, it looked every 0.25 s for as long as it
stayed hidden.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The comment in LayoutEngine.relayout said that the view shows every tag at rest after a relayout. The view now tells the engine again which tags wait or play.

The doc comment of InlineSpan.customTag now says which spans also hold the tag's traits and link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BlockLayout.layOutText: a line that wraps ends where the typesetter says, and lineEnd keeps a tag with keepsTogether on one line.
BlockLayout.layOutText: a line that does not wrap ends at its line break, and room(at:) gives the leading padding in both cases.
TranscriptTextView.didMoveToWindow: the view stops the sideways deceleration, then finishes the animations and shows the waiting tags at rest.
TranscriptTextView.startAnimation: the check that shows a tag at rest in a block that scrolls sideways moves into the function for one tag, which takes the layout.
TagImageTests: the draw call gives highContrast: false.

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 a9c199a into main Nov 24, 2026
1 of 6 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