Giter Club home page Giter Club logo

async-swift-ui's Introduction

treastrain/AsyncSwiftUI

MIT License Swift: 5.9 Swift Package Manager compatible Platform: iOS 15.0+ | iPadOS 15.0+ | macOS 12.0+ | Mac Catalyst 15.0+ | tvOS 15.0+ | watchOS 8.0+ | visionOS 1.0+ Twitter: @treastrain

Wrappers for Swift Concurrency asynchronous actions on controls that enable user interaction specific to each platform and context provided by SwiftUI.

It's based on the following post: https://zenn.dev/treastrain/articles/3effccd39f4056

AsyncSwiftUI_README

Features

  • ✅ Designed for Swift Concurrency and SwiftUI.
  • ✅ Compatible with all Apple platforms (iPhone, iPod touch, iPad, Mac, Apple TV, Apple Watch, Apple Vision Pro).
  • ✅ Automatically cancels the task and performs a new action on new user interaction.
  • ✅ Automatically cancels the task after the view disappears before the action completes.
  • ✅ Supports Sendable and inherits the Actor context.
  • ✅ No dependencies.

Samples

import AsyncSwiftUI

struct ContentView: View {
    @State private var isRunning = false
    
    var body: some View {
        AsyncButton(isRunning ? "Running..." : "Run") {
            isRunning = true
            defer { isRunning = false }
            do {
                print("START")
                try await Task.sleep(for: .seconds(2))
            } catch {
                print("ERROR:", error)
            }
            print("FINISH")
        }
        .disabled(isRunning)
    }
}

Installation

To use this library in a Swift Package Manager project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/treastrain/AsyncSwiftUI", from: "0.1.0"),

Include "AsyncSwiftUI" as a dependency for your executable target:

.target(name: "<target>", dependencies: [
    .product(name: "AsyncSwiftUI", package: "AsyncSwiftUI"),
]),

Finally, add import AsyncSwiftUI to your source code (or replace the existing import SwiftUI with it).

Components

Controls and indicators

SwiftUI AsyncSwiftUI Available on
Button AsyncButton iOS 15.0+, iPadOS 15.0+, macOS 12.0+, Mac Catalyst 15.0+, tvOS 15.0+, watchOS 8.0+, visionOS 1.0+
EditButton (No need)
PasteButton 🚧
RenameButton 🚧
Link (No need)
ShareLink (No need)
TextFieldLink AsyncTextFieldLink watchOS 9.0+
HelpLink 🚧
Slider 🚧
Stepper 🚧
Toggle 🚧
Picker (No need)
DatePicker (No need)
MultiDatePicker (No need)
ColorPicker (No need)
Gauge (No need)
ProgressView (No need)
ContentUnavailableView (No need)

Menus and commands

SwiftUI AsyncSwiftUI Available on
Menu 🚧
MenuButton (No need)
PullDownButton (No need)
CommandMenu (No need)
CommandGroup (No need)

Note

The documentation comments included in this library, with some exceptions, are from the SwiftUI entry in the Apple Developer Documentation.

async-swift-ui's People

Contributors

treastrain avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.