Overloads
2 ways to call compose().popover(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().popover({
isPresented: Binding<boolean>,
attachmentAnchor?: SwiftUI.PopoverAttachmentAnchor,
arrowEdge?: SwiftUI.Edge | null,
content: ReactNode,
})@export(implementation) nonisolated func popover<Content>(
isPresented: Binding<Bool>,
attachmentAnchor: PopoverAttachmentAnchor = .rect(.bounds),
arrowEdge: Edge? = nil,
@ContentBuilder content: @escaping () -> Content
) -> some View
where Content : ViewParameters
options.isPresented*Binding<boolean>A binding to a Boolean value that determines whether to present the popover content that you return from the modifier's
contentclosure.options.attachmentAnchorSwiftUI.PopoverAttachmentAnchorThe positioning anchor that defines the attachment point of the popover. The default is
Anchor.Source.bounds.options.arrowEdgeSwiftUI.Edge | nullThe edge of the
attachmentAnchorthat defines the location of the popover's arrow. The default isnil, which results in the system allowing any arrow edge.options.content*ReactNodeA closure returning the content of the popover.
Discussion
Use this method to show a popover with contents that are a SwiftUI view, which you provide when
a bound Boolean variable is true. In the example below, a popover displays whenever the user
toggles the isShowingPopover state variable by pressing the "Show Popover" button:
struct PopoverExample: View {
@State private var isShowingPopover = false
```swift
var body: some View {
Button("Show Popover") {
self.isShowingPopover = true
}
.popover(isPresented: $isShowingPopover) {
Text("Popover Content")
.padding()
}
}
}
> **Important:** Prior to iOS 18.1, the popover arrow edge was not
respected. Apps that are re-compiled with the iOS 18.1 or later SDK or
visionOS 2.1 or later SDK and run on iOS 18.1 or later or visionOS 2.1
or later have the arrow edge respected. On macOS, arrow edge has always
been respected. Alternatively, to allow the system to choose the
best orientation of the popover's arrow, use the
[`View.popover(isPresented:attachmentAnchor:content:)`](/docs/modifiers/popover) variant.
On iPhone, popovers adapt into sheets. In vertically compact environments, such as iPhone in
landscape orientation, a popover presentation automatically adapts to appear as a
full-screen cover. Use the [`View.presentationCompactAdaptation(_:)`](/docs/modifiers/presentationcompactadaptation) or
[`View.presentationCompactAdaptation(horizontal:vertical:)`](/docs/modifiers/presentationcompactadaptation) modifier to
override this behavior.
### Breakthrough effect
In visionOS, most system presentations appear with a breakthrough effect by
default. To change how the enclosing presentation breaks through
content occluding it, use `presentationBreakthroughEffect(_:)`,
like in the following example:
```swift
.popover(isPresented: $isShowingPopover) {
Text("Popover Content")
.padding()
.presentationBreakthroughEffect(.prominent)
}See also
More in Presentation.
- alertPresents an alert when a given condition is true, using a localized string resource for the title.
- confirmationDialogPresents a confirmation dialog when a given condition is true, using a localized string resource for the title.
- contextMenuAdds an item-based context menu to a view.
- dialogIconConfigures the icon used by dialogs within this view.
- dialogSuppressionToggleEnables user suppression of dialogs and alerts presented within self, with a custom suppression message on macOS. Unused on other platforms.
- dismissalConfirmationDialogPresents a confirmation dialog upon an attempt to dismiss the window for this view.
- documentBrowserContextMenuAdds to a DocumentLaunchView actions that accept a list of selected files as their parameter.
- fileDialogBrowserOptionsOn macOS, configures the fileExporter, fileImporter, or fileMover to provide a refined URL search experience: include or exclude hidden files, allow searching by tag, etc.
- fileDialogConfirmationLabelOn macOS, configures the fileExporter, fileImporter, or fileMover with a custom confirmation button label.
- fileDialogCustomizationIDOn macOS, configures the fileExporter, fileImporter, or fileMover to persist and restore the file dialog configuration.
- fileDialogDefaultDirectoryConfigures the fileExporter, fileImporter, or fileMover to open with the specified default directory.
- fileDialogImportsUnresolvedAliasesOn macOS, configures the fileExporter, fileImporter, or fileMover behavior when a user chooses an alias.