diff --git a/README.md b/README.md index 6a342a1..b214352 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,7 @@ MyFULayout().forEach(["Hello", "World"], id: \.self) { item in HMasonry(columns: 3, maxHeight: height) { ForEach(["Hello", "World", "More Text"], id: \.self) { item in Text(item.value) + .frame(maxHeight: .infinity, alignment: .center) .padding(12) .foregroundColor(.white) .background(Color.blue) @@ -255,6 +256,7 @@ MyFULayout().forEach(["Hello", "World"], id: \.self) { item in VMasonry(columns: 3, maxWidth: width) { ForEach(["Hello", "World", "More Text"], id: \.self) { item in Text(item.value) + .frame(maxWidth: .infinity, alignment: .center) .padding(12) .foregroundColor(.white) .background(Color.blue) diff --git a/Sources/FrameUp/FULayout/Layouts/HMasonry.swift b/Sources/FrameUp/FULayout/Layouts/HMasonry.swift index 313a2ac..664cd57 100644 --- a/Sources/FrameUp/FULayout/Layouts/HMasonry.swift +++ b/Sources/FrameUp/FULayout/Layouts/HMasonry.swift @@ -33,25 +33,25 @@ import SwiftUI public struct HMasonry: FULayout { typealias Row = FULayoutRow - public let alignment: Alignment + public let alignment: HorizontalAlignment public let rows: Int public let rowHeight: CGFloat - public let maxItemHeight: CGFloat? public let horizontalSpacing: CGFloat public let verticalSpacing: CGFloat + public var maxItemHeight: CGFloat? { rowHeight } public let maxItemWidth: CGFloat? = nil public let fixedSize: Axis.Set = .horizontal /// Creates a FrameUp layout that arranges views into rows, adding views to the shortest row. /// - Parameters: - /// - alignment: Used to align views vertically in their rows and align rows horizontally relative to each other. Default is leading. + /// - alignment: Used to align rows horizontally relative to each other. Default is leading. /// - rows: Number of rows to place views in. /// - maxHeight: Maximum height containing all rows (can be obtained through a `HeightReader`). /// - horizontalSpacing: Minimum horizontal spacing between columns. /// - verticalSpacing: Vertical spacing between views in a column public init( - alignment: Alignment = .leading, + alignment: HorizontalAlignment = .leading, rows: Int, maxHeight: CGFloat, horizontalSpacing: CGFloat? = nil, @@ -61,13 +61,12 @@ public struct HMasonry: FULayout { self.rows = max(1, rows) self.horizontalSpacing = horizontalSpacing ?? 10 self.verticalSpacing = verticalSpacing ?? 10 - self.maxItemHeight = (maxHeight - (self.horizontalSpacing * CGFloat(self.rows - 1))) / CGFloat(self.rows) - self.rowHeight = maxItemHeight ?? maxHeight + self.rowHeight = (maxHeight - (self.horizontalSpacing * CGFloat(self.rows - 1))) / CGFloat(self.rows) } public func contentOffsets(sizes: [Int: CGSize]) -> [Int: CGPoint] { var rows: [Row] = (0.. [Int: CGPoint] { var columns: [Column] = (0..: View { guard let measurements else { /// Settings have not been set or have for some unknown reason been set to nil if state != nil { - Task { +// Task { resetMeasurements() - } +// } } return } @@ -141,25 +141,25 @@ public struct SmartScrollView: View { guard let state else { /// State is nil so initialize state - Task { +// Task { self.state = .init(content: contentSize, scrollView: scrollViewSize) - } +// } return } guard state.content.equals(contentSize, precision: 0.01) else { /// Content size has changed so reset state. - Task { +// Task { resetMeasurements() - } +// } return } guard state.scrollView.equals(scrollViewSize, precision: 0.01) else { /// Scroll view size has changed (it can only shrink) so update state. - Task { +// Task { self.state = .init(content: contentSize, scrollView: scrollViewSize) - } +// } return } @@ -180,6 +180,7 @@ public struct SmartScrollView: View { return .init(contentFrame: contentFrame, scrollViewSize: scrollViewSize) } .fixedSize(horizontal: axes.contains(.horizontal), vertical: axes.contains(.vertical)) +// .opacity(state == nil ? 0 : 1) } } /// A frame that's able to shrink the scroll view is applied only when the state is known.