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
- ✅ 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.
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)
}
}
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).
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) | ― |
SwiftUI | AsyncSwiftUI | Available on |
---|---|---|
Menu |
🚧 | ― |
MenuButton |
(No need) | ― |
PullDownButton |
(No need) | ― |
CommandMenu |
(No need) | ― |
CommandGroup |
(No need) | ― |
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
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.