Skip to content

Commit 8c55520

Browse files
committed
Initial commit with CocoaPods && SwiftPM support
1 parent 4298523 commit 8c55520

File tree

14 files changed

+408
-29
lines changed

14 files changed

+408
-29
lines changed

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ DerivedData
2323
.bundle
2424

2525
# Add this line if you want to avoid checking in source code from Carthage dependencies.
26-
# Carthage/Checkouts
27-
28-
Carthage/Build
26+
Carthage
2927

3028
# We recommend against adding the Pods directory to your .gitignore. However
3129
# you should judge for yourself, the pros and cons are mentioned at:
@@ -34,4 +32,5 @@ Carthage/Build
3432
# Note: if you ignore the Pods directory, make sure to uncomment
3533
# `pod install` in .travis.yml
3634
#
37-
# Pods/
35+
Pods/
36+
Podfile.lock

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/SDWebImageLottiePlugin.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,15 @@
313313
);
314314
inputPaths = (
315315
"${PODS_ROOT}/Target Support Files/Pods-SDWebImageLottiePlugin_Example/Pods-SDWebImageLottiePlugin_Example-frameworks.sh",
316+
"${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework",
316317
"${BUILT_PRODUCTS_DIR}/SDWebImageLottiePlugin/SDWebImageLottiePlugin.framework",
318+
"${BUILT_PRODUCTS_DIR}/lottie-ios/Lottie.framework",
317319
);
318320
name = "[CP] Embed Pods Frameworks";
319321
outputPaths = (
322+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework",
320323
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageLottiePlugin.framework",
324+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Lottie.framework",
321325
);
322326
runOnlyForDeploymentPostprocessing = 0;
323327
shellPath = /bin/sh;

Example/SDWebImageLottiePlugin.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/SDWebImageLottiePlugin/ViewController.swift

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,33 @@
77
//
88

99
import UIKit
10+
import Lottie
11+
import SDWebImageLottiePlugin
1012

1113
class ViewController: UIViewController {
14+
15+
let animationView = AnimationView()
1216

1317
override func viewDidLoad() {
1418
super.viewDidLoad()
15-
// Do any additional setup after loading the view, typically from a nib.
16-
}
17-
18-
override func didReceiveMemoryWarning() {
19-
super.didReceiveMemoryWarning()
20-
// Dispose of any resources that can be recreated.
19+
animationView.contentMode = .scaleAspectFit
20+
animationView.frame = self.view.bounds
21+
animationView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
22+
view.addSubview(animationView)
23+
24+
let lottieUrl = URL(string: "https://raw.githubusercontent.com/airbnb/lottie-web/master/demo/gatin/data.json")
25+
animationView.sd_setImage(with: lottieUrl) { (image, error, cacheType, url) in
26+
self.animationView.play(fromProgress: 0,
27+
toProgress: 1,
28+
loopMode: LottieLoopMode.playOnce,
29+
completion: { (finished) in
30+
if finished {
31+
print("Animation Complete")
32+
} else {
33+
print("Animation cancelled")
34+
}
35+
})
36+
}
2137
}
2238

2339
}

Example/Screenshot/LottieDemo.gif

194 KB
Loading

Package.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// swift-tools-version:5.1
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SDWebImageLottiePlugin",
8+
platforms: [
9+
.macOS(.v10_10), .iOS(.v9), .tvOS(.v9)
10+
],
11+
products: [
12+
// Products define the executables and libraries produced by a package, and make them visible to other packages.
13+
.library(
14+
name: "SDWebImageLottiePlugin",
15+
targets: ["SDWebImageLottiePlugin"]),
16+
],
17+
dependencies: [
18+
// Dependencies declare other packages that this package depends on.
19+
// .package(url: /* package url */, from: "1.0.0"),
20+
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.1.0"),
21+
.package(url: "https://github.com/airbnb/lottie-ios.git", from: "3.1.2")
22+
],
23+
targets: [
24+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
25+
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
26+
.target(
27+
name: "SDWebImageLottiePlugin",
28+
dependencies: ["SDWebImage"],
29+
path: ".",
30+
sources: ["SDWebImageLottiePlugin/Classes"],
31+
publicHeadersPath: "SDWebImageLottiePlugin/Classes"
32+
)
33+
]
34+
)

README.md

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,95 @@
11
# SDWebImageLottiePlugin
22

3-
[![CI Status](https://img.shields.io/travis/lizhuoli1126@126.com/SDWebImageLottiePlugin.svg?style=flat)](https://travis-ci.org/lizhuoli1126@126.com/SDWebImageLottiePlugin)
3+
[![CI Status](https://img.shields.io/travis/SDWebImage/SDWebImageLottiePlugin.svg?style=flat)](https://travis-ci.org/SDWebImage/SDWebImageLottiePlugin)
44
[![Version](https://img.shields.io/cocoapods/v/SDWebImageLottiePlugin.svg?style=flat)](https://cocoapods.org/pods/SDWebImageLottiePlugin)
55
[![License](https://img.shields.io/cocoapods/l/SDWebImageLottiePlugin.svg?style=flat)](https://cocoapods.org/pods/SDWebImageLottiePlugin)
66
[![Platform](https://img.shields.io/cocoapods/p/SDWebImageLottiePlugin.svg?style=flat)](https://cocoapods.org/pods/SDWebImageLottiePlugin)
7+
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-brightgreen.svg?style=flat)](https://github.com/SDWebImage/SDWebImageLottiePlugin)
8+
[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager/)
9+
[![codecov](https://codecov.io/gh/SDWebImage/SDWebImageLottiePlugin/branch/master/graph/badge.svg)](https://codecov.io/gh/SDWebImage/SDWebImageLottiePlugin)
710

8-
## Example
9-
10-
To run the example project, clone the repo, and run `pod install` from the Example directory first.
11+
## What's for
12+
SDWebImageLottiePlugin is a plugin for [SDWebImage](https://github.com/rs/SDWebImage/) framework, which provide the [Lottie](https://github.com/airbnb/lottie-ios) aniamtion loading from JSON file.
1113

1214
## Requirements
1315

16+
+ iOS 9+
17+
+ macOS 10.10+
18+
+ tvOS 9+
19+
+ Xcode 11+
20+
1421
## Installation
1522

23+
#### CocoaPods
24+
1625
SDWebImageLottiePlugin is available through [CocoaPods](https://cocoapods.org). To install
1726
it, simply add the following line to your Podfile:
1827

1928
```ruby
2029
pod 'SDWebImageLottiePlugin'
2130
```
2231

32+
#### Carthage
33+
34+
SDWebImageLottiePlugin is available through [Carthage](https://github.com/Carthage/Carthage).
35+
36+
```
37+
github "SDWebImage/SDWebImageLottiePlugin"
38+
```
39+
40+
#### Swift Package Manager (Xcode 11+)
41+
42+
SDWebImageLottiePlugin is available through [Swift Package Manager](https://swift.org/package-manager).
43+
44+
```swift
45+
let package = Package(
46+
dependencies: [
47+
.package(url: "https://github.com/SDWebImage/SDWebImageLottiePlugin.git", from: "0.1")
48+
]
49+
)
50+
```
51+
52+
## Usage
53+
54+
+ Swift
55+
56+
```swift
57+
let animationView: AnimationView
58+
let lottieJSONURL: URL
59+
animationView.sd_setImage(with: lottieJSONURL)
60+
```
61+
62+
+ Objective-C
63+
64+
Note: Lottie 3.0 was rewritten with Swift, but there are still one compatible view left for Objective-C. Learn more here: http://airbnb.io/lottie/#/ios-migration
65+
66+
```objective-c
67+
CompatibleAnimationView *animationView;
68+
NSURL *lottieJSONURL;
69+
[animationView sd_setImageWithURL:lottieJSONURL];
70+
```
71+
72+
## Demo
73+
74+
If you have some issue about usage, SDWebImageLottiePlugin provide a demo for iOS && macOS platform. To run the demo, clone the repo and run the following command.
75+
76+
```bash
77+
cd Example/
78+
pod install
79+
open SDWebImageLottiePlugin.xcworkspace
80+
```
81+
82+
After the Xcode project was opened, click `Run` to build and run the demo.
83+
84+
## Screenshot
85+
86+
<img src="https://raw.githubusercontent.com/SDWebImage/SDWebImageLottiePlugin/master/Example/Screenshot/LottieDemo.gif" width="300" />
87+
88+
The lottie json is from [lottie-web example](https://github.com/airbnb/lottie-web/tree/master/demo/gatin)
89+
2390
## Author
2491

25-
lizhuoli1126@126.com, lizhuoli1126@126.com
92+
DreamPiggy
2693

2794
## License
2895

SDWebImageLottiePlugin.podspec

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,17 @@ Pod::Spec.new do |s|
2121
TODO: Add long description of the pod here.
2222
DESC
2323

24-
s.homepage = 'https://github.com/lizhuoli1126@126.com/SDWebImageLottiePlugin'
25-
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
24+
s.homepage = 'https://github.com/SDWebImage/SDWebImageLottiePlugin'
2625
s.license = { :type => 'MIT', :file => 'LICENSE' }
27-
s.author = { 'lizhuoli1126@126.com' => 'lizhuoli1126@126.com' }
28-
s.source = { :git => 'https://github.com/lizhuoli1126@126.com/SDWebImageLottiePlugin.git', :tag => s.version.to_s }
29-
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
30-
31-
s.ios.deployment_target = '8.0'
26+
s.author = { 'DreamPiggy' => 'lizhuoli1126@126.com' }
27+
s.source = { :git => 'https://github.com/SDWebImage/SDWebImageLottiePlugin.git', :tag => s.version.to_s }
28+
s.swift_version = '5.0'
29+
s.ios.deployment_target = '9.0'
30+
s.osx.deployment_target = '10.10'
31+
s.tvos.deployment_target = '9.0'
3232

3333
s.source_files = 'SDWebImageLottiePlugin/Classes/**/*'
34-
35-
# s.resource_bundles = {
36-
# 'SDWebImageLottiePlugin' => ['SDWebImageLottiePlugin/Assets/*.png']
37-
# }
3834

39-
# s.public_header_files = 'Pod/Classes/**/*.h'
40-
# s.frameworks = 'UIKit', 'MapKit'
41-
# s.dependency 'AFNetworking', '~> 2.3'
35+
s.dependency 'SDWebImage', '~> 5.1'
36+
s.dependency 'lottie-ios', '~> 3.1'
4237
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// AnimatedControl+WebCache.swift
3+
// SDWebImageLottiePlugin
4+
//
5+
// Created by 李卓立 on 2020/2/29.
6+
//
7+
8+
import SDWebImage
9+
import Lottie
10+
11+
extension AnimatedControl {
12+
/**
13+
* Set the imageView `image` with an `url`, placeholder, custom options and context.
14+
*
15+
* The download is asynchronous and cached.
16+
*
17+
* @param url The url for the image.
18+
* @param placeholder The image to be set initially, until the image request finishes.
19+
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
20+
* @param context A context contains different options to perform specify changes or processes, see `SDWebImageContextOption`. This hold the extra objects which `options` enum can not hold.
21+
* @param progressBlock A block called while image is downloading
22+
* @note the progress block is executed on a background queue
23+
* @param completedBlock A block called when operation has been completed. This block has no return value
24+
* and takes the requested UIImage as first parameter. In case of error the image parameter
25+
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
26+
* indicating if the image was retrieved from the local cache or from the network.
27+
* The fourth parameter is the original image url.
28+
*/
29+
public func sd_setImage(with url: URL?, placeholderImage placeholder: UIImage? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil, progress progressBlock: SDImageLoaderProgressBlock? = nil, completed completedBlock: SDExternalCompletionBlock? = nil) {
30+
var context = context ?? [:]
31+
context[.animatedImageClass] = LottieImage.self
32+
self.sd_internalSetImage(with: url, placeholderImage: placeholder, options: options, context: context, setImageBlock: { [weak self] (image, data, cacheType, url) in
33+
if let lottieImage = image as? LottieImage {
34+
self?.animation = lottieImage.animation
35+
} else {
36+
self?.animation = nil
37+
}
38+
}, progress: progressBlock) { (image, data, error, cacheType, finiseh, url) in
39+
completedBlock?(image, error, cacheType, url)
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)