๐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
}
}
TestSVGFE - test ScrollVGridForEach.
uses ScrollView.
uses Grids layout.
History
2022.02.15
โฌ๏ธ ้่ฆ๏ผ VGridForEach
// ------------------------------
// ๐ฆ ScrollVGridForEach
// ------------------------------
public struct ScrollVGridForEach<Content: View>: View {
// properties
let columns: [GridItem]
let data : Range<Int>
let alignment: HorizontalAlignment
let spacing : CGFloat?
let pinnedViews: PinnedScrollableViews
let content : (Int) -> Content
// view body
public var body: some View {
ScrollView(.vertical){
VGridForEach(data, columns: columns, alignment: alignment, spacing: spacing, pinnedViews: pinnedViews, content: content)
}
}
}
// convenience init
extension ScrollVGridForEach {
public init(
_ data : Range<Int>,
columns : [GridItem],
alignment: HorizontalAlignment = .center,
spacing : CGFloat? = nil,
pinnedViews: PinnedScrollableViews = .init(),
content : @escaping (Int) -> Content
) {
// ForEach
self.data = data
// LazyVGrid
self.columns = columns
self.alignment = alignment
self.spacing = spacing
self.pinnedViews = pinnedViews
self.content = content
}
}
Last updated