Repository Public MIT
1{2 "accessibility" : [3 "Each cell is a button labelled \"Image n of m, description\" with the image trait.",4 "In the viewer the image carries the same label and supports the VoiceOver zoom action; the buttons are labelled \"Previous\", \"Next\" and \"Close\".",5 "Keyboard: left and right arrows navigate, Escape closes.",6 "Failure is a symbol plus text. The double-tap zoom animation becomes a short fade with Reduce Motion."7 ],8 "category" : "media",9 "changelog" : [10 {11 "changes" : [12 "Release 1.1.0: see the project changelog."13 ],14 "date" : "2026-12-03",15 "version" : "1.1.0"16 },17 {18 "changes" : [19 "Initial release."20 ],21 "date" : "2026-12-02",22 "version" : "1.0.0"23 }24 ],25 "dependencies" : [26 {27 "id" : "glass-foundation",28 "version" : "1.1.0"29 },30 {31 "id" : "glass-icon-button",32 "version" : "1.1.0"33 },34 {35 "id" : "glass-media-support",36 "version" : "1.1.0"37 }38 ],39 "description" : "Lazy image grid with a zoomable viewer, navigation and cancellable loading.",40 "examples" : [41 {42 "code" : "import SwiftUI\nimport CoreGraphics\nimport SPGlassKit\n\npublic struct GlassGalleryExample: GlassExample {\n public static let componentID = \"glass-gallery\"\n\n public init() {}\n\n public var body: some View {\n VStack(alignment: .leading, spacing: 8) {\n Text(\"Sample data · drawings and gradients generated in code, one slow image and one failing image.\")\n .font(.caption)\n .foregroundStyle(.secondary)\n .padding(.horizontal)\n GlassGallery(items: Self.items, cacheCapacity: 12, layout: .featured, selection: \"drawing-1\")\n }\n }\n\n private struct SampleLoadingError: Error {}\n\n static let items: [GlassGalleryItem] = {\n let names = [\"Dawn\", \"Lagoon\", \"Orchard\", \"Ember\", \"Glacier\", \"Dusk\", \"Moss\", \"Coral\", \"Slate\", \"Saffron\", \"Iris\", \"Tundra\"]\n var items = names.enumerated().map { index, name in\n GlassGalleryItem(id: \"gradient-\\(index)\", description: \"\\(name) gradient\", loadCGImage: {\n // Stands in for decoding a file; the sleep makes cancellation observable while scrolling.\n try await Task.sleep(for: .milliseconds(index == 3 ? 1_500 : 120))\n return try gradient(hue: Double(index) / Double(names.count))\n })\n }\n // Local images, already in memory: the drawn compositions of the examples.\n for index in (0..<6).reversed() {\n items.insert(GlassGalleryItem(id: \"drawing-\\(index)\", description: SampleArtwork.title(index), image: SampleArtwork.image(index)), at: 0)\n }\n items.insert(GlassGalleryItem(id: \"broken\", description: \"An image that fails to load\", load: { throw SampleLoadingError() }), at: 8)\n return items\n }()\n\n /// Draws a diagonal two-colour gradient into a bitmap.\n nonisolated static func gradient(hue: Double, side: Int = 256) throws -> CGImage {\n let space = CGColorSpaceCreateDeviceRGB()\n guard let context = CGContext(data: nil, width: side, height: side, bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else {\n throw SampleLoadingError()\n }\n let colors = [rgb(hue: hue), rgb(hue: (hue + 0.18).truncatingRemainder(dividingBy: 1))] as CFArray\n guard let gradient = CGGradient(colorsSpace: space, colors: colors, locations: [0, 1]) else {\n throw SampleLoadingError()\n }\n context.drawLinearGradient(gradient, start: .zero, end: CGPoint(x: side, y: side), options: [])\n guard let image = context.makeImage() else { throw SampleLoadingError() }\n return image\n }\n\n /// A saturated colour for a hue in 0…1, without any platform colour type.\n nonisolated private static func rgb(hue: Double) -> CGColor {\n let sector = hue * 6\n let x = 1 - abs(sector.truncatingRemainder(dividingBy: 2) - 1)\n let (r, g, b): (Double, Double, Double) = switch Int(sector) % 6 {\n case 0: (1, x, 0)\n case 1: (x, 1, 0)\n case 2: (0, 1, x)\n case 3: (0, x, 1)\n case 4: (x, 0, 1)\n default: (1, 0, x)\n }\n return CGColor(red: 0.25 + 0.6 * r, green: 0.25 + 0.6 * g, blue: 0.25 + 0.6 * b, alpha: 1)\n }\n}\n\n#Preview(\"GlassGallery\") { GlassGalleryExample().glassTheme(.crystal) }\n",43 "title" : "GlassGallery example"44 }45 ],46 "files" : [47 {48 "bytes" : 9178,49 "path" : "Media/Media/GlassGallery+Viewer.swift",50 "sha256" : "737ca24a62cd279be92672f83b165b9625c2ee7e29e0b12df4f48c98a7c5501a"51 },52 {53 "bytes" : 14581,54 "path" : "Media/Media/GlassGallery.swift",55 "sha256" : "d01a56499f14100655c7f396bfa52d9e1f2ff7e279a77e15eb689659efd0cb75"56 }57 ],58 "frameworks" : [5960 ],61 "id" : "glass-gallery",62 "kind" : "content-component",63 "license" : "MIT",64 "minimumOS" : {65 "iOS" : "26.0",66 "iPadOS" : "26.0",67 "macOS" : "26.0"68 },69 "name" : "GlassGallery",70 "platforms" : [71 "iOS",72 "iPadOS",73 "macOS"74 ],75 "schemaVersion" : 1,76 "sha256" : "b09a4f285cb037ca46ec39d06a1470084f40ab28c211cdb913bdb1a7e8c12e83",77 "symbols" : [78 "GlassGalleryZoom",79 "GlassGalleryItem",80 "GlassGalleryLoading",81 "GlassGalleryLayout",82 "GlassGallery"83 ],84 "version" : "1.1.0"85}86