Skip to content

winddpan/HUD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUI HUD

iOS14+ macOS13+

Demo

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-12-10.at.17.55.43.mp4

Usage

struct ContentView: View {
    @State var hudState: HUDState?

    var body: some View {
        ZStack {
            Color.clear

            VStack(spacing: 20) {
                Button("message") {
                    hudState = .message("this is title text", caption: "this is caption text")
                }

                Button("success with text") {
                    hudState = .success("this is title text", caption: "this is caption text")
                }

                Button("error with text") {
                    hudState = .error("error message")
                }

                Button("loading with text") {
                    hudState = .loading("loading message")

                    DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
                        hudState = nil
                    }
                }

                Button("success without text") {
                    hudState = .success()
                }

                Button("error without text") {
                    hudState = .error()
                }

                Button("loading without text") {
                    hudState = .loading()

                    DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
                        hudState = nil
                    }
                }

                if #available(iOS 16, *) {
                    Button("loading task") {
                        $hudState.loadingTask {
                            try await Task.sleep(for: .seconds(3))
                            throw NSError(domain: "some thing wrong", code: 0)
                        }
                    }
                }
            }
        }
        .ignoresSafeArea()
        .overlayHUD($hudState)
    }
}

About

Pure SwiftUI HUD

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages