Skip to main content
.galleryItem(id: string): Component
id
string
required
A unique identifier for this gallery item. This id is passed to the parent .gallery() detail callback when the item is tapped.

Support

Usage

Apply .galleryItem() to each child that should be tappable within a .gallery() parent.
VStack([
    Image({ url: "sunset.jpg" })
        .frame({ width: 120, height: 120 })
        .clipShape(RoundedRectangle(8))
        .galleryItem("sunset"),
    Image({ url: "mountain.jpg" })
        .frame({ width: 120, height: 120 })
        .clipShape(RoundedRectangle(8))
        .galleryItem("mountain")
]).gallery((id) =>
    Image({ url: id + ".jpg" })
        .resizable()
        .scaledToFit()
)

Notes

  • This modifier must be used inside a component that has the .gallery() modifier applied. Without a parent gallery, it has no effect.
  • Each id should be unique within the gallery so the detail callback can identify which item was selected.

See Also

  • gallery — wraps children in a full-screen photo gallery