Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/c-villain/popoverpresenter
Demo SwiftUI-project with custom alerts/popovers
https://github.com/c-villain/popoverpresenter
popover sheet swift swiftui swiftui-example swiftui-popover swiftui-popup
Last synced: about 1 month ago
JSON representation
Demo SwiftUI-project with custom alerts/popovers
- Host: GitHub
- URL: https://github.com/c-villain/popoverpresenter
- Owner: c-villain
- License: mit
- Created: 2022-01-30T13:43:02.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-30T14:40:46.000Z (almost 2 years ago)
- Last Synced: 2024-10-30T17:20:41.424Z (about 2 months ago)
- Topics: popover, sheet, swift, swiftui, swiftui-example, swiftui-popover, swiftui-popup
- Language: Swift
- Homepage: https://t.me/swiftui_dev
- Size: 686 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PopoverPresenter
[![Latest release](https://img.shields.io/github/v/release/c-villain/PopoverPresenter?color=brightgreen&label=version)](https://github.com/c-villain/PopoverPresenter/releases/latest)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fc-villain%2FPopoverPresenter%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/c-villain/PopoverPresenter)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fc-villain%2FPopoverPresenter%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/c-villain/PopoverPresenter)
[![](https://img.shields.io/badge/SPM-supported-DE5C43.svg?color=brightgreen)](https://swift.org/package-manager/)
![](https://img.shields.io/github/license/c-villain/PopoverPresenter)[![contact: @lexkraev](https://img.shields.io/badge/contact-%40lexkraev-blue.svg?style=flat)](https://t.me/lexkraev)
[![Telegram Group](https://img.shields.io/endpoint?color=brightgreen&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fswiftui_dev)](https://telegram.dog/swiftui_dev)👨🏻💻 Feel free to subscribe to channel **[SwiftUI dev](https://t.me/swiftui_dev)** in telegram.
Demo project with tutorial how to customize alerts or popovers in SwiftUI based on [this article](https://medium.com/@ihamadfuad/swiftui-present-sheet-from-anywhere-using-environment-6104b2bd7d4e).
Before starting highly recommended to read [SwiftUI Custom Environment Values](https://useyourloaf.com/blog/swiftui-custom-environment-values/).
## Installation
To use PopoverPresenter with a project targeting iOS 13, simply copy folder `Source` into your project.
#### Swift Package Manager
To integrate PopoverPresenter into your project using SwiftPM add the following to your `Package.swift`:
```swift
dependencies: [
.package(url: "https://github.com/c-villain/PopoverPresenter", from: "0.1.0"),
],
```## Quick start
1. Import library to your root-file view:
```swift
import PopoverPresenter
```
2. Init instance in root view:
```swift
@StateObject var popoverPresenter = PopoverPresenter()
```
3. Add modifier to root-object view:
```swift
.environment(\.popoverPresenterKey, popoverPresenter)
.customPopover(item: $popoverPresenter.activePopover) { popover in
switch popover {
default:
popoverPresenter.currentPopover
}
}
```
4. In child view create link to environment key:
```swift
@Environment(\.popoverPresenterKey) var popoverPresenter
```
5. In child view create view with alert:
```swift
popoverPresenter.currentPopover = AnyView(Text("This is alert!"))
popoverPresenter.activePopover = .any
```You may look iOS example in package for guide steps above.