-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductRow.swift
More file actions
55 lines (49 loc) · 1.53 KB
/
ProductRow.swift
File metadata and controls
55 lines (49 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// ProductRow.swift
// FlowStackExample
//
// Created by Charles Hieger on 7/24/23.
//
import SwiftUI
import CachedAsyncImage
struct ProductRow: View {
var product: Product
var cornerRadius: CGFloat
var body: some View {
Color.clear
.aspectRatio(4 / 3, contentMode: .fill)
.overlay {
image(url: product.imageUrl)
.allowsHitTesting(false) // https://stackoverflow.com/a/74711565
.accessibilityLabel("Product Row Image overlay")
}
.overlay(alignment: .topTrailing) {
Text(product.name)
.font(.system(size: 48))
.fontWeight(.black)
.foregroundStyle(.white)
.padding()
.accessibilityLabel("Product Row name")
}
.clipShape(RoundedRectangle(cornerRadius: 24, style: .continuous))
}
private func image(url: URL) -> some View {
CachedAsyncImage(url: url, urlCache: .imageCache) { image in
image
.resizable()
.scaledToFill()
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
} placeholder: {
Color(uiColor: .secondarySystemFill)
}
}
}
struct ProductRow_Previews: PreviewProvider {
static var previews: some View {
ScrollView {
LazyVStack {
ProductRow(product: .appleII, cornerRadius: 24)
}
}
}
}