Skip to content

Commit

Permalink
Add demos gif
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbergeron committed Sep 23, 2023
1 parent e828d44 commit 2e5495e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
Binary file added .github/readme/RemoteImageDemos.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ Add `RemoteImage` to your project via Swift Package Manager, and add `import Rem

`RemoteImage`'s APIs have been designed to make it super easy to adopt in your app/project. In most cases, it's a simple drop-in replacement for SwiftUI's `AsyncImage`.

Check out the `RemoteImage Demos` app in the Xcode project to see some live exmaples.

![Demos](.github/readme/RemoteImageDemos.gif)

### Simple Configuration

```swift
let imageURL: URL?

/// A simple `RemoteImage` view.
#Preview("Simple") {
RemoteImage(url: imageULRL)
RemoteImage(url: imageURL)
}

/// A simple `RemoteImage` view, with modifier.
/// A simple `RemoteImage` view with modifier closure.
#Preview("Simple, with image modifier") {
RemoteImage(url: imageURL) {
$0.resizable().scaledToFit()
Expand All @@ -36,8 +40,8 @@ let imageURL: URL?

/// A `RemoteImage` view with a custom placeholder.
#Preview("Custom placeholder") {
RemoteImage(url: imageURL) { image in
image.resizable().scaledToFit()
RemoteImage(url: imageURL) {
$0.resizable().scaledToFit()
} placeholder: {
ProgressView()
}
Expand Down Expand Up @@ -67,19 +71,17 @@ let imageURL: URL?

```swift
let imageURL: URL?
let urlSession: URLSession
let imageCache: URLCache
let urlSession = URLSession(configuration: .ephemeral)
let imageCache = URLCache(memoryCapacity: 10_000_000, diskCapacity: 0)

/// Image loaded with a custom `URLSession`, skipping the cache, and using a custom
/// phase transition animation.
/// Image loaded with a custom `URLSession` and using a custom phase transition animation.
#Preview("Custom URLSession") {
RemoteImage(
url: .cuteDoggo,
urlSession: .shared,
url: imageURL,
urlSession: urlSession,
configuration: RemoteImageConfiguration(
skipCache: true,
transaction: Transaction(
animation: .easeInOut(duration: 0.5))))
animation: .spring(duration: 1.0).delay(0.5))))
{
$0.resizable().scaledToFit()
}
Expand All @@ -89,8 +91,8 @@ let imageCache: URLCache
/// will be constructed using the `URLSessionConfiguration.default` configuration
/// and the provided cache instance.
#Preview("Custom URLCache") {
RemoteImage(url: .cuteDoggo, cache: .shared) { image in
image.resizable().scaledToFit()
RemoteImage(url: imageURL, cache: imageCache) {
$0.resizable().scaledToFit()
}
}
```
34 changes: 27 additions & 7 deletions RemoteImageDemo/DemosList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ struct DemosList: View {
/// A `RemoteImage` view with custom content.
case customContent = "Custom content"

/// Image loaded with a custom `URLSession`, skipping the cache, and using a custom
/// phase transition animation.
/// Image loaded with a custom `URLSession` and using a custom phase transition animation.
case customURLSession = "Custom URLSession"

/// Image loaded from a custom cache. If the image is not yet cached, a new `URLSession`
Expand Down Expand Up @@ -72,7 +71,13 @@ struct DemosList: View {
}

case .customPlaceholder:
RemoteImage(url: nil) { image in
RemoteImage(
url: .cuteDoggo,
configuration: .init(
skipCache: true,
transaction: .init(
animation: .spring(duration: 1.0).delay(0.5))))
{ image in
image.resizable().scaledToFit()
} placeholder: {
ZStack {
Expand Down Expand Up @@ -118,18 +123,29 @@ struct DemosList: View {
case .customURLSession:
RemoteImage(
url: .cuteDoggo,
urlSession: .shared,
urlSession: URLSession(configuration: .ephemeral),
configuration: RemoteImageConfiguration(
skipCache: true,
transaction: Transaction(
animation: .spring(duration: 1.0).delay(0.5))))
{
$0.resizable().scaledToFit()
}

case .customCache:
RemoteImage(url: .cuteDoggo, cache: .shared) { image in
image.resizable().scaledToFit()
RemoteImage(
url: .cuteDoggo,
cache: .inMemoryOnly,
configuration: RemoteImageConfiguration(
transaction: Transaction(
animation: .spring(duration: 1.0).delay(0.5))))
{
$0.resizable().scaledToFit()
} placeholder: {
ZStack {
Color.black.opacity(0.05)
ProgressView()
}
.aspectRatio(1, contentMode: .fit)
}
}
}
Expand All @@ -141,6 +157,10 @@ extension URL {
fileprivate static let githubRepo = URL(string: "https://github.com/bdbergeron/RemoteImage")!
}

extension URLCache {
static let inMemoryOnly = URLCache(memoryCapacity: 10_000_000, diskCapacity: 0)
}

#if DEBUG
// MARK: - DemosListPreviews

Expand Down

0 comments on commit 2e5495e

Please sign in to comment.