Skip to content

Commit

Permalink
chore: Add public init
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon committed Oct 24, 2024
1 parent 6b24dd8 commit ba45687
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Sources/InfomaniakCoreSwiftUI/Layouts/FlowLayout.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Infomaniak Core UI - iOS
Copyright (C) 2023 Infomaniak Network SA
Copyright (C) 2024 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -20,9 +20,15 @@ import SwiftUI

@available(iOS 16.0, *)
public struct FlowLayout: Layout {
public var alignment: HorizontalAlignment = .center
public var verticalSpacing: CGFloat = .zero
public var horizontalSpacing: CGFloat = .zero
private let alignment: HorizontalAlignment
private let verticalSpacing: CGFloat
private let horizontalSpacing: CGFloat

init(alignment: HorizontalAlignment = .center, verticalSpacing: CGFloat = .zero, horizontalSpacing: CGFloat = .zero) {
self.alignment = alignment
self.verticalSpacing = verticalSpacing
self.horizontalSpacing = horizontalSpacing
}

public func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
let (size, _) = computeLayout(proposal: proposal, subviews: subviews)
Expand Down Expand Up @@ -128,6 +134,7 @@ public struct FlowLayout: Layout {
.background(Color.blue, in: .capsule)
}
}
.border(.black)

FlowLayout(alignment: .center, verticalSpacing: 8, horizontalSpacing: 8) {
ForEach(items, id: \.self) { item in
Expand All @@ -137,6 +144,7 @@ public struct FlowLayout: Layout {
.background(Color.green, in: .capsule)
}
}
.border(.black)

FlowLayout(alignment: .trailing, verticalSpacing: 8, horizontalSpacing: 8) {
ForEach(items, id: \.self) { item in
Expand All @@ -146,7 +154,7 @@ public struct FlowLayout: Layout {
.background(Color.red, in: .capsule)
}
}
.border(.black)
}
.border(.black)
}

0 comments on commit ba45687

Please sign in to comment.