Skip to content

Commit

Permalink
reenable card previews
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Chien <stdrc@outlook.com>
  • Loading branch information
stdrc committed Jun 29, 2024
1 parent fc61440 commit 95f17f5
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 60 deletions.
42 changes: 22 additions & 20 deletions excerpts/Cards/Bold.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,25 @@ struct BoldCard: Card {
}
}

// struct BoldCard_Previews: PreviewProvider {
// static let screenEdgePadding: CGFloat = 12
//
// static var previews: some View {
// ForEach(Array(demoExcerpts.enumerated()), id: \.offset) { i, excerpt in
// GeometryReader { geometry in
// ScrollView(.vertical, showsIndicators: false) {
// VStack {
// BoldCard(CardOptions(excerpt: excerpt, width: geometry.size.width - screenEdgePadding * 2, font: BoldCard.meta.defaultFont))
// }
// .padding(screenEdgePadding)
// .frame(width: geometry.size.width)
// .frame(minHeight: geometry.size.height)
// }
// }
// .environment(\.locale, .init(identifier: "zh-Hans"))
// .previewDisplayName("Demo \(i + 1)")
// }
// }
// }
struct BoldCard_Previews: PreviewProvider {
static var previews: some View {
ForEach(Array(demoExcerpts.enumerated()), id: \.offset) { i, excerpt in
GeometryReader { geometry in
ScrollView(.vertical, showsIndicators: false) {
HStack {
Spacer()
VStack {
BoldCard(CardOptions(excerpt: excerpt, width: CardConsts.cardWidth(geometry.size.width), font: BoldCard.meta.defaultFont))
}
.frame(maxWidth: CardConsts.maxCardContainerWidth)
.padding(CardConsts.cardContainerPadding)
Spacer()
}
.frame(minHeight: geometry.size.height)
}
}
.environment(\.locale, .init(identifier: "zh-Hans"))
.previewDisplayName("Demo \(i + 1)")
}
}
}
9 changes: 9 additions & 0 deletions excerpts/Cards/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ protocol Card: View {

init(_ options: CardOptions)
}

enum CardConsts {
static let cardContainerPadding: CGFloat = 12
static let maxCardContainerWidth: CGFloat = 400

static func cardWidth(_ geoWidth: CGFloat) -> CGFloat {
min(geoWidth, Self.maxCardContainerWidth) - Self.cardContainerPadding * 2
}
}
42 changes: 22 additions & 20 deletions excerpts/Cards/Classic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,25 @@ struct ClassicCard: Card {
}
}

// struct ClassicCard_Previews: PreviewProvider {
// static let screenEdgePadding: CGFloat = 12
//
// static var previews: some View {
// ForEach(Array(demoExcerpts.enumerated()), id: \.offset) { i, excerpt in
// GeometryReader { geometry in
// ScrollView(.vertical, showsIndicators: false) {
// VStack {
// ClassicCard(CardOptions(excerpt: excerpt, width: geometry.size.width - screenEdgePadding * 2, font: ClassicCard.meta.defaultFont))
// }
// .padding(screenEdgePadding)
// .frame(width: geometry.size.width)
// .frame(minHeight: geometry.size.height)
// }
// }
// .environment(\.locale, .init(identifier: "zh-Hans"))
// .previewDisplayName("Demo \(i + 1)")
// }
// }
// }
struct ClassicCard_Previews: PreviewProvider {
static var previews: some View {
ForEach(Array(demoExcerpts.enumerated()), id: \.offset) { i, excerpt in
GeometryReader { geometry in
ScrollView(.vertical, showsIndicators: false) {
HStack {
Spacer()
VStack {
ClassicCard(CardOptions(excerpt: excerpt, width: CardConsts.cardWidth(geometry.size.width), font: ClassicCard.meta.defaultFont))
}
.frame(maxWidth: CardConsts.maxCardContainerWidth)
.padding(CardConsts.cardContainerPadding)
Spacer()
}
.frame(minHeight: geometry.size.height)
}
}
.environment(\.locale, .init(identifier: "zh-Hans"))
.previewDisplayName("Demo \(i + 1)")
}
}
}
42 changes: 22 additions & 20 deletions excerpts/Cards/Minimal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,25 @@ struct MinimalCard: Card {
}
}

// struct MinimalCard_Previews: PreviewProvider {
// static let screenEdgePadding: CGFloat = 12
//
// static var previews: some View {
// ForEach(Array(demoExcerpts.enumerated()), id: \.offset) { i, excerpt in
// GeometryReader { geometry in
// ScrollView(.vertical, showsIndicators: false) {
// VStack {
// MinimalCard(CardOptions(excerpt: excerpt, width: geometry.size.width - screenEdgePadding * 2, font: ClassicCard.meta.defaultFont))
// }
// .padding(screenEdgePadding)
// .frame(width: geometry.size.width)
// .frame(minHeight: geometry.size.height)
// }
// }
// .environment(\.locale, .init(identifier: "zh-Hans"))
// .previewDisplayName("Demo \(i + 1)")
// }
// }
// }
struct MinimalCard_Previews: PreviewProvider {
static var previews: some View {
ForEach(Array(demoExcerpts.enumerated()), id: \.offset) { i, excerpt in
GeometryReader { geometry in
ScrollView(.vertical, showsIndicators: false) {
HStack {
Spacer()
VStack {
MinimalCard(CardOptions(excerpt: excerpt, width: CardConsts.cardWidth(geometry.size.width), font: MinimalCard.meta.defaultFont))
}
.frame(maxWidth: CardConsts.maxCardContainerWidth)
.padding(CardConsts.cardContainerPadding)
Spacer()
}
.frame(minHeight: geometry.size.height)
}
}
.environment(\.locale, .init(identifier: "zh-Hans"))
.previewDisplayName("Demo \(i + 1)")
}
}
}

0 comments on commit 95f17f5

Please sign in to comment.