Repository navigation
Replace a document at once, with a crossfade - #41
Merged
Merged
Conversation
DocumentUpdate decides how a view takes a document that the app sets. A document that does not add to the one before goes to the main thread when the app asks for it. An append, and the first text after an empty document, stay on the background path. LayoutEngine.submit takes schedulesLayout. When it is false, the queue does not lay out the request, because the main thread calls relayout at once. This prevents a second layout of the same document. Tests cover the choice, the height of the new layout, and an append after a replacement. An opt-in test times the main-thread call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TranscriptTextView gets replacementCrossfadeDuration, and TranscriptText gets crossfadesReplacedText(_:duration:). With a duration, the view lays out a replaced document on the main thread in the document setter. Then sizeThatFits gives the new height in the same SwiftUI update. A fade CATransition on the canvas crossfades from the old drawing to the new one. Appends and streams keep the background path. The default is nil, so the behavior does not change for current apps. A signpost in Points of Interest marks each main-thread replacement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Launch the demo with -replacementCheck to swap a short text and a long text in a card every two seconds. Add -crossfade to turn on the new option. The console shows each swap and each height change of the card, with the time from the swap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The view adds the fade transition to its layer itself, so it does not depend on UIView.areAnimationsEnabled. The crossfade then also plays in a SwiftUI update that turns off UIKit animations, if one does. An app that wants no crossfade sets a duration of zero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add -animatedSwap to -replacementCheck to swap the text inside withAnimation. The card's height then animates, and a screenshot during the animation shows whether the red bar under the card moves with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A drain that was already scheduled took a request that the main thread lays out. The main thread then waited for that layout and laid out the same document again. The engine now marks such a request, and a drain leaves it for relayout. A replacement with no crossfade, and a background install that is not an append, now remove a crossfade that still runs. The README and the doc comments now say that a text that starts with the old one, with the same block ids, and the first text after an empty document only add text. They do not crossfade. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Core Animation keeps every CATransition under the key kCATransition, whatever key the add call gets. The view added the fade under its own key, so the remove calls did not find it. A zero-duration replacement, a background install that is not an append, and a replacement out of the window then left the old fade on the canvas. The text from before the first replacement showed over the new text until that fade ended. The view now adds and removes the fade with kCATransition. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The crossfade shows the old drawing until it ends. When the new text is shorter, the view gets its new height at once, but the old text showed below the view, over the content that follows it. When the view grows in an animation, the new text showed below the view too. The canvas is now in a container view. While a crossfade plays, the container clips to the bounds, widened by the space that tags' shapes may draw in. The clip ends with the crossfade, or when the view stops the crossfade or leaves the window. Outside a crossfade, nothing is clipped, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TranscriptTextView: the file keeps both the side scroll logger and the replacement signposter. TranscriptTextView.didMoveToWindow: the view does the side scroll and tag steps, and then stops the crossfade. TranscriptTextView: the file keeps both helper classes, SideScrollFrameTarget and CrossfadeEnd. 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 11 of a stack of 13 pull requests. The base is #40 (
feature/right-to-left). #31 (part 1) tells how to merge the stack.On this stacked branch,
swift testpasses (379 tests), and the iOS build and build-for-testing pass.Summary
An app that swaps one complete text for another, such as a summary for its details, needs the new height in the same SwiftUI update and a smooth change of text. Before this change, a new document always went to the layout queue. Until that layout was installed,
sizeThatFits(_:)gave the old height, and the new text then appeared with no transition. The new option is off by default.TranscriptTextView.replacementCrossfadeDuration(nil by default) andTranscriptText.crossfadesReplacedText(_:duration:)(0.25 s by default). With a duration, thedocumentsetter lays out a replaced document on the main thread at once.sizeThatFits(_:)andintrinsicContentSizethen give the new height in the same update. Zero shows the new text at once.CATransitionon the canvas layer crossfades from the old drawing to the new drawing. During the fade, the drawing is clipped to the view's bounds plus the space that tag shapes can draw in, so the old text does not show below a view that got shorter.kCATransition, the key that Core Animation uses.TranscriptDocument.extends(_:)) keeps the background path, as stream updates do. The README tells apps to parse a summary and its details with different id prefixes.-replacementCheck). The README has a new section, "Replacing the text".Tests
swift teston macOS: 188 tests pass. The newReplacementTestscover the choice of path, the new height, and the queue that must not lay out a replacement.xcodebuild build -scheme TranscriptKit -destination 'generic/platform=iOS'(Xcode 27.2) succeeds with no warnings.Checked on an iPhone 12 mini
A check screen in a local test app swapped a short text and a long text. The height, SwiftUI and picture checks ran on main first and showed the problem.
withAnimation, the height moves smoothly, with no stretched glyphs. Tag shapes outside the view fade with the text and are not cut.Round 1 found two problems on the branch. A zero-duration swap, a background install and a removal from the window did not stop a running crossfade, and the old text showed below a view that got shorter. Round 2, with the
kCATransitionkey and the clip, showed no fade after these cases, and the clip only during a fade. The main run of round 2 stopped when the phone disconnected, so the main results come from round 1.Not checked
Known limits
UIAccessibility.isReduceMotionEnabledis true. The view then still lays out the new text at once, with no fade. A nil duration sends the text back to the background path.🤖 Generated with Claude Code