Swiftpack.co - bdbergeron/RemoteImage as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by bdbergeron.
bdbergeron/RemoteImage 1.2.0
A drop-in alternative to SwiftUI's AsyncImage, with support for custom URLSessions, caching, and animated phase changes.
⭐️ 4
🕓 30 weeks ago
iOS macOS
.package(url: "https://github.com/bdbergeron/RemoteImage.git", from: "1.2.0")

🖼️ RemoteImage

A drop-in alternative to SwiftUI's AsyncImage, with support for custom URLSessions, caching, and animated phase changes.

build-ios build-macos codecov CodeFactor

Getting Started

Add RemoteImage to your project via Swift Package Manager, and add import RemoteImage where you want to use it.

.package(url: "https://github.com/bdbergeron/RemoteImage", from: "1.0.0"),

Usage

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

Simple Configuration

let imageURL: URL?

/// A simple `RemoteImage` view.
RemoteImage(url: imageURL)

/// A simple `RemoteImage` view with modifier closure.
RemoteImage(url: imageURL) {
  $0.resizable().scaledToFit()
}

/// A `RemoteImage` view with a custom placeholder view.
RemoteImage(url: imageURL) {
  $0.resizable().scaledToFit()
} placeholder: {
  ProgressView()
}

/// A `RemoteImage` view with custom placeholder and failure views.
RemoteImage(url: imageURL) {
  $0.resizable().scaledToFit()
} placeholder: {
  ProgressView()
} failure: { error in
  ZStack {
    Color.yellow.opacity(0.3)
    Text("Image could not be loaded.")
      .font(.caption)
      .foregroundStyle(.secondary)
  }
}

Advanced Configuration

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

/// Image loaded with a custom `URLSession` and using a custom phase transition animation.
RemoteImage(
  url: imageURL,
  urlSession: urlSession,
  configuration: RemoteImageConfiguration(
    transaction: Transaction(
      animation: .spring(duration: 1.0).delay(0.5))))
{
  $0.resizable().scaledToFit()
}

/// Image loaded from a custom cache. If the image is not yet cached, a new `URLSession`
/// will be constructed using the `URLSessionConfiguration.default` configuration
/// and the provided cache instance.
RemoteImage(url: imageURL, cache: imageCache) {
  $0.resizable().scaledToFit()
} placeholder: {
  ZStack {
    Color.black.opacity(0.05)
    ProgressView()
  }
}

GitHub

link
Stars: 4
Last commit: 3 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

1.2.0
30 weeks ago

What's Changed

Full Changelog: https://github.com/bdbergeron/RemoteImage/compare/1.1.0...1.2.0

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics