Flow

1.2.3

A flow view for SwiftUI
toastersocks/Flow

What's New

v1.2.3

2024-03-03T21:43:45Z

This fixes an alignment issue where views could be be misplaced when using a non-leading alignment. This occurred when the bounds proposed was non-zero, which is common when a Layout is used inside another layout container.

Flow


A layout for placing views in a flow-like arrangement in SwiftUI. A Flow organizes views sequentially, wrapping them onto new lines when the current line is filled. The alignment and spacing between views can be customized. Flow layouts are commonly used to display a set of tags.

Left-aligned tags. Right-aligned tags. Multi-colored rectangles languidly animating between different alignments. Multi-colored rectangles bordered in teal enthusiastically and jauntily animating between different alignments.

Using Flow is similar to using SwiftUI's VStack and HStack layouts/views. Alignment and spacing changes can be animated and since Flow conforms to the Layout protocol you can even animate changing to an entirely different layout type!

Usage

import Flow

struct ContentView: View {
    @State var tags: [Tag]

    var body: some View {
        // Default .topLeading alignment and system spacing.
        Flow { 
            ForEach(tags) { tag in
                TagView(tag)
            }
        }
        // Alignment and spacing specified.
        Flow(alignment: .bottomTrailing, spacing: 10) {
            ForEach(tags) { tag in
                TagView(tag)
            }
        }
    }
}

Check the documentation for more in-depth usage.

Installing

Swift Package Manager

Via Xcode

  • Select your .xcproject file
  • Select the project under PROJECT
  • Select Swift Package
  • Tap the + sign
  • Paste this repo's address https://github.com/toastersocks/Flow into the text field and hit 'Next'
  • Choose your version/branch on the next screen
  • Choose your targets and hit 'Finish'

Description

  • Swift Tools 5.8.0
View More Packages from this Author

Dependencies

Last updated: Mon Dec 09 2024 03:31:27 GMT-1000 (Hawaii-Aleutian Standard Time)