Repository navigation
Animate tags in text that is complete when it shows, and keep pills on one line - #38
Merged
Merged
Conversation
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>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 testpasses (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.
InlineSpan.CustomTag:init(_:attributes:)andinit(name:attributes:decoration:). AddInlineSpan(range:tagged:), which makes a span as the parser does, with the traits and the link of the decoration.animation(for:in:)toTranscriptAnimationRecipe, withTranscriptAnimationGroup: the index of the tag among the tags that start together, and their count. By default it callsanimation(for:).TranscriptTagImage(showsDuringAnimation:). The image then shows while the tag is open, waits and plays.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.TranscriptPath.maximumOverhang(6 pt) above the view, so a pill on the first line is not cut..whenVisibleor.whenRequested, keep tags waiting while the view is out of its window..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.TranscriptTextView.animatesTagsInFirstTextand.animatesTagsInFirstText()onTranscriptText. Each closed tag in the first text plays one time, with the timing of the view.Tests
swift teston 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.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.
animatesTagsInFirstText, the branch plays 3 tags 0 to 33 ms after the view shows (SwiftUI and UIKit).playTagAnimations()..opacity(0). The branch plays 0 while hidden, and plays less than 1 s after the view shows.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 = falsestands in for Reduce Motion.Not checked
Known limits
🤖 Generated with Claude Code