97 lines
3.2 KiB
Swift
97 lines
3.2 KiB
Swift
import SwiftUI
|
|
|
|
struct MainHomeRecentDebutCreatorSection: View {
|
|
let items: [HomeCreatorItem]
|
|
let onTapCreator: (Int) -> Void
|
|
|
|
init(
|
|
items: [HomeCreatorItem],
|
|
onTapCreator: @escaping (Int) -> Void = { _ in }
|
|
) {
|
|
self.items = items
|
|
self.onTapCreator = onTapCreator
|
|
}
|
|
|
|
var body: some View {
|
|
if !items.isEmpty {
|
|
VStack(alignment: .leading, spacing: SodaSpacing.s14) {
|
|
SectionTitle(title: I18n.HomeRecommendation.recentDebutCreatorSectionTitle)
|
|
|
|
ScrollView(.horizontal, showsIndicators: false) {
|
|
LazyHStack(alignment: .center, spacing: SodaSpacing.s4) {
|
|
ForEach(items, id: \.self) { item in
|
|
MainHomeRecentDebutCreatorItemView(item: item) {
|
|
onTapCreator(item.creatorId)
|
|
}
|
|
}
|
|
}
|
|
.padding(.horizontal, SodaSpacing.s14)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct MainHomeRecentDebutCreatorItemView: View {
|
|
let item: HomeCreatorItem
|
|
let action: () -> Void
|
|
|
|
var body: some View {
|
|
let itemSize = AiCharacterCard.responsiveSize()
|
|
|
|
Button(action: action) {
|
|
ZStack(alignment: .bottom) {
|
|
DownsampledKFImage(
|
|
url: URL(string: item.creatorProfileImage),
|
|
size: itemSize
|
|
)
|
|
.frame(width: itemSize.width, height: itemSize.height)
|
|
.background(Color.gray800)
|
|
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
|
|
|
|
LinearGradient(
|
|
colors: [Color.black.opacity(0), Color.black.opacity(0.7)],
|
|
startPoint: .top,
|
|
endPoint: .bottom
|
|
)
|
|
.frame(height: min(80, itemSize.height))
|
|
|
|
Text(item.creatorNickname)
|
|
.appFont(.heading4)
|
|
.foregroundColor(.white)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
.padding(.horizontal, SodaSpacing.s12)
|
|
.padding(.bottom, SodaSpacing.s20)
|
|
}
|
|
.frame(width: itemSize.width, height: itemSize.height)
|
|
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
}
|
|
|
|
struct MainHomeRecentDebutCreatorSection_Previews: PreviewProvider {
|
|
private static let previewImageUrl = "https://picsum.photos/500/700"
|
|
|
|
static var previews: some View {
|
|
MainHomeRecentDebutCreatorSection(
|
|
items: [
|
|
HomeCreatorItem(
|
|
creatorId: 1,
|
|
creatorNickname: "크리에이터 이름",
|
|
creatorProfileImage: previewImageUrl
|
|
),
|
|
HomeCreatorItem(
|
|
creatorId: 2,
|
|
creatorNickname: "크리에이터 이름",
|
|
creatorProfileImage: previewImageUrl
|
|
)
|
|
]
|
|
)
|
|
.padding(.vertical, SodaSpacing.s20)
|
|
.background(Color.black)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|