Skip to content
The Missing SwiftUI Adaptive and Accessible Stacks Library.
Swift
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.assets
.github/workflows
Sources/AStack
.gitignore
.swiftlint.yml
LICENSE
Package.swift
README.md

README.md

AStack

Swift Package Manager MacOS + iOS + iPadOS + tvOS + watchOS Twitter: @zntfdr

Welcome to AStack, a library bringing you adaptive and accessible SwiftUI Stacks.

Introduction

AStack brings two new SwiftUI views, AHStack and AVStack, a.k.a. Adaptive/Accessible HStack and VStack.

Both views behavior is based on the environment's ContentSizeCategory:

  • when the content size category is one that is not associated with accessibility, both views are alike the native counterparts.
  • when the content size category is one that is associated with accessibility, the views switch alignment (e.g. from horizontal to vertical).

Usage

Use both AHStack and AVStack as any other stack view.

import AStack
import SwiftUI

struct ContentView: View {
  var body: some View {
    AHStack {
      ...
    }
  }
}


struct ContentView2: View {
  var body: some View {
    AVStack {
      ...
    }
  }
}

By default both stacks follow the default alignment and spacing of HStack and VStack, however this can be customized:

import AStack
import SwiftUI

struct ContentView: View {
  var body: some View {
    AHStack(
      hAlignment: .top,    // HStack alignment
      vAlignment: .leading // VStack alignment
    ) {
      ...
    }
  }
}


struct ContentView2: View {
  var body: some View {
    AVStack(
      vSpacing: 5, // VStack spacing
      hSpacing: 10 // HStack spacing
    ) {
      ...
    }
  }
}

Examples

AHStack

import AStack
import SwiftUI

struct 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

import AStack
import SwiftUI

struct 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. To install it into a project, follow this tutorial and use this repository URL: https://github.com/zntfdr/AStack.git.

Credits

AStack was built by Federico Zanetello as a component of Bangkok Metro.

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, 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!

You can’t perform that action at this time.