Skip to content

Commit

Permalink
Supports background gif decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
xspyhack committed May 18, 2019
1 parent b20bac4 commit 7c66083
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/Views/AnimatedImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ open class AnimatedImageView: UIImageView {
/// Default is `true`.
public var needsPrescaling = true

/// Decode the GIF frames in background thread before using. It will decode frames data and do a off-screen
/// rendering to extract pixel information in background. This can reduce the main thread CPU usage.
public var backgroundDecode = true

/// The animation timer's run loop mode. Default is `RunLoop.Mode.common`.
/// Set this property to `RunLoop.Mode.default` will make the animation pause during UIScrollView scrolling.
public var runLoopMode = KFRunLoopModeCommon {
Expand Down Expand Up @@ -251,6 +255,7 @@ open class AnimatedImageView: UIImageView {
preloadQueue: preloadQueue)
animator.delegate = self
animator.needsPrescaling = needsPrescaling
animator.backgroundDecode = backgroundDecode
animator.prepareFramesAsynchronously()
self.animator = animator
}
Expand Down Expand Up @@ -361,6 +366,9 @@ extension AnimatedImageView {
var isFinished: Bool = false

var needsPrescaling = true

var backgroundDecode = true

weak var delegate: AnimatorDelegate?

// Total duration of one animation loop
Expand Down Expand Up @@ -501,7 +509,8 @@ extension AnimatedImageView {
return nil
}

return Image(cgImage: cgImage)
let image = Image(cgImage: cgImage)
return backgroundDecode ? image.kf.decoded : image
}

private func updatePreloadedFrames() {
Expand Down

0 comments on commit 7c66083

Please sign in to comment.