QuickLook Preview for SwiftUI on Mac Catalyst

Overview

QuickLook Preview for SwiftUI on Mac Catalyst

According to the documentation for QLPreviewController:

For Mac apps built with Mac Catalyst, presenting a QLPreviewController displays the preview in a 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

Basic Usage

.quickLookPreview(_ items: Binding<[QuickLookPreviewItem]>, at index: Binding<Int> = Binding<Int>.constant(0))

Add the line above to a view. When $items is populated with QuickLookPreviewItems, the preview is presented.

Full Example

Note that the example uses files named 1.png, 2.png, and 3.png in the Xcode project.

import SwiftUI

struct 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
    }
}
You might also like...
The missing Apple Weather App for Mac.
The missing Apple Weather App for Mac.

BetterWeather The missing Weather App for your Mac and iPad. Installation for mac. Download the notarized, universal binary from here Click the curren

iCloud Drive is Apple's essential connection between all your devices, Mac, iPhone, iPad, even your Windows PC.
iCloud Drive is Apple's essential connection between all your devices, Mac, iPhone, iPad, even your Windows PC.

iCloud Drive is Apple's essential connection between all your devices, Mac, iPhone, iPad, even your Windows PC.While the cost of storage seems expensive in comparison to other online storage services, its advantage is that it works natively across all your devices.

A simple Timer app for Mac
A simple Timer app for Mac

A simple Timer app for Mac

Mac OSX app that displays window previews when hovering over app icon on the Dock.
Mac OSX app that displays window previews when hovering over app icon on the Dock.

Dock Window Preview Adds window preview functionality on hover for Mac Dock, an open-source alternative. This is very early in development and it will

🎲 100% SwiftUI 2.0, classic 2048 game [SwiftUI 2.0, iOS 14.0+, iPadOS 14.0+, macOS 11.0+, Swift 5.3].
🎲 100% SwiftUI 2.0, classic 2048 game [SwiftUI 2.0, iOS 14.0+, iPadOS 14.0+, macOS 11.0+, Swift 5.3].

swiftui-2048 If you like the project, please give it a star ⭐ It will show the creator your appreciation and help others to discover the repo. ✍️ Abou

A simple SwiftUI Application to demonstrate creation of UI using SwiftUI.
A simple SwiftUI Application to demonstrate creation of UI using SwiftUI.

WatchShop_UI A simple SwiftUI Application to demonstrate creation of UI using SwiftUI. How to run the project ? Fork the project. Run the project usin

E-commerce app built in SwiftUI. Built in the course SwiftUI Masterclass in Udemy.
E-commerce app built in SwiftUI. Built in the course SwiftUI Masterclass in Udemy.

Touchdown-SwiftUI E-commerce app built in SwiftUI. Built in the course SwiftUI Masterclass in Udemy. Main components and concepts used: @EnvironmentOb

A multiplatform SwiftUI project demonstrating various SwiftUI features.

WikiDemo A multiplatform SwiftUI project demonstrating various SwiftUI features, including creating a master-detail interface. It's a multiplatform ve

SwiftUI Projects from Udemy SwiftUI Masterclass

SwiftUI Masterclass Repos: AsyncImage (N/A) Fructus (finished): an app for getting information about different fruits. Data comes from json files. Afr

Owner
Tom Dai
Tom Dai
Demonstration of using UIWindowScene and SwiftUI to provide a native-looking Mac preferences window in Catalyst

CatalystPrefsWindow Ever wondered how to create a more Mac-like preferences window for Catalyst? Perhaps Settings Bundles are too limiting for the kin

Steven Troughton-Smith 148 Dec 27, 2022
Grid-based app for macOS Catalyst (Mac Idiom) with navigation stack

Catalyst Grid App Simple Catalyst example (Mac idiom) of a grid-based app with a push/pop navigation stack. Includes back button in toolbar that auto-

Steven Troughton-Smith 120 Nov 14, 2022
A Figma component preview for your SwiftUI views

FigmaPreviewSwiftUI A Figma component preview for your SwiftUI views. You can use Figma components instead of real views within your app until you imp

Danis Tazetdinov 50 Dec 23, 2022
PreviewDevice - library with elegant syntax for Preview Device in SwiftUI

PreviewDevice Requirements Xcode 13.x iOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+ Usage Example: import PreviewDevice struc

Anton Paliakov 32 Nov 22, 2022
Preview with Link's meta information.(SwiftUI)

LinkPreview(SwiftUI) Preview with Link's meta information. Image Gif Get Started import SwiftUI import LinkPreview struct LinkPreview_Test: View {

null 15 Dec 16, 2022
Preview with Link's meta information with SwiftUI

LinkPreview(SwiftUI) Preview with Link's meta information. Image Gif Get Started import SwiftUI import LinkPreview struct LinkPreview_Test: View {

null 15 Dec 16, 2022
Window preview app for MacOS (on the dock) using AltTab.

DockAltTab The #1 Window manager/Task switcher & Companion for AltTab v1.1 download link https://github.com/steventheworker/DockAltTab/releases/downlo

Steven G. 40 Jan 2, 2023
Mac-asksec - Test Mac Permissions from the Terminal

asksec A simple CLI to test permissions from any macOS terminal app. Building ru

Christian Zangl 1 Jan 18, 2022
Exposing macOS Services through a Catalyst app

CatalystServices This is a simple example to show how you can implement the macOS Services system in your Catalyst app. The services you expose are pr

Steven Troughton-Smith 33 Oct 26, 2022
An example project to demonstrate the new scripting capabilities of Shortcuts For Mac.

Scripting Shortcuts Test Project This simple project is designed to test the new scripting capabilities introduced in the Shortcuts app in macOS Monte

Alex Hay 16 Nov 17, 2022