Easily show HUDs with SwiftUI! Lightweight SwiftUI wrapper for JGProgressHUD for iOS, tvOS, Catalyst.

Overview

JGProgressHUD-SwiftUI

This is a lightweight and easy-to-use SwiftUI wrapper for JGProgressHUD, giving you access to the large and proven feature set of JGProgressHUD. Supports iOS, macCatalyst and tvOS 14.0+.

GitHub license SwiftPM compatible Mac Catalyst compatible

Installation

JGProgressHUD-SwiftUI can only be used with the Swift Package Manager.

In Xcode, use the menu File > Swift Packages > Add Package Dependency... and enter the package URL https://github.com/JonasGessner/JGProgressHUD-SwiftUI.git.

Usage

This package builds on top of the UIKit-based JGProgressHUD and provides a trivial way of showing HUDs in SwiftUI code.

You use the view JGProgressHUDPresenter as a canvas, which can display HUDs over its contents. Generally you want to use a single JGProgressHUDPresenter view as the root view of your application, such that full screen HUDs can be displayed.

To show a HUD from any contained view, define the environment object of type JGProgressHUDCoordinator in your view struct. This object is automatically available in the environment via JGProgressHUDPresenter. Call its showHUD(constructor:handleExistingHUD:) method, providing a constructor closure that returns the HUD to show. The returned HUD will be shown automatically, hence you do not need to call the show() method on the HUD. You may already schedule the HUD to disappear using the dismiss(afterDelay:) method.

The handleExistingHUD closure is only called in case a HUD is already presented. You can, for example, dismiss the current HUD and return true to continue showing the new HUD. By returning false (default), you prevent the new HUD from being shown.

You may furthermore access, modify or dismiss a HUD that is already presented by accessing the presentedHUD property of the JGProgressHUDCoordinator environment object. After a HUD dismisses, this property is automatically reset to nil.

Example

Also see the Example Project.

import SwiftUI
import JGProgressHUD_SwiftUI
 
struct NavigationBody: View {
    // This environment object is automatically set by JGProgressHUDPresenter.
    @EnvironmentObject var hudCoordinator: JGProgressHUDCoordinator

    var body: some View {
        Button("Press Me") {
            // Simply call showHUD and return your HUD!
            hudCoordinator.showHUD {
                let hud = JGProgressHUD()
                hud.textLabel.text = "Hello!"
                hud.dismiss(afterDelay: 3)

                return hud
            }
        }
    }
}

struct ContentView: View {
    var body: some View {
        // This presenter can present a fullscreen HUD.
        JGProgressHUDPresenter {
            NavigationView {
                NavigationBody()
            }
        }
    }
}

Requirements

  • Deployment target of iOS/tvOS/macCatalyst 14.0 or higher.

Detailed Documentation

Please see the JGProgressHUD project for documentation on JGProgressHUD itself.

See the doc strings in JGProgressHUD_SwiftUI.swift for more info.

License

MIT License.
© 2020, Jonas Gessner.

Credits

Created and maintained by Jonas Gessner, © 2020.

You might also like...
Multiple Arcade Machine Emulator for iOS, iPadOS, tvOS, macOS (Catalyst)
Multiple Arcade Machine Emulator for iOS, iPadOS, tvOS, macOS (Catalyst)

MAME4iOS Original Author: David Valdeita (Seleuco) This is a port of MAME for iOS, iPadOS, tvOS and macOS. MAME4iOS is designed to run for modern iOS

Show the confetti only when the user is having fun, and if not having fun, don't show it.
Show the confetti only when the user is having fun, and if not having fun, don't show it.

SPConfetti - A simple solution to show the confetti to the user. Smoothly starts and stops. Allow set multiply diffrent particles at once. You can chang

Easily show RichText(html) in SwiftUI
Easily show RichText(html) in SwiftUI

RichText LightMode DarkMode Code import SwiftUI

 SwiftUI App Icon Generator App for iOS & macOS Catalyst
SwiftUI App Icon Generator App for iOS & macOS Catalyst

SwiftUI App Icon Generator App for iOS & macOS Catalyst Generate Asset Icons easily to your iPhone, iPad, Mac, and Apple Watch Features The app has se

Easily hide and show a view controller's navigation bar (and tab bar) as a user scrolls
Easily hide and show a view controller's navigation bar (and tab bar) as a user scrolls

HidingNavigationBar An easy to use library (written in Swift) that manages hiding and showing a navigation bar as a user scrolls. Features Usage Custo

Demonstrates hosting SwiftUI in a UISplitViewController to gain the sidebar style in Mac Catalyst
Demonstrates hosting SwiftUI in a UISplitViewController to gain the sidebar style in Mac Catalyst

Really trivial example showing how to wrap SwiftUI in a UISplitViewController, so that you can use the correct sidebar background style when building for macOS.

Demonstration of using UIWindowScene and SwiftUI to provide a native-looking Mac preferences window in Catalyst
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

Advanced Catalyst Example with sidebar, list view, SwiftUI detail view, toolbar & AppKit bundle
Advanced Catalyst Example with sidebar, list view, SwiftUI detail view, toolbar & AppKit bundle

Advanced Catalyst Example This is an example of a Catalyst app using a three-column layout, with a primary toolbar. It includes topics such as: Drag &

QuickLook Preview for SwiftUI on Mac Catalyst
QuickLook Preview for SwiftUI on Mac Catalyst

QuickLook Preview for SwiftUI on Mac Catalyst According to the documentation for

CatalystMenuBarStatusWindow - A method of presenting UIKit (or Catalyst-specific SwiftUI) content from the status menu area on macOS
UIPredicateEditor aims to be come a drop-in replacement of NSPredicateEditor for iOS, iPadOS and Mac Catalyst targets.

UIPredicateEditor UIPredicateEditor aims to be come a drop-in replacement of NSPredicateEditor for iOS, iPadOS and Mac Catalyst targets. The plan is t

A nano-sized weather station based on a Raspberry Pi with an API, iOS & Mac Catalyst app, and sensor-based automations.
A nano-sized weather station based on a Raspberry Pi with an API, iOS & Mac Catalyst app, and sensor-based automations.

Nanotool A nano-sized weather station based on a Raspberry Pi with an API, iOS & Mac Catalyst app, and sensor-based automations. Descriere Vremea este

A SwiftUI dynamic property wrapper for fetching media from your photo library. (iOS, tvOS, macOS)

Media Also available as a part of my SwiftUI+ Collection – just add it to Xcode 13+ A package for simplifying the user of the camera and the user's ph

Demonstration of how to integrate AppleScript/Cocoa scripting into a Catalyst app
Demonstration of how to integrate AppleScript/Cocoa scripting into a Catalyst app

CatalystAppleScript Trivial demonstration showing how to build support for AppleScript into a Catalyst app. Showcases multiple commands and variables

Exposing macOS Services through a Catalyst app
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

Work in progress gallery of controls available to Catalyst apps using Optimized for Mac
Work in progress gallery of controls available to Catalyst apps using Optimized for Mac

Catalyst Controls Gallery Very simple work-in-progress demonstration of many common controls available to Mac Catalyst as of macOS 11. Provided moreso

Creating a blurred window background in Mac Catalyst
Creating a blurred window background in Mac Catalyst

TransparentChrome In response to a developer question, I looked for the easiest way to provide a translucent full-window chrome with a blurred backgro

Grid-based app for macOS Catalyst (Mac Idiom) with navigation stack
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-

Comments
  • How to show in .sheet pages?

    How to show in .sheet pages?

    The ContentView is wrapped with JGProgressHUDPresenter and showing some HUDs, presenting a .sheet page (eg.: some PreferencesView) which is also wrapped with another JGProgressHUDPresenter. Calling show() in the sheet page only shows the HUD in the content view, behind the sheet view itself. (observed from Xcode view hierarchy) Passing the hudCoordinator from ContentView to .sheet(), instead of wrapping .sheet with JGProgressHUDPresenter, does not help. Any ideas on this? Or is there another (correct) way to show the HUD? Thanks! (Falling back to use objc JGProgressHUD now)

    opened by xsown 1
  • Reacting to state changes

    Reacting to state changes

    As I see the current state of art, I need to do dismiss(afterDelay: ) with the hud. What about dismissing it with when there is a change in a property of a view model. Let's say I want to hide after fetching is completed. I am doing it this way, I don't know whether it is a good approach or not.

               hudCoordinator.showHUD {
                        let hud = JGProgressHUD()
                        hud.textLabel.text = "Fetching Profile Details....."
                        hud.textLabel.font = UIFont(name: FontConstants.poppinsMedium, size: 12)
                        hud.backgroundColor = UIColor(white: 0, alpha: 0.4)
                        viewModel.$fetchedCompleted.sink { completed in
                            if completed {
                                hud.dismiss()
                            }
                        }.store(in: &viewModel.subscription)
                        return hud
                    }
    
    

    Can anybody guide me with this?

    opened by ravisharmaa 0
Releases(0.1.1)
A Circular SwiftUI progress View

A Circular progress view. There are some controllers to let you customize the progress-view and see which one works better for you. This whole project

Mahdi Bahrami 8 May 7, 2022
A number of preset loading indicators created with SwiftUI

ActivityIndicatorView A number of preset loading indicators created with SwiftUI We are a development agency building phenomenal apps. Usage Create an

Exyte 956 Dec 26, 2022
AsyncView is a SwiftUI View for handling in-progress and error states when loading data asynchronously.

AsyncView AsyncView is a SwiftUI View for handling in-progress and error states when loading data asynchronously using async/await: See my blog post "

Ralf Ebert 41 Dec 20, 2022
PBCircularProgressView is a circular progress view for iOS similar to the app store download progress view.

Overview PBCircularProgressView is a circular progress view for iOS similar to the app store download progress view. It also ha

null 0 Oct 27, 2021
GaugeProgressViewStyle adds the Apple Watch gauge view to iOS.

GaugeProgressViewStyle adds the Apple Watch gauge view to iOS. Installation To install GaugeProgressViewStyle, add GaugeProgressViewStyle as a depende

null 29 Jul 28, 2022
A simple circular progress view for iOS

CircularProgress A simple circular progress view for iOS. TODOs Gradient Colors Shadow Paths & Colors Multiplied Progress (i.e. progress > 1.0) Usage

i_82 10 Nov 11, 2022
Snake Progress shows circular progress for iOS Apps.

SnakeProgress SnakeProgress shows circular progress for iOS Apps. With SnakeProgress With SnakeProgress, you can easily circular progress. @IBOutlet w

null 8 Sep 22, 2022
SwiftyStoreKit is a lightweight In App Purchases framework for iOS, tvOS, watchOS, macOS, and Mac Catalyst ⛺

SwiftyStoreKit is a lightweight In App Purchases framework for iOS, tvOS, watchOS, macOS, and Mac Catalyst. Features Super easy-to-use block-based API

Andrea Bizzotto 6.1k Jan 7, 2023
Mercato is a lightweight In-App Purchases (StoreKit 2) library for iOS, tvOS, watchOS, macOS, and Mac Catalyst.

Mercato Mercato is a lightweight In-App Purchases (StoreKit 2) library for iOS, tvOS, watchOS, macOS, and Mac Catalyst. Installation Swift Package Man

Pavel T 49 Jan 4, 2023
🚀 Create XCFrameworks with ease! A Command Line Tool to create XCFramework for multiple platforms at one shot! The better way to deal with XCFrameworks for iOS, Mac Catalyst, tvOS, macOS, and watchOS.

Surmagic ?? Create XCFramework with ease! A Command Line Tool to create XCFramework for multiple platforms at one shot! The better way to deal with XC

Muhammed Gurhan Yerlikaya 260 Dec 28, 2022