๐ScrollVGridForEach
SwiftUI โฉ Layout โฉ Grids โฉ
๐ ScrollVGridForEach = ScrollView + LazyVGrid + ForEach
โฌ๏ธ ้่ฆ๏ผ VGridForEach
// (r) refactor (f) fix
// 2022.02.15 (r) : param `data` -> `indices`
// : param exchange order `indices` <-> `columns`
// : param `content` -> `cellViewAtIndex`
// (f) : @ViewBuilder cellViewAtIndex
import SwiftUI
// ------------------------------
// ๐ ScrollVGridForEach
// ------------------------------
/// ๐ ScrollVGridForEach = ScrollView + LazyVGrid + ForEach
public struct ScrollVGridForEach<Content: View>: View {
// properties
let indices: Range<Int>
let columns: [GridItem]
let alignment : HorizontalAlignment // alignment in cell
let rowSpacing : CGFloat? // row spacing
let pinnedViews: PinnedScrollableViews // ?
@ViewBuilder let cellViewAtIndex: (Int) -> Content // โญ ViewBuilder
// view body
public var body: some View {
ScrollView(.vertical){ // ScrollView + VGridForEach
VGridForEach( // ๐ VGridForEach
indices,
columns: columns,
alignment: alignment,
rowSpacing: rowSpacing,
pinnedViews: pinnedViews,
cellViewAtIndex: cellViewAtIndex
)
}
}
}
// convenience init
extension ScrollVGridForEach {
public init(
_ indices: Range<Int>,
columns : [GridItem],
alignment: HorizontalAlignment = .center,
rowSpacing : CGFloat? = nil,
pinnedViews: PinnedScrollableViews = .init(),
// โญ ViewBuilder
@ViewBuilder cellViewAtIndex: @escaping (Int) -> Content
) {
// ForEach
self.indices = indices
// LazyVGrid
self.columns = columns
self.alignment = alignment
self.rowSpacing = rowSpacing
self.pinnedViews = pinnedViews
self.cellViewAtIndex = cellViewAtIndex
}
}
History
2022.02.15
Last updated
Was this helpful?