Repository navigation
Crossfade a replaced document only in an animated update - #46
Merged
Merged
Conversation
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>
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.
Summary
crossfadesReplacedText(_:duration:)crossfaded each replaced document, also in a SwiftUI update without an animation. For example, aTextFieldthat drives aTranscriptTextthrough 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.updateUIViewreadscontext.transaction. In an update with an animation (animationis not nil anddisablesAnimationsis false), the view crossfades for the duration of the modifier, as before.Textdoes.documentsetter returns early for an equal document.TranscriptTextView.replacementCrossfadeDuration(UIKit) does not change.crossfadesReplacedText, the README section "Replacing the text", and the comment and label of the demo's-replacementCheckscreen 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
TranscriptTextTests(iOS view tests):withAnimationgives the new height in the same update and a crossfade.xcodebuild test -scheme TranscriptKit -only-testing:TranscriptKitViewTestson an iOS 27.2 simulator (Xcode 27.2): 24 tests run and 23 pass.TranscriptTextViewTests/aLineLimitCutsTheHeightAndTheTextfails at the selected range. It fails on main too (3 of 3 runs), and it testsTranscriptTextView, which this change does not touch.swift teston macOS did not run, because the change is only in iOS code.RichCopyTestsdoes not build with Xcode 26.6. This change does not fix that.🤖 Generated with Claude Code