Skip to content

Commit eb04cf8

Browse files
committed
Add an image playground
1 parent 6473e10 commit eb04cf8

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#if canImport(AndroidSwiftUI)
2+
import AndroidSwiftUI
3+
#else
4+
import SwiftUI
5+
#endif
6+
import Foundation
7+
8+
struct ImagePlayground: View {
9+
10+
@State private var remoteIndex = 0
11+
12+
private let remotes = [
13+
"https://www.gstatic.com/webp/gallery/1.jpg",
14+
"https://picsum.photos/id/237/300/200",
15+
]
16+
17+
var body: some View {
18+
ScrollView {
19+
VStack(alignment: .leading, spacing: 0) {
20+
Example("Asset image") {
21+
VStack(alignment: .leading, spacing: 8) {
22+
Text("Image(\"sample_photo\") — natural size")
23+
Image("sample_photo")
24+
}
25+
}
26+
Example("resizable + scaledToFit") {
27+
Image("sample_photo")
28+
.resizable()
29+
.scaledToFit()
30+
.frame(width: 160, height: 90)
31+
}
32+
Example("resizable + scaledToFill") {
33+
Image("sample_photo")
34+
.resizable()
35+
.scaledToFill()
36+
.frame(width: 160, height: 90)
37+
}
38+
Example("AsyncImage") {
39+
VStack(alignment: .leading, spacing: 8) {
40+
AsyncImage(url: URL(string: remotes[remoteIndex]))
41+
.frame(width: 200, height: 150)
42+
Button("Load the other image") {
43+
remoteIndex = (remoteIndex + 1) % remotes.count
44+
}
45+
}
46+
}
47+
Example("AsyncImage — failure") {
48+
AsyncImage(url: URL(string: "https://example.invalid/missing.png"))
49+
.frame(width: 200, height: 60)
50+
}
51+
Example("Unknown asset falls back") {
52+
Image("no_such_asset")
53+
}
54+
}
55+
}
56+
.navigationTitle("Images")
57+
}
58+
}

0 commit comments

Comments
 (0)