SwiftUI Image loading and Animation framework powered by SDWebImage
Go to file
DreamPiggy a3b7bab17a Add demos for all of Apple Platforms and environment, including: iOS, macOS, macOS Catalyst, tvOS, watchOS
All of them using the same codebase
2019-10-05 19:55:42 +08:00
Example Add demos for all of Apple Platforms and environment, including: iOS, macOS, macOS Catalyst, tvOS, watchOS 2019-10-05 19:55:42 +08:00
SDWebImageSwiftUI Using the frame layout for view wrapper instead of Autolayout. Solve the issue when running on AppKit (not Catalyst) 2019-10-05 19:03:47 +08:00
SDWebImageSwiftUI.xcodeproj Support AnimatedImage with `aspectRatio`, `antialiased`, `interpolation`, `renderingMode` and `resizable` methods, some of them is not fully implemented 2019-10-01 14:34:11 +08:00
.gitignore Update the gitignore to avoid swiftpm folder 2019-10-03 14:45:36 +08:00
.travis.yml Fix the Travis-CI script 2019-08-09 16:32:05 +08:00
Cartfile Add the Xcode project to support Carthage. Fix the build issue on macOS/tvOS/watchOS 2019-08-09 15:58:21 +08:00
Cartfile.resolved Add the Xcode project to support Carthage. Fix the build issue on macOS/tvOS/watchOS 2019-08-09 15:58:21 +08:00
LICENSE Initial commit 2019-08-07 18:10:05 +08:00
Package.resolved Update the new screenshot of demo 2019-10-03 14:42:29 +08:00
Package.swift Add Swift Package Manager support 2019-08-09 16:06:53 +08:00
README.md Bump version to 0.3.0 2019-10-05 16:50:27 +08:00
SDWebImageSwiftUI.podspec Bump version to 0.3.0 2019-10-05 16:50:27 +08:00
_Pods.xcodeproj Initial commit 2019-08-07 18:10:05 +08:00

README.md

SDWebImageSwiftUI

CI Status Version License Platform Carthage compatible SwiftPM compatible

What's for

This is an experimental project for SDWebImage.

It aims to ensure the following function available for users and try to do some experiments for Swift platform.

  • Swift Package Manager integration
  • SwiftUI compatibility
  • Swift source code compatibility

Note we do not guarantee the public API stable for current status until v1.0 version. Since SwiftUI is a new platform for us, we need to investigate the API design.

Requirements

  • Xcode 11+
  • iOS 13+
  • macOS 10.15+
  • tvOS 13+
  • watchOS 6+
  • Swift 5.1+

Installation

CocoaPods

SDWebImageSwiftUI is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SDWebImageSwiftUI'

Carthage

SDWebImageSwiftUI is available through Carthage.

github "SDWebImage/SDWebImageSwiftUI"

Swift Package Manager

SDWebImageSwiftUI is available through Swift Package Manager.

let package = Package(
    dependencies: [
        .package(url: "https://github.com/SDWebImage/SDWebImageSwiftUI.git", from: "0.3")
    ],
)

Usage

Using WebImage to load network image

  • Supports the placeholder and detail options control for image loading as SDWebImage.
  • Supports the success/failure/progress changes event for custom handling.

Note: Unlike UIImageView in UIKit, SwiftUI's Image does not support animation. This WebImage using Image for internal implementation and supports static image format only.

var body: some View {
    WebImage(url: URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic"))
        .onSuccess(perform: { (image, cacheType) in
            // Success
        })
        .resizable()
        .scaledToFit()
        .frame(width: 300, height: 300, alignment: .center)
}

Using AnimatedImage to play animation

var body: some View {
    Group {
        // Network
        AnimatedImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif"))
        .onFailure(perform: { (error) in
            // Error
        })
        .scaledToFit()
        // Data
        AnimatedImage(data: try! Data(contentsOf: URL(fileURLWithPath: "/tmp/foo.webp")))
        .customLoopCount(1)
        // Bundle (not Asset Catalog)
        AnimatedImage(name: "animation1", isAnimating: $isAnimating)) // Animation control binding
        .maxBufferSize(.max)
    }
}
  • Supports network image as well as local data and bundle image
  • Supports animation control using the SwiftUI Binding
  • Supports advanced control like loop count, incremental load, buffer size.

Note: AnimatedImage supports both image url or image data for animated image format. Which use the SDWebImage's Animated ImageView for internal implementation.

Demo

To run the example using SwiftUI, following the steps:

cd Example
pod install

Then open the Xcode Workspace to run the demo application. You can run it on iOS and macOS.

Screenshot

  • iOS Demo
  • macOS Demo

Author

DreamPiggy

License

SDWebImageSwiftUI is available under the MIT license. See the LICENSE file for more info.