// One picture whose bytes are on this device, drawn at the size its row states.//// It was the version reader's own view, because a published version's track was// the only page that drew a stored screenshot. A note's attachment and a code// session's attachment are the other two, and a picture has to look and behave// the SAME on all of them — so this is scaffold, one view rather than three, and// the reason it reports an absence in words lives here rather than in each// caller.importCottonKitimportSwiftUI/// THREE STATES and it says all three: resolving, here, and not on this phone./// It is the one place in this lane that REPORTS a missing picture rather than/// sitting quiet, and the reason is what the picture IS: on a catalogue tile the/// photo decorates a product, and here the picture is the subject of the page.////// **MOUNTING NEVER FETCHES.** The `.task` asks `read.mediaPath` — where the/// bytes are on THIS phone — because a strip is a row of these and a shelf is a/// grid of them, and a view that called `media.ensure` as it scrolled into place/// opened the radio once per picture nobody had asked for. An absence draws/// the sentence and stays put; the one viewer (`MediaViewer`), opened by a/// tap, is what fetches.structCapturedImage: View {let key: String?let title: Stringlet width: CGFloatlet height: CGFloat/// The picture AND the key it is about: `.task(id:)` re-runs on a pop-back/// with the very same key, and this is what stops that re-run blanking a/// picture that is already decoded and drawn. @State privatevar slot = MediaImageSlot() @Environment(\.displayScale) privatevar scale/// The open database, read from the environment rather than threaded down/// the strip: this is a View, and a View is not handed a database. @Environment(\.cottonCore) privatevar database @Environment(\.tableDefinitions) privatevar definitionsvar body: someView {Group {iflet image = slot.image {Image(uiImage: image) .resizable() .scaledToFill() .accessibilityLabel(title) } elseif slot.isAbsent { absence } else {CottonColors.groundMuted } } .frame(width: width, height: height) .clipped() .clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous)) .task(id: key) { await load() }// Bytes moved on this phone: an absent picture asks again, a drawn one// does nothing. .onMediaArrival {guard !slot.isReady else { return }await load() } }/// Not on this phone: the slip. Nothing here fetches — opening the/// picture does.privatevar absence: someView { ZStack {CottonColors.groundMutedAbsentSlip(kind: .photo, words: ViewerWords.reading(definitions), compact: true) .padding(AbsentSlipKnobs.gap) } .accessibilityIdentifier("captured-image-absent") }/// The RENDER ask: where the bytes are on this phone, and never a fetch.privatefunc load() async {let number = slot.begin(key)guardlet key, !key.isEmpty, let database else { slot.finish(.absent, for: key, ask: number)return }let answer = awaitMediaImages.load( from: database, key: key, edge: max(width, height) * scale ) slot.finish(answer, for: key, ask: number) }}