Repository navigation
fix(upscale): keep a page's ratio stable across the 2x swap - #100
Merged
Merged
Conversation
PageImage derived its box ratio from the current AsyncImagePainter state, so while the enhanced request was in Loading the ratio fell back to page.width/height (or the 0.7 default when metadata is stale/missing). In a webtoon strip the LazyColumn item is measured with an infinite height and sized by that ratio, so the fallback resized the item for a frame and moved the scroll anchor — the view jumped as the 2x bitmap replaced the source. The ratio the cell actually decoded at is now remembered per page/half and reused across model swaps; first loads still guess from metadata. The existing lastPainter fallback keeps the frame's content, so geometry and pixels are both unchanged during the swap.
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.
Problem
With waifu2x enabled, a page's scroll position could jump at the moment the enhanced bitmap replaced the source in the webtoon (continuous vertical) reader.
PageImagederives its box ratio from the current painter state:FitRatioBoxmeasures a webtoon cell with an infinite height and derives it from that ratio (fillMaxWidth().aspectRatio(ratio)). When the enhanced request starts, Coil entersLoading,decodedRatiobecomes null, and the ratio falls back topage.width/height(or0.7when the metadata is stale or missing). That resizes the cell for a frame, theLazyColumnre-anchors on visible item + pixel offset, and the view visibly moves.Content itself was already handled (
lastPainterkeeps painting the previous bitmap while the new one decodes); only the geometry was unstable.Fix
Remember the ratio the cell actually decoded at, per page and per split half, and reuse it across the source→2x model swap:
halfis part of the key), matching the existing per-half crop.Verification
./gradlew :app:compileDebugKotlin— passes../gradlew :app:testDebugUnitTest— passes.Remaining (deliberately out of scope)
page.width/height: if the server metadata ratio differs from the real bitmap, a cell's first settle still nudges the height. That is the pre-existing design trade-off, independent of upscaling.lastRatio/lastPainterare composition-local; scrolling far enough to recycle the item resets them, so a revisit re-settles from metadata once. Hoisting a reader-level per-URL ratio cache would remove that, but it needs its own decision on what to render before the first decode.