Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jasonnam/AStack
The Missing SwiftUI Adaptive and Accessible Stacks Library.
https://github.com/jasonnam/AStack
a11y accessibility ios stacks swiftui swiftui-components
Last synced: 25 days ago
JSON representation
The Missing SwiftUI Adaptive and Accessible Stacks Library.
- Host: GitHub
- URL: https://github.com/jasonnam/AStack
- Owner: jasonnam
- License: mit
- Created: 2020-03-22T05:52:01.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-25T09:59:56.000Z (almost 4 years ago)
- Last Synced: 2024-11-28T13:53:09.857Z (26 days ago)
- Topics: a11y, accessibility, ios, stacks, swiftui, swiftui-components
- Language: Swift
- Homepage:
- Size: 312 KB
- Stars: 114
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Welcome to **AStack**, a library bringing you adaptive and accessible SwiftUI stacks.
## Introduction
AStack introduces four new SwiftUI views:- `AHStack`
- `AVStack`
- `LazyAHStack`
- `LazyAVStack`Their behavior is based on the [environment][environment]'s [`ContentSizeCategory`][ContentSizeCategory] and/or [`UserInterfaceSizeClass`][UserInterfaceSizeClass]:
- when the **content size** category is one that is **not** associated with accessibility, they are equivalent to SwiftUI's counterparts
- when the **content size** category is one that **is** associated with accessibility, the views switch alignment (e.g. from horizontal to vertical)
- when the associated **class size** is `.regular`, they are equivalent to SwiftUI's counterparts
- when the associated **class size** is `.compact`, the views switch alignment (e.g. from horizontal to vertical)By default all views observe just `ContentSizeCategory`, however this can be changed to observing either `ContentSizeCategory` or `UserInterfaceSizeClass`, both, or none via the `observing` parameter.
## Usage
Use any AStack view as any other stack view:
```swift
import AStack
import SwiftUIstruct ContentView: View {
var body: some View {
AHStack {
...
}
}
}@available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)
struct ContentView2: View {
var body: some View {
LazyAVStack {
...
}
}
}
```Properties such as alignment and spacing can be customized:
```swift
import AStack
import SwiftUIstruct ContentView: View {
var body: some View {
AHStack(
hAlignment: .top, // HStack alignment
vAlignment: .leading // VStack alignment
) {
...
}
}
}
```
## Examples### AHStack
```swift
import AStack
import SwiftUIstruct ContentView: View {
var body: some View {
AHStack {
ZStack {
RoundedRectangle(cornerRadius: 12).strokeBorder()
Text("1")
}
ZStack {
RoundedRectangle(cornerRadius: 12).strokeBorder()
Text("2")
}.foregroundColor(.purple)
ZStack {
RoundedRectangle(cornerRadius: 12).strokeBorder()
Text("3")
}.foregroundColor(.blue)
}
}
}
```### AVStack
```swift
import AStack
import SwiftUIstruct ContentView: View {
var body: some View {
AVStack {
ZStack {
RoundedRectangle(cornerRadius: 12).strokeBorder()
Text("1")
}
ZStack {
RoundedRectangle(cornerRadius: 12).strokeBorder()
Text("2")
}.foregroundColor(.purple)
ZStack {
RoundedRectangle(cornerRadius: 12).strokeBorder()
Text("3")
}.foregroundColor(.blue)
}
}
}
```## Installation
AStack is distributed using the [Swift Package Manager](https://swift.org/package-manager). To install it into a project, follow [this tutorial](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app) and use this repository URL: `https://github.com/zntfdr/AStack.git`.
## Credits
AStack was built by [Federico Zanetello](https://twitter.com/zntfdr) as a component of [Bangkok Metro](http://yourmetro.app).
## Contributions and Support
All users are welcome and encouraged to become active participants in the project continued development — by fixing any bug that they encounter, or by improving the documentation wherever it’s found to be lacking.
If you'd like to make a change, please [open a Pull Request](https://github.com/zntfdr/AStack/pull/new), even if it just contains a draft of the changes you’re planning, or a test that reproduces an issue.
Thank you and please enjoy using **AStack**!
[ContentSizeCategory]: https://developer.apple.com/documentation/swiftui/environmentvalues/3284540-sizecategory
[Environment]: https://developer.apple.com/documentation/swiftui/environment
[UserInterfaceSizeClass]: https://developer.apple.com/documentation/swiftui/userinterfacesizeclass