Cotton code
107 lines · 4.7 KB · SwiftRaw
// The pictures on the draft — a row of small prints inside the composer card,// above the words.//// Every one is ALREADY a record (`DockModel`'s header, "Pictures on a// thought"): `capture.media` wrote it before it was drawn here, so a tile is a// photo in the library that the next send will name. Taking one off the draft// deletes nothing.//// **What is shown is what is sent** — the chips' rule, and the reason this row// WRAPS (`ChipWrap`) rather than scrolling: a picture riding the capture that// the writer cannot see is a picture they can neither check nor take off.//// **A RENDERER ASKS `read.mediaPath`.** Each print goes through `KeyedPicture`,// which draws the empty window when the bytes are not on this device and never// fetches (`MediaFetchSweepTests`). A picture captured on this device always// has its bytes here, so the window is the rare case.//// **A clip draws its still and a play mark.** `capture.media` answers the// film's key AND its still's (`posterKey`); the tile draws// `CapturedPicture.tileKey`, never the film's key, which no image decoder// reads. A clip the phone could cut no frame from draws its window.//// No new vocabulary: the print is `InstantPrint` at its thumbnail size, the// take-off control is the close circle the attachment pager already wears, and// the long-press menu says `AttachmentWords.remove`, the strip's own word.import CottonKitimport SwiftUIstruct DockPictureStrip: View {    let pictures: [CapturedPicture]    /// Pictures still on their way into the store — drawn as empty prints so a    /// person who just picked one sees it arriving rather than nothing.    let arriving: Int    /// The composer's identifier stem.    let identifier: String    let onRemove: (CapturedPicture) -> Void    /// The print's width. Wide enough to recognise a screenshot at a glance,    /// small enough that three sit beside a line of words.    static let edge: CGFloat = 64    var body: some View {        if !pictures.isEmpty || arriving > 0 {            ChipWrap(spacing: 10) {                ForEach(pictures, id: \.recordId) { picture in                    DockPictureTile(picture: picture, identifier: identifier, onRemove: onRemove)                }                ForEach(0..<max(0, arriving), id: \.self) { index in                    EmptyPrint(seed: "\(identifier)-arriving-\(index)", size: .thumb)                        .frame(width: DockPictureStrip.edge)                        .accessibilityLabel(ShellLines.line("capture", "dock.picture_on_its_way"))                }            }            .padding(.top, 6)            .accessibilityIdentifier("\(identifier)-pictures")        }    }}/// One picture on the draft, and the one verb it has: take it off.private struct DockPictureTile: View {    @Environment(\.theme) private var theme    let picture: CapturedPicture    let identifier: String    let onRemove: (CapturedPicture) -> Void    private var isFilm: Bool { picture.kind == .video }    var body: some View {        InstantPrint(seed: picture.recordId, size: .thumb) {            ZStack {                // A film's own key is not a picture — see the header.                KeyedPicture(key: picture.tileKey, edge: DockPictureStrip.edge)                if isFilm {                    Image(systemName: "play.fill")                        .font(.system(size: 16))                        .foregroundStyle(theme.print(.pencil))                }            }        }        .frame(width: DockPictureStrip.edge)        .accessibilityLabel(ShellLines.line("capture", isFilm ? "dock.film_on_thought" : "dock.picture_on_thought"))        .accessibilityAction(named: AttachmentWords.remove) { onRemove(picture) }        .overlay(alignment: .topTrailing) { remove.offset(x: 8, y: -8) }        .contextMenu {            Button(role: .destructive) { onRemove(picture) } label: {                Label(AttachmentWords.remove, systemImage: "minus.circle")            }        }        .accessibilityIdentifier("\(identifier)-picture-\(picture.recordId)")    }    /// The close circle, small — the pager's own, at the corner of the print.    private var remove: some View {        Button { onRemove(picture) } label: {            Image(systemName: "xmark")                .font(.system(size: 10, weight: .semibold))                .foregroundStyle(CottonColors.ink)                .frame(width: 22, height: 22)                .background(Circle().fill(CottonColors.groundElevated))        }        .buttonStyle(MotionButtonStyle())        .accessibilityLabel(ShellLines.line("capture", "dock.take_picture_off"))        .accessibilityIdentifier("\(identifier)-picture-remove-\(picture.recordId)")    }}