GithubHelp home page GithubHelp logo

josscii / wrappinghstack Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ksemianov/wrappinghstack

0.0 1.0 0.0 14 KB

WrappingHStack (FlowLayout) is a SwiftUI component similar to HStack that wraps horizontally overflowing subviews onto the next lines.

License: MIT License

Ruby 7.54% Swift 92.46%

wrappinghstack's Introduction

WrappingHStack

A SwiftUI component similar to HStack that wraps horizontally overflowing subviews onto the next lines.

Overview

The library is based on the SwiftUI's Layout protocol and thus has the following deployment requirement:

iOS 16.0+, iPadOS 16.0+, macOS 13.0+, Mac Catalyst 16.0+, tvOS 16.0+, watchOS 9.0+

The component's signature:

WrappingHStack(alignment: Alignment = .center,
               horizontalSpacing: CGFloat? = nil,
               verticalSpacing: CGFloat? = nil,
               fitContentWidth: Bool = false)

The component, by default, uses the .center alignment, but also supports the following alignment values: .center, .leading, .topLeading, .top, .topTrailing, .trailing, .bottomTrailing, .bottom, .bottomLeading. The rest are treated as .center.

The component, by default, uses the system provided spacing, but it's also possible to specify explicit horizontalSpacing and verticalSpacing.

The component, by default, spans the entire available width. However, you can set fitContentWidth to true to make it adjust its width based on its content.

The component assumes that the largest subview fits into the bounds and there are no infinitely growing subviews. The component assumes that it can grow vertically as much as necessary to fit into the width constraint.

Examples

An array of tags:

WrappingHStack

WrappingHStack(alignment: .leading) {
    ForEach(tags) {
        Text($0.text)
            .foregroundColor(Color.white)
            .padding(.horizontal, $0.horizontalPadding)
            .padding(.vertical, $0.verticalPadding)
            .background(Color.gray)
            .cornerRadius(16)
    }
}

Installation

You can add WrappingHStack to an Xcode project by adding it as a package dependency.

https://github.com/ksemianov/WrappingHStack

If you want to use WrappingHStack in a SwiftPM project, it's as simple as adding it to a dependencies clause in your Package.swift:

dependencies: [
    .package(url: "https://github.com/ksemianov/WrappingHStack", from: "0.2.0")
]

If you want to use WrappingHStack in a CocoaPods project, add this line to your Podfile:

'WrappingHStackLayout', '~> 0.2.0'

License

This library is released under the MIT license. See LICENSE for details.

wrappinghstack's People

Contributors

ksemianov avatar

Watchers

 avatar

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.