Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomdai/quicklookpreview
QuickLook Preview for SwiftUI on Mac Catalyst
https://github.com/tomdai/quicklookpreview
mac-catalyst maccatalyst quicklook swiftui
Last synced: 7 days ago
JSON representation
QuickLook Preview for SwiftUI on Mac Catalyst
- Host: GitHub
- URL: https://github.com/tomdai/quicklookpreview
- Owner: tomdai
- License: unlicense
- Created: 2021-12-22T00:47:33.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-22T01:32:59.000Z (almost 3 years ago)
- Last Synced: 2024-11-02T14:42:05.908Z (14 days ago)
- Topics: mac-catalyst, maccatalyst, quicklook, swiftui
- Language: Swift
- Homepage:
- Size: 7.81 KB
- Stars: 15
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QuickLook Preview for SwiftUI on Mac Catalyst
According to the documentation for [`QLPreviewController`](https://developer.apple.com/documentation/quicklook/qlpreviewcontroller):
> For Mac apps built with Mac Catalyst, presenting a `QLPreviewController` displays the preview in a [`QLPreviewPanel`](https://developer.apple.com/documentation/quicklookui/qlpreviewpanel) and dims the previously active window.This package provides a way to present the preview that doesn't dim the window.
⚠️ This package is designed for and only tested on Mac Catalyst apps.
![screen-recording](https://user-images.githubusercontent.com/5054148/147019774-dccba616-129b-45a2-bc40-0fa16acf3c10.gif)
## Basic Usage
```swift
.quickLookPreview(_ items: Binding<[QuickLookPreviewItem]>, at index: Binding = Binding.constant(0))
```Add the line above to a view. When `$items` is populated with `QuickLookPreviewItem`s, the preview is presented.
## Full Example
Note that the example uses files named `1.png`, `2.png`, and `3.png` in the Xcode project.
```swift
import SwiftUIstruct ContentView: View {
@State private var items: [QuickLookPreviewItem] = []
@State private var index = 0
var body: some View {
ZStack {
Button("Present QuickLook Preview") {
// Workaround needed because there's no way to know when the preview window is dismissed.
if self.items.isEmpty {
fillItems()
} else {
Task {
self.items = []
do { try await Task.sleep(nanoseconds: 0) } catch { fillItems() }
fillItems()
}
}
}
}
.quickLookPreview(self.$items, at: self.$index)
}
func fillItems() {
self.items = [
QuickLookPreviewItem(url: Bundle.main.url(forResource: "1", withExtension: "png")!, title: "No. 1"),
QuickLookPreviewItem(url: Bundle.main.url(forResource: "2", withExtension: "png")!, title: "No. 2"),
QuickLookPreviewItem(url: Bundle.main.url(forResource: "3", withExtension: "png")!, title: "No. 3"),
]
self.index = 2
}
}
```