### SwiftUI Horizontal Flow Layout (HFlow) Example Source: https://context7.com/tevelee/swiftui-flow/llms.txt Demonstrates how to use HFlow to create a horizontal layout that wraps views to new lines when horizontal space is exceeded. It takes alignment, item spacing, and row spacing as parameters. This is useful for tag clouds or lists of items that need to adapt to available width. ```swift import SwiftUI import Flow struct TagsView: View { let tags = ["Swift", "SwiftUI", "iOS", "macOS", "Xcode", "Development"] var body: some View { HFlow(alignment: .top, itemSpacing: 8, rowSpacing: 12) { ForEach(tags, id: \.self) { tag in Text(tag) .padding(.horizontal, 12) .padding(.vertical, 6) .background(Color.blue) .foregroundColor(.white) .cornerRadius(16) } } .frame(maxWidth: 300) .padding() } } ``` -------------------------------- ### SwiftUI Vertical Flow Layout (VFlow) Example Source: https://context7.com/tevelee/swiftui-flow/llms.txt Illustrates the use of VFlow for creating a vertical layout that wraps views into new columns when vertical space is exceeded. It allows customization of alignment, item spacing, and column spacing, suitable for arranging items in a grid-like fashion that adapts to height. ```swift import SwiftUI import Flow struct VerticalTagsView: View { let colors: [Color] = [.red, .blue, .green, .orange, .purple, .pink] var body: some View { VFlow(alignment: .leading, itemSpacing: 8, columnSpacing: 12) { ForEach(colors.indices, id: \.self) { index in RoundedRectangle(cornerRadius: 8) .fill(colors[index]) .frame(width: 60, height: CGFloat.random(in: 40...80)) } } .frame(maxHeight: 400) .padding() } } ``` -------------------------------- ### HFlowLayout - Direct Usage for Advanced SwiftUI Composition Source: https://context7.com/tevelee/swiftui-flow/llms.txt Demonstrates using HFlowLayout directly as a Layout for advanced SwiftUI composition. It takes alignment, item spacing, row spacing, justification, and distribution options. Dependencies include SwiftUI and Flow. Outputs a horizontally flowing layout of views. ```swift import SwiftUI import Flow struct AdvancedLayoutView: View { let items = Array(1...15) var body: some View { // Using HFlowLayout as a Layout directly let flowLayout = HFlowLayout( alignment: .center, itemSpacing: 8, rowSpacing: 12, justified: false, distributeItemsEvenly: true ) flowLayout { ForEach(items, id: \.self) { item in Text("\(item)") .font(.system(size: 16, weight: .medium)) .foregroundColor(.white) .frame(width: 40, height: 40) .background(Color.blue) .clipShape(Circle()) } } .frame(width: 300) .padding() } } ``` -------------------------------- ### SwiftUI HFlow Manual Line Breaks Source: https://context7.com/tevelee/swiftui-flow/llms.txt Shows how to insert manual line breaks in `HFlow` layouts using either the `LineBreak()` view or the `.startInNewLine()` modifier. Requires SwiftUI and the Flow library. Useful for precise layout control. ```swift import SwiftUI import Flow struct LineBreakView: View { var body: some View { VStack(spacing: 20) { // Using LineBreak() HFlow(itemSpacing: 8) { RoundedRectangle(cornerRadius: 10) .fill(.red) .frame(width: 50, height: 50) RoundedRectangle(cornerRadius: 10) .fill(.green) .frame(width: 50, height: 50) RoundedRectangle(cornerRadius: 10) .fill(.blue) .frame(width: 50, height: 50) LineBreak() RoundedRectangle(cornerRadius: 10) .fill(.yellow) .frame(width: 50, height: 50) } .frame(width: 300) // Using startInNewLine() HFlow(itemSpacing: 8) { RoundedRectangle(cornerRadius: 10) .fill(.red) .frame(width: 50, height: 50) RoundedRectangle(cornerRadius: 10) .fill(.green) .frame(width: 50, height: 50) .startInNewLine() RoundedRectangle(cornerRadius: 10) .fill(.blue) .frame(width: 50, height: 50) } .frame(width: 300) } .padding() } } ``` -------------------------------- ### SwiftUI HFlow Right-to-Left Support Source: https://context7.com/tevelee/swiftui-flow/llms.txt Demonstrates `HFlow`'s automatic adaptation to right-to-left (RTL) layout environments by setting the `layoutDirection` environment variable. Requires SwiftUI and the Flow library. ```swift import SwiftUI import Flow struct RTLFlowView: View { let colors: [Color] = [.blue, .orange, .green, .yellow, .brown, .mint] var body: some View { VStack(spacing: 20) { Text("Left-to-Right") HFlow { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: 50, height: 50) } } .frame(maxWidth: 300) .environment(\.layoutDirection, .leftToRight) Text("Right-to-Left") HFlow { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: 50, height: 50) } } .frame(maxWidth: 300) .environment(\.layoutDirection, .rightToLeft) } .padding() } } ``` -------------------------------- ### HFlow Basic Usage in SwiftUI Source: https://github.com/tevelee/swiftui-flow/blob/main/README.md Demonstrates the basic implementation of HFlow to arrange views horizontally, wrapping to new lines when elements exceed the bounding space. It requires the 'Flow' package. ```swift import Flow struct Colors: View { let colors: [Color] = [ .blue, .orange, .green, .yellow, .brown, .mint, .indigo, .cyan, .gray, .pink ] var body: some View { HFlow { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: .random(in: 40...60), height: 50) } } .frame(maxWidth: 300) } } ``` -------------------------------- ### SwiftUI Justified HFlow Layout Source: https://context7.com/tevelee/swiftui-flow/llms.txt Demonstrates how to use `HFlow(justified: true)` to stretch spacing between items, filling the entire row width and creating aligned edges. Requires SwiftUI and the Flow library. ```swift import SwiftUI import Flow struct JustifiedFlowView: View { let items = ["Apple", "Banana", "Cherry", "Date", "Elderberry", "Fig", "Grape"] var body: some View { HFlow(justified: true) { ForEach(items, id: \.self) { item in Text(item) .padding(.horizontal, 12) .padding(.vertical, 8) .background(Color.blue.opacity(0.3)) .cornerRadius(8) } } .frame(width: 300) .border(Color.blue, width: 2) .padding() } } ``` -------------------------------- ### SwiftUI Flow Layout Distributed Item Distribution Source: https://context7.com/tevelee/swiftui-flow/llms.txt Explains and shows how to use the `distributeItemsEvenly` flag in HFlow to apply the Knuth-Plass line breaking algorithm. This optimizes item distribution across rows to minimize empty space, creating more balanced layouts. ```swift import SwiftUI import Flow struct DistributedFlowView: View { let colors: [Color] = [.blue, .orange, .green, .yellow, .brown, .mint, .indigo, .cyan] var body: some View { VStack(spacing: 20) { // Without distribution HFlow { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: 65, height: 50) } } .frame(width: 300, alignment: .leading) // With even distribution HFlow(distributeItemsEvenly: true) { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: 65, height: 50) } } .frame(width: 300, alignment: .leading) } } } ``` -------------------------------- ### HFlow Flexibility Configuration in SwiftUI Source: https://github.com/tevelee/swiftui-flow/blob/main/README.md Explains how to control the flexibility of items within an HFlow, allowing them to take up space proportionally based on minimum, natural, or maximum flexibility. Uses the 'Flow' package. ```swift HFlow { // distributes flexible items proportionally RoundedRectangle(cornerRadius: 10) .fill(.red) .frame(minWidth: 50, maxWidth: .infinity) .frame(height: 50) .flexibility(.minimum) // takes as little space as possible, rigid RoundedRectangle(cornerRadius: 10) .fill(.green) .frame(minWidth: 50, maxWidth: .infinity) .frame(height: 50) .flexibility(.natural) // expands RoundedRectangle(cornerRadius: 10) .fill(.blue) .frame(minWidth: 50, maxWidth: .infinity) .frame(height: 50) .flexibility(.natural) // expands RoundedRectangle(cornerRadius: 10) .fill(.yellow) .frame(minWidth: 50, maxWidth: .infinity) .frame(height: 50) // takes as much space as possible .flexibility(.maximum) } .frame(width: 300) ``` -------------------------------- ### HFlow Alignment Options in SwiftUI Source: https://github.com/tevelee/swiftui-flow/blob/main/README.md Shows how to configure alignment for HFlow, similar to HStack and VStack, including single-axis and dual-axis alignment for elements. Uses the 'Flow' package. ```swift HFlow(alignment: .top) { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: 50, height: .random(in: 40...60)) } } .frame(maxWidth: 300) ``` ```swift HFlow(horizontalAlignment: .center, verticalAlignment: .top) { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: .random(in: 30...60), height: 30) } } .frame(maxWidth: 300) ``` -------------------------------- ### SwiftUI HFlow Item Flexibility Control Source: https://context7.com/tevelee/swiftui-flow/llms.txt Illustrates controlling item expansion/contraction in `HFlow` using `.flexibility()` modifiers: `.minimum`, `.natural`, and `.maximum`. Requires SwiftUI and the Flow library. Items are defined with `minWidth` and `maxWidth`. ```swift import SwiftUI import Flow struct FlexibilityView: View { var body: some View { HFlow(itemSpacing: 8) { // Minimum flexibility - takes minimal space RoundedRectangle(cornerRadius: 10) .fill(.red) .frame(minWidth: 50, maxWidth: .infinity) .frame(height: 50) .flexibility(.minimum) // Natural flexibility - expands proportionally RoundedRectangle(cornerRadius: 10) .fill(.green) .frame(minWidth: 50, maxWidth: .infinity) .frame(height: 50) .flexibility(.natural) RoundedRectangle(cornerRadius: 10) .fill(.blue) .frame(minWidth: 50, maxWidth: .infinity) .frame(height: 50) .flexibility(.natural) // Maximum flexibility - takes maximum available space RoundedRectangle(cornerRadius: 10) .fill(.yellow) .frame(minWidth: 50, maxWidth: .infinity) .frame(height: 50) .flexibility(.maximum) } .frame(width: 300) .padding() } } ``` -------------------------------- ### HFlow Even Item Distribution in SwiftUI Source: https://github.com/tevelee/swiftui-flow/blob/main/README.md Demonstrates how to evenly distribute items within each row of an HFlow layout to minimize empty space, utilizing the Knuth-Plass line breaking algorithm. Uses the 'Flow' package. ```swift HFlow(distributeItemsEvenly: true) { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: 65, height: 50) } } .frame(width: 300, alignment: .leading) ``` -------------------------------- ### FlexibilityBehavior Enum - Controlling View Expansion in Flow Layouts Source: https://context7.com/tevelee/swiftui-flow/llms.txt Illustrates the FlexibilityBehavior enum (.minimum, .natural, .maximum) to control how views expand within flow layouts. This affects their proportional or maximum space occupation. Dependencies include SwiftUI and Flow. Input is a state variable controlling the picker selection. ```swift import SwiftUI import Flow struct FlexibilityOptionsView: View { @State private var flexMode: FlexibilityBehavior = .natural var body: some View { VStack(spacing: 20) { Picker("Flexibility", selection: $flexMode) { Text("Minimum").tag(FlexibilityBehavior.minimum) Text("Natural").tag(FlexibilityBehavior.natural) Text("Maximum").tag(FlexibilityBehavior.maximum) } .pickerStyle(.segmented) HFlow(itemSpacing: 8) { ForEach(0..<4) { _ in RoundedRectangle(cornerRadius: 8) .fill(Color.blue) .frame(minWidth: 40, maxWidth: .infinity) .frame(height: 40) .flexibility(flexMode) } } .frame(width: 300) } .padding() } } ``` -------------------------------- ### SwiftUI Flow Layout Custom Spacing Source: https://context7.com/tevelee/swiftui-flow/llms.txt Demonstrates how to set custom spacing between items and rows/columns in an HFlow layout. This allows for fine-grained control over the layout's density and visual appearance, differentiating it from default spacing. ```swift import SwiftUI import Flow struct CustomSpacingView: View { let colors: [Color] = [.blue, .orange, .green, .yellow, .brown, .mint] var body: some View { HFlow(itemSpacing: 4, rowSpacing: 20) { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: 50, height: 50) } } .frame(maxWidth: 300) .padding() } } ``` -------------------------------- ### HFlow Justified Layout in SwiftUI Source: https://github.com/tevelee/swiftui-flow/blob/main/README.md Illustrates how to create a justified HFlow layout where items are stretched to fill the available horizontal space. Requires the 'Flow' package. ```swift HFlow(justified: true) { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: 50, height: 50) } } .frame(width: 300) ``` -------------------------------- ### HFlow Line Break Controls in SwiftUI Source: https://github.com/tevelee/swiftui-flow/blob/main/README.md Demonstrates explicit control over line breaks within an HFlow layout using `LineBreak()` and `.startInNewLine()` modifiers. Requires the 'Flow' package. ```swift HFlow { RoundedRectangle(cornerRadius: 10) .fill(.red) .frame(width: 50, height: 50) RoundedRectangle(cornerRadius: 10) .fill(.green) .frame(width: 50, height: 50) RoundedRectangle(cornerRadius: 10) .fill(.blue) .frame(width: 50, height: 50) LineBreak() RoundedRectangle(cornerRadius: 10) .fill(.yellow) .frame(width: 50, height: 50) } .frame(width: 300) ``` ```swift HFlow { RoundedRectangle(cornerRadius: 10) .fill(.red) .frame(width: 50, height: 50) RoundedRectangle(cornerRadius: 10) .fill(.green) .frame(width: 50, height: 50) .startInNewLine() RoundedRectangle(cornerRadius: 10) .fill(.blue) .frame(width: 50, height: 50) RoundedRectangle(cornerRadius: 10) .fill(.yellow) .frame(width: 50, height: 50) } .frame(width: 300) ``` -------------------------------- ### VFlow Basic Usage in SwiftUI Source: https://github.com/tevelee/swiftui-flow/blob/main/README.md Illustrates the fundamental usage of VFlow for vertical arrangement of views, with automatic line breaks. This component is part of the 'Flow' package. ```swift VFlow { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: 50, height: .random(in: 40...60)) } } .frame(maxHeight: 300) ``` -------------------------------- ### SwiftUI Flow Layout Dual-Axis Alignment Source: https://context7.com/tevelee/swiftui-flow/llms.txt Shows how to configure both horizontal and vertical alignment within an HFlow layout. This provides precise control over how items are positioned along both axes, enabling complex and aesthetically pleasing arrangements. ```swift import SwiftUI import Flow struct CenteredTagsView: View { let items = ["Short", "Medium Length", "Very Long Tag Name", "Tiny"] var body: some View { HFlow( horizontalAlignment: .center, verticalAlignment: .top, horizontalSpacing: 10, verticalSpacing: 8 ) { ForEach(items, id: \.self) { item in Text(item) .padding(8) .background(Color.gray.opacity(0.2)) .cornerRadius(4) } } .frame(width: 250) .border(Color.gray, width: 1) } } ``` -------------------------------- ### Adapt HFlow to Right-to-Left Layout Source: https://github.com/tevelee/swiftui-flow/blob/main/README.md This Swift code snippet demonstrates how to configure an HFlow to render correctly in a right-to-left layout environment. It iterates through a collection of colors, creating a RoundedRectangle for each, and applies the layout direction environment modifier to the HFlow. No external dependencies are required beyond standard SwiftUI. ```swift HFlow { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: .random(in: 40...60), height: 50) } } .frame(maxWidth: 300) .environment(\.layoutDirection, .rightToLeft) ``` -------------------------------- ### HFlow Spacing Customization in SwiftUI Source: https://github.com/tevelee/swiftui-flow/blob/main/README.md Details how to customize spacing between items and rows independently in an HFlow layout. Requires the 'Flow' package. ```swift HFlow(itemSpacing: 4, rowSpacing: 20) { ForEach(colors, id: \.description) { color in RoundedRectangle(cornerRadius: 10) .fill(color.gradient) .frame(width: 50, height: 50) } } .frame(maxWidth: 300) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.