Skip to content

Crossfade a replaced document only in an animated update - #46

Merged
servercimen merged 2 commits into
mainfrom
fix/crossfade-animated-updates
Nov 25, 2026
Merged

servercimen merged 2 commits into
mainfrom
fix/crossfade-animated-updates

Conversation

@servercimen

Copy link
Copy Markdown
Owner

Summary

crossfadesReplacedText(_:duration:) crossfaded each replaced document, also in a SwiftUI update without an animation. For example, a TextField that drives a TranscriptText through a binding faded the text at each edit that was not an append, such as a deleted character. A SwiftUI view animates only in a transaction with an animation, so the fade must follow the transaction too.

  • TranscriptText.updateUIView reads context.transaction. In an update with an animation (animation is not nil and disablesAnimations is false), the view crossfades for the duration of the modifier, as before.
  • In an update without an animation, the view gets a duration of zero. It still lays out the replaced document at once, so SwiftUI gets the new height in the same update. The new text shows with no fade, as a Text does.
  • A later update without an animation, with the same document, does not stop a crossfade that plays. The document setter returns early for an equal document.
  • TranscriptTextView.replacementCrossfadeDuration (UIKit) does not change.
  • The doc comment of crossfadesReplacedText, the README section "Replacing the text", and the comment and label of the demo's -replacementCheck screen tell the new rule.

Behavior change

An app that swaps the text without an animation no longer gets a fade. To keep the fade, swap the text in withAnimation, or put .animation(_:value:) on the view. The fade duration still comes from the modifier, not from the animation of the transaction.

Tests

  • New tests in TranscriptTextTests (iOS view tests):
    • A replacement without an animation gives the new height in the same update and no crossfade.
    • A replacement in withAnimation gives the new height in the same update and a crossfade.
    • An update without an animation that only changes another setting does not stop a crossfade that plays.
  • On the code before this change, the first test fails (a crossfade plays), and the other two pass.
  • xcodebuild test -scheme TranscriptKit -only-testing:TranscriptKitViewTests on an iOS 27.2 simulator (Xcode 27.2): 24 tests run and 23 pass. TranscriptTextViewTests/aLineLimitCutsTheHeightAndTheText fails at the selected range. It fails on main too (3 of 3 runs), and it tests TranscriptTextView, which this change does not touch.
  • swift test on macOS did not run, because the change is only in iOS code.
  • In CI, the test jobs also fail on main, because RichCopyTests does not build with Xcode 26.6. This change does not fix that.

🤖 Generated with Claude Code

servercimen and others added 2 commits November 25, 2026 08:39
TranscriptText crossfaded each replaced document, also in a SwiftUI
update without an animation, for example when a binding replaced the
text at each edit. The view now crossfades only when the transaction of
the update has an animation. Without one, it still lays out the replaced
document at once, with a duration of zero, so SwiftUI gets the new
height in the same update, and the new text shows with no fade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@servercimen
servercimen merged commit 27c123c into main Nov 25, 2026
1 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