Skip to content

Commit

Permalink
Update case naming
Browse files Browse the repository at this point in the history
  • Loading branch information
kaishin committed Jun 23, 2024
1 parent b60d5cf commit 24bc14e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Test

on:
on:
push:
branches:
- master
- master
pull_request:
branches:
- master
- master

jobs:
build:
Expand All @@ -15,8 +15,8 @@ jobs:
DEVELOPER_DIR: /Applications/Xcode_15.0.1.app/Contents/Developer

steps:
- uses: actions/checkout@v1
- name: Run iOS tests
run: make test-ios
- name: Run tvOS tests
run: make test-tvos
- uses: actions/checkout@v1
- name: Run iOS tests
run: make test-ios
- name: Run tvOS tests
run: make test-tvos
1 change: 1 addition & 0 deletions Demo/Demo-iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ViewController: UIViewController {

func animate() {
imageView.setFrameBufferSize(1)

imageView.animate(withGIFNamed: currentGIFName, preparationBlock: {
DispatchQueue.main.async {
self.imageDataLabel.text = self.currentGIFName.capitalized + " (\(self.imageView.frameCount) frames / \(String(format: "%.2f", self.imageView.gifLoopDuration))s)"
Expand Down
6 changes: 2 additions & 4 deletions Sources/Gifu/Classes/Animator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,14 @@ public class Animator {

if store.isFinished {
stopAnimating()
if let animationBlock = animationBlock {
animationBlock()
}
animationBlock?()
return
}

store.shouldChangeFrame(with: displayLink.duration) {
if $0 {
delegate.animatorHasNewFrame()
if store.isLoopFinished, let loopBlock = loopBlock {
if store.isLoopFinished, let loopBlock {
loopBlock()
}
}
Expand Down
18 changes: 11 additions & 7 deletions Sources/Gifu/Classes/FrameStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import UIKit

/// Responsible for storing and updating the frames of a single GIF.
class FrameStore {
/// The strategy to use for frame cache.
enum FrameCachingStrategy: Equatable {
case keepUpcoming(Int)
case keepAll
// Cache only a given number of upcoming frames.
case cacheUpcoming(Int)

// Cache all frames.
case cacheAll
}

/// The caching strategy to use for frames
Expand Down Expand Up @@ -39,12 +43,12 @@ class FrameStore {
/// The content mode to use when resizing.
let contentMode: UIView.ContentMode

/// Maximum number of upcoming frames to pre-load.
/// Maximum number of upcoming frames to keep in the cache.
/// Defaults to 10 when all frames are cached indefinitely.
var frameBufferSize: Int {
switch cachingStrategy {
case .keepUpcoming(let size): size
case .keepAll: 10
case .cacheUpcoming(let size): size
case .cacheAll: 10
}
}

Expand Down Expand Up @@ -113,7 +117,7 @@ class FrameStore {
self.imageSource = CGImageSourceCreateWithData(data as CFData, options) ?? CGImageSourceCreateIncremental(options)
self.size = size
self.contentMode = contentMode
self.cachingStrategy = frameBufferSize > 0 ? .keepUpcoming(frameBufferSize) : .keepAll
self.cachingStrategy = frameBufferSize > 0 ? .cacheUpcoming(frameBufferSize) : .cacheAll
self.loopCount = loopCount
}

Expand Down Expand Up @@ -194,7 +198,7 @@ private extension FrameStore {

/// Updates the frames by preloading new ones and replacing the previous frame with a placeholder.
func updateFrameCache() {
if case let .keepUpcoming(size) = cachingStrategy,
if case let .cacheUpcoming(size) = cachingStrategy,
size < frameCount - 1 {
deleteCachedFrame(at: previousFrameIndex)
}
Expand Down

0 comments on commit 24bc14e

Please sign in to comment.