Skip to content

Commit

Permalink
Better demo code
Browse files Browse the repository at this point in the history
  • Loading branch information
leoz committed Sep 10, 2023
1 parent cfb4109 commit 98c842f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
42 changes: 19 additions & 23 deletions Demo/CachedImageDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,28 @@
import SwiftUI
import CachedImage

let posters = [
"https://picsum.photos/800/600?random=1",
"https://picsum.photos/600/800?random=2",
"https://picsum.photos/800/600?random=3",
"https://picsum.photos/600/800?random=4"
].map { URL(string: $0)! }
let images = (0...20).map {
"https://picsum.photos/800/600?random=\($0)"
}
let imageURLs = images.map {
URL(string: $0)!
}

struct ContentView: View {
var body: some View {
GeometryReader { geometry in
List(posters, id: \.self) { url in
CachedImage(
url: url,
content: { image in
image
.resizable()
.aspectRatio(contentMode: .fit)
},
placeholder: {
Text("Loading ...")
}
)
.frame(
idealHeight: geometry.size.width / 2 * 3
) // 2:3 aspect ratio
}
List(imageURLs, id: \.self) { url in
CachedImage(
url: url,
content: { image in
image
.resizable()
.aspectRatio(contentMode: .fit)
},
placeholder: {
Text("Loading ...")
}
)
.scaledToFit()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/CachedImage/PlatformImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public typealias PlatformImage = NSImage
public typealias PlatformImage = UIImage
#endif

public extension Image {
extension Image {
@inlinable init(platformImage: PlatformImage) {
#if os(macOS)
self.init(nsImage: platformImage)
Expand Down

0 comments on commit 98c842f

Please sign in to comment.