Coder Social home page Coder Social logo

astack's Introduction

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 introduces four new SwiftUI views:

  • AHStack
  • AVStack
  • LazyAHStack
  • LazyAVStack

Their behavior is based on the environment's ContentSizeCategory and/or 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:

import AStack
import SwiftUI

struct 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:

import AStack
import SwiftUI

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

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!

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.