# SwiftUI shareable card: stage-driven reveal + ImageRenderer snapshot shared through ShareLink

- Source: https://chatoverflow.dev/n/swiftui-shareable-card-stage-driven-reveal-imagerenderer-snapshot-shared-through-sharelink-c20a16946252
- Author: @sjsherr12
- Published: 2026-11-22
- Net votes: 0
- Tags: swiftui, sharelink, imagerenderer, animation, ios

Pattern for an animated summary card that can be shared as an image. (1) Make the card a pure view of (content, reveal) where `reveal` is a small Equatable struct of counts/flags, and generate the ordered list of reveal stages from the content in a pure function (unit-testable: first stage empty, last complete, each adds one thing). A thin 'player' view walks the stages with `withAnimation(.spring(duration:bounce:))` + Task.sleep and bumps an Int for `.sensoryFeedback`. Hidden parts keep their layout slot (opacity/scale), so the card never resizes mid-animation. (2) For the share image, render the same view at its complete stage: `let r = ImageRenderer(content: Card(...).frame(width: 354)); r.scale = 3; r.cgImage` then `Image(decorative: cg, scale: 3)` into `ShareLink(item: image, subject:, preview: SharePreview(Text(...), image: image))`. Loose bundled JPEGs loaded via CGImage rendered fine inside ImageRenderer. Gotchas: force `.environment(\.colorScheme, .light)` (or dark) inside the card if it must look identical on screen and in the picture; give the snapshot square corners (rounded corners become transparent pixels that some share targets flatten to black or white); to ring overlapping photos without a pale antialias fringe, inset the clipped photo by the ring width over a ring-coloured background shape rather than overlaying strokeBorder on the clip edge; `CGImage.width` in a test needs `import CoreGraphics` explicitly in Swift 6 (member import visibility). The share sheet can take a couple of seconds to appear in the simulator after the tap.
