Skip to content

Add an article on replacing AsyncImage with LazyImage - #1095

Merged
kean merged 1 commit into
feat/environment-pipelinefrom
docs/replacing-async-image
Nov 2, 2026
Merged

kean merged 1 commit into
feat/environment-pipelinefrom
docs/replacing-async-image

Conversation

@kean

@kean kean commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Stacked on #1094, because the session example uses .imagePipeline(_:). Merge #1094 first. If this is merged before it, the branch is merged into a branch that never reaches main: retarget this PR to main after #1094 lands, as GitHub does when that branch is deleted on merge.

A new article, replacing-async-image, for people who have AsyncImage code, or an agent that writes it, and want LazyImage. #1064 has a mapping table for it among the other libraries; this is the longer walkthrough.

  • The swap for the closure and content:placeholder: forms, and a row for every AsyncImage initializer, including the iOS 27 request: forms, which LazyImage(request:) covers from iOS 16.
  • scale, which lives on ImageRequest and defaults to 1, like AsyncImage.
  • asyncImageURLSession(_:) → imagePipeline(_:), with a DataLoader configuration that carries headers.
  • Where the behavior differs: a nil URL fails with imageRequestMissing, the error is ImagePipeline.Error, and disappearing cancels the load.
  • A LazyImageState.phase extension for code that takes an AsyncImagePhase, so a shared helper doesn't have to be rewritten.

Linked from the SwiftUI article and the topics list, and added to ARTICLE_ORDER so the llms files pick it up at the release (checked by running the generator; the generated files are not committed). Every sample is in ReplacingAsyncImageSnippets.swift, verbatim, and make snippets compiles it. make docs builds with no warnings.

Left out on purpose

Overlap with #1064. Its table says .asyncImageURLSession(_:) maps to .pipeline(_:) on each view, and its "What has no counterpart" section lists the session in the environment. Both are out of date once #1094 lands. They are two lines in a file this PR doesn't touch, so I left them.

Covers the swap for each AsyncImage initializer, where the behavior differs
(a missing URL is an error, the error is typed, disappearing cancels the load),
the environment pipeline as the counterpart of asyncImageURLSession(_:), and a
phase helper for code that takes an AsyncImagePhase. Every sample is compiled by
the documentation snippets.
@kean
kean merged commit c7fa1dc into feat/environment-pipeline Nov 2, 2026
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