71 lines
1.9 KiB
Swift
71 lines
1.9 KiB
Swift
import SwiftUI
|
|
|
|
struct CreatorProfileGridItem: Identifiable, Hashable {
|
|
let id: String
|
|
let imageUrl: String?
|
|
let name: String
|
|
let subtitle: String?
|
|
|
|
init(
|
|
id: String,
|
|
imageUrl: String?,
|
|
name: String,
|
|
subtitle: String? = nil
|
|
) {
|
|
self.id = id
|
|
self.imageUrl = imageUrl
|
|
self.name = name
|
|
self.subtitle = subtitle
|
|
}
|
|
}
|
|
|
|
struct CreatorProfileGrid: View {
|
|
let items: [CreatorProfileGridItem]
|
|
let columns: Int
|
|
let spacing: CGFloat
|
|
let action: (CreatorProfileGridItem) -> Void
|
|
|
|
init(
|
|
items: [CreatorProfileGridItem],
|
|
columns: Int = 3,
|
|
spacing: CGFloat = SodaSpacing.s16,
|
|
action: @escaping (CreatorProfileGridItem) -> Void = { _ in }
|
|
) {
|
|
self.items = items
|
|
self.columns = columns
|
|
self.spacing = spacing
|
|
self.action = action
|
|
}
|
|
|
|
var body: some View {
|
|
LazyVGrid(columns: gridColumns, alignment: .center, spacing: spacing) {
|
|
ForEach(items) { item in
|
|
CreatorProfileItem(
|
|
imageUrl: item.imageUrl,
|
|
name: item.name,
|
|
subtitle: item.subtitle
|
|
) {
|
|
action(item)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private var gridColumns: [GridItem] {
|
|
Array(repeating: GridItem(.flexible(), spacing: spacing), count: columns)
|
|
}
|
|
}
|
|
|
|
struct CreatorProfileGrid_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
CreatorProfileGrid(items: [
|
|
CreatorProfileGridItem(id: "1", imageUrl: nil, name: "크리에이터 1"),
|
|
CreatorProfileGridItem(id: "2", imageUrl: nil, name: "크리에이터 2"),
|
|
CreatorProfileGridItem(id: "3", imageUrl: nil, name: "크리에이터 3")
|
|
])
|
|
.padding(SodaSpacing.s20)
|
|
.background(Color.black)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|