https://github.com/lepips/alwayspopover
Native popover on iOS in SwiftUI
https://github.com/lepips/alwayspopover
Last synced: 8 months ago
JSON representation
Native popover on iOS in SwiftUI
- Host: GitHub
- URL: https://github.com/lepips/alwayspopover
- Owner: LePips
- License: mit
- Created: 2023-11-12T04:16:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-12T04:21:45.000Z (over 2 years ago)
- Last Synced: 2025-04-06T06:43:25.539Z (about 1 year ago)
- Language: Swift
- Homepage:
- Size: 109 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AlwaysPopover
SwiftUI's `.popover` will perform a sheet presentation on iOS but use the expected popover presentation on iPadOS.
I needed the expected popover on iOS. Influenced by [this great blog post](https://pspdfkit.com/blog/2022/presenting-popovers-on-iphone-with-swiftui/).
## Usage
Identical to SwiftUI's `.popover`:
```swift
import AlwaysPopover
import SwiftUI
struct ContentView: View {
@State
private var presentPopover: Bool = false
var body: some View {
Button {
presentPopover = true
} label: {
Text("Present Popover!")
}
.alwaysPopover(isPresented: $presentPopover) {
Text("I'm in a popover, even on iOS!")
.padding()
}
}
}
```
Result

The popover is dismissed by:
- tapping outside the popover
- setting the presentation binding to `false`
- calling the native SwitUI `dismiss` environment action