Skip to content

Open source CapCut alternative.

TypeScript

refactor(ios): one grid cell behind the media tiles

David Led6a52c9c5efd
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/Components.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/Components.swift
index a7355137..68a730d3 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/Components.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/Components.swift
@@ -83,6 +83,24 @@ struct AvatarMenu: View {
}
}
+/// A grid cell of fixed aspect ratio. Artwork rides in an overlay, so a
+/// landscape frame filling a portrait cell is cropped at the cell's edge; the
+/// cell keeps the size the grid gave it and rows stay aligned.
+struct MediaTile<Content: View>: View {
+ var ratio: CGFloat
+ var corner: CGFloat = 16
+ @ViewBuilder var content: Content
+
+ var body: some View {
+ Color.clear
+ .aspectRatio(ratio, contentMode: .fit)
+ .frame(maxWidth: .infinity)
+ .background(.fill.secondary)
+ .overlay { content }
+ .clipShape(RoundedRectangle(cornerRadius: corner, style: .continuous))
+ }
+}
+
struct EmptyState: View {
let title: String
let message: String
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift
index 40100719..acb42154 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/IdeasScreen.swift
@@ -222,20 +222,15 @@ struct InspirationCard: View {
.buttonStyle(.plain)
case .media(let fileName, let isVideo):
let url = ideas.mediaURL(fileName: fileName)
- Group {
+ MediaTile(ratio: 3 / 4) {
if isVideo {
VideoPlayer(player: AVPlayer(url: url))
} else if let image = UIImage(contentsOfFile: url.localPath) {
Image(uiImage: image)
.resizable()
.scaledToFill()
- } else {
- Rectangle().fill(.fill.tertiary)
}
}
- .aspectRatio(3 / 4, contentMode: .fit)
- .frame(maxWidth: .infinity)
- .clipShape(RoundedRectangle(cornerRadius: 16))
}
}
}
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/MediaScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/MediaScreen.swift
index e4df46b4..981e42c2 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/MediaScreen.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/MediaScreen.swift
@@ -75,21 +75,17 @@ struct RecordingCard: View {
var media: MediaModel
var body: some View {
- ZStack {
+ MediaTile(ratio: 9 / 14) {
if let url = media.thumbnailURL(for: recording),
let image = UIImage(contentsOfFile: url.localPath) {
Image(uiImage: image)
.resizable()
.scaledToFill()
} else {
- Rectangle().fill(.fill.secondary)
Image(systemName: "play.fill")
.foregroundStyle(.secondary)
}
}
- .aspectRatio(9 / 14, contentMode: .fit)
- .frame(maxWidth: .infinity)
- .clipShape(RoundedRectangle(cornerRadius: 16))
.overlay(alignment: .bottomTrailing) {
Text(formattedDuration(recording.duration))
.font(.caption2.weight(.bold))
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/ProjectsScreen.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/ProjectsScreen.swift
index 0a8a2e5f..4c6e42ce 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitUI/ProjectsScreen.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitUI/ProjectsScreen.swift
@@ -56,14 +56,12 @@ struct ProjectCard: View {
switch project.export {
case .ready(let renderedOn):
Button(action: onPlay) {
- ZStack {
+ MediaTile(ratio: 9 / 13) {
if let thumbnail = project.thumbnail,
let image = UIImage(contentsOfFile: thumbnail.localPath) {
Image(uiImage: image)
.resizable()
.scaledToFill()
- } else {
- RoundedRectangle(cornerRadius: 16).fill(.fill.secondary)
}
Circle()
.fill(.black.opacity(0.35))
@@ -75,7 +73,6 @@ struct ProjectCard: View {
.offset(x: 2)
}
}
- .clipShape(RoundedRectangle(cornerRadius: 16))
.overlay(alignment: .topLeading) {
ProjectTag(text: formattedDuration(project.duration))
.padding(8)
@@ -88,9 +85,9 @@ struct ProjectCard: View {
.buttonStyle(.plain)
case .none:
GhostCard(title: project.name, subtitle: "No export yet")
+ .aspectRatio(9 / 13, contentMode: .fit)
}
}
- .aspectRatio(9 / 13, contentMode: .fit)
.frame(maxWidth: .infinity)
}
}