Giter Site home page Giter Site logo

swiftui-async-button's Introduction

swiftui-async-button

Wrapper initializers for SwiftUI Button that allow async action arguments (i.e. asyncAction) instead of the built-in synchronous actions.

Usage

Add the following as a package in your Package.swift file or Xcode project:

[email protected]:rlziii/swiftui-async-button.git

Then simply import SwiftUIAsyncButton in a file that needs to use one of the new Button initializers (see below).

Initializers

All native SwiftUI Button initializers have asyncAction equivalents via this package. As in: any initializer that has an action-named parameter has an asyncAction-named parameter now as well. Therefore a Button can be used in this kind of way (or using a similar initializer):

Button("Some Title", asyncAction: someAsyncFunction)

Or using trailing-closure syntax:

Button("Some Title") {
  await someAsyncFunction()
}

Minimum Deployment Targets

macOS: 10.15
iOS/iPadOS: 13.0
tvOS: 13.0
watchOS: 6.0

However, some initializers (i.e. those with support for ButtonRole) require:

macOS: 12.0
iOS/iPadOS: 15.0
tvOS: 15.0
watchOS: 8.0

License

MIT License. See LICENSE file for more details.

swiftui-async-button's People

Contributors

rlziii avatar

Stargazers

 avatar Nikita avatar Marlon Raskin avatar

Watchers

 avatar

swiftui-async-button's Issues

Create Restartable Tasks

Currently if a Button is tapped multiple times with a previous Task still in flight, news Tasks are just created. However this is perhaps unexpected. Instead, the option of have any previous in-flight Tasks "replaced"/"restarted" should instead be an option (the default?) should be constructed.

Create More Strict Task Lifetime

Button's Task lifetime right now is non-strict, meaning that long-running tasks may exceed the lifetime of the Button itself. This may be unexpected. Therefore a mechanism should be created to fix this problem.

Note: it might be necessary to make this opt-in so that some tasks always run to completion without being cancelled prematurely.

Expose `TaskPriority` for Button Async Initializers

Currently all Button async initializers spawn a new Task with a nil priority (i.e. therefore inheriting their outer context priority). This should instead be an option to pass into the Button's created Task.

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.