SPB Git

Repository Public MIT

glass-popover.md 3.1 KB 72 lines markdown

1# GlassPopover23| | |4|---|---|5| Identifier | `glass-popover` |6| Module | `SPGlassComponents` |7| Kind | `native-wrapper` — the system `.popover`; the system draws the popover and its glass |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Containers/GlassPopoverExample.swift` |1011## Minimal usage1213```swift14GlassIconButton(systemImage: "info", accessibilityLabel: "Details") { showsInfo = true }15    .glassPopover(isPresented: $showsInfo) {16        Text("Prices include taxes.").padding()17    }18```1920## Variants2122| `compactAdaptation` | In a compact size class (iPhone, narrow iPad window) |23|---|---|24| `.automatic` (default) | The system's choice: a sheet. |25| `.popover` | Stays a popover with its arrow. For short content. |26| `.sheet` | A sheet. |27| `.fullScreenCover` | A full-screen cover. |2829In a regular size class and on macOS the popover is always a popover.3031## Parameters3233| Parameter | Type | Default | Meaning |34|---|---|---|---|35| `isPresented` | `Binding<Bool>` | — | Presentation state. |36| `title` | `LocalizedStringKey?` | `nil` | Heading shown above the content. |37| `attachmentAnchor` | `PopoverAttachmentAnchor` | `.rect(.bounds)` | Where the popover is attached on the source view. |38| `arrowEdge` | `Edge?` | `nil` | Preferred edge carrying the arrow; `nil` lets the system choose. |39| `compactAdaptation` | `GlassPopoverAdaptation` | `.automatic` | See Variants. |40| `content` | `@ViewBuilder` | — | Content; it supplies its own padding. |4142## States4344Presented or not, owned by the host. When the popover is adapted to a sheet or a cover, a close button appears in a title row above the content (`GlassPopoverAdaptation.needsCloseButton(isCompact:platform:)`).4546## Advanced example4748```swift49GlassButton("Sort", systemImage: "arrow.up.arrow.down") { showsSort = true }50    .glassPopover(isPresented: $showsSort, title: "Sort by", attachmentAnchor: .point(.bottom), arrowEdge: .top, compactAdaptation: .popover) {51        Picker("Sort by", selection: $order) {52            ForEach(SortOrder.allCases) { Text($0.title).tag($0) }53        }54        .pickerStyle(.inline)55        .labelsHidden()56        .padding()57    }58```5960## Accessibility6162- A real popover is dismissed by tapping outside, by Escape and by the VoiceOver escape gesture; all are the system's.63- An adapted popover has no outside area: the added close button uses the system close role (symbol and localised label supplied by the system) and answers Escape on a hardware keyboard.64- The title carries the header trait.6566## Limits6768- The close-button rule reads the size classes of the presented content. In a compact height with a regular width (some iPhones in landscape) the system may keep a popover while the rule shows the button; the button is then redundant but harmless.69- The system may place the arrow on another edge than `arrowEdge` when there is no room.70- GlassKit adds no surface; do not add glass inside the popover.71- The adaptation was compiled for iOS and macOS; the rule deciding the close button is unit-tested, the presentation was not exercised in a running application by the automated tests.72
Files main
Menu

Theme