Coder Social home page Coder Social logo

pinwheel's Introduction

Pinwheel

Build Status Carthage compatible

Pinwheel is an Image Loading library written in Swift

Features

  • Comprehensive Unit Test Coverage
  • Carthage support
  • Priority control in accordance with the visibility
  • Combine HTTP Request to the same URL
  • Memory Cache
  • Disk Cache
  • Timeout Settings ( timeoutIntervalForRequest / timeoutIntervalForResource )
  • Cache Settings
  • ImageLoadingListener

Architecture

Architecture

Usage

Minimum

ImageLoader.displayImage(url, imageView: imageView)

Optimized for violent scroll. eg. Twitter Client

With .BeforeMemory, it is individually cache.

memory Many consume, but the cost of the display is low.

.BeforeMemory is sufficient if you do not use waterfall layout.

import UIKit
import Pinwheel

struct MyDisplayOptions {
    static let photo = DisplayOptions.Builder()
        .displayer(FadeInDisplayer())
        .queuePriority(NSOperationQueuePriority.Low)
        .prepare { (imageView) -> Void in
            // run only at the time of download
            imageView.image = UIImage(named: "Loading")
        }
        .failure { (imageView, reason, error, requestURL) -> Void in
            switch reason {
            case .EmptyUri:
                imageView.image = UIImage(named: "Empty")
            case .InvalidData:
                imageView.image = UIImage(named: "Broken")
            case .NetworkError:
                imageView.image = UIImage(named: "Cancel")
            }
        }
        .build()

    static let userIcon = DisplayOptions.Builder()
        .addFilter(RoundedFilter(r: 6, w: 42, h: 42), hook: .BeforeMemory)
        .displayer(FadeInDisplayer())
        .build()

    static let userIconXS = DisplayOptions.Builder()
        .addFilter(RoundedFilter(r: 2, w: 16, h: 16), hook: .BeforeMemory)
        .displayer(FadeInDisplayer())
        .build()
}

// photo
ImageLoader.displayImage(url, imageView: imageView, options: MyDisplayOptions.photo)

// user icon
ImageLoader.displayImage(url, imageView: imageView, options: MyDisplayOptions.userIcon)

// small user icon
ImageLoader.displayImage(url, imageView: imageView, options: MyDisplayOptions.userIconXS)

Suspend display queue

func scrollToTop() {
    ImageLoader.suspend = true
    self.tableView.setContentOffset(CGPointZero, animated: true)
}

func scrollEnd() {
    ImageLoader.suspend = false
}

Cache Settings

// Simple
DiskCache.sharedInstance().cacheSize(10 * 1024 * 1024)

// Professional
DisplayOptions.Builder()
    .diskCache(YourDiskCache())
    .memoryCache(YourMemoryCache())
    .build()

ImageLoadingListener / ImageLoadingProgressListener

class DebugListener: ImageLoadingListener {
    func onLoadingCancelled(url: NSURL, imageView: UIImageView) {
        NSLog("onLoadingCancelled: url:\(url.absoluteString)")
    }
    func onLoadingComplete(url: NSURL, imageView: UIImageView, image: UIImage, loadedFrom: LoadedFrom) {
        NSLog("onLoadingComplete: url:\(url.absoluteString)")
    }
    func onLoadingFailed(url: NSURL, imageView: UIImageView, reason: FailureReason) {
        NSLog("onLoadingFailed: url:\(url.absoluteString)")
    }
    func onLoadingStarted(url: NSURL, imageView: UIImageView) {
        NSLog("onLoadingStarted: url:\(url.absoluteString)")
    }
}

class DebugProgressListener: ImageLoadingProgressListener {
    func onProgressUpdate(url: NSURL, imageView: UIImageView, current: Int64, total: Int64) {
        NSLog("onProgressUpdate: url:\(url.absoluteString) \(current)/\(total)")
    }
}

ImageLoader.displayImage(url, imageView: imageView, options: Static.defaultOptions,
    loadingListener: DebugListener(),
    loadingProgressListener: DebugProgressListener())

Cancel

ImageLoader.cancelRequest(url)

// or

ImageLoader.cancelRequest(imageView)

Requirements

  • iOS 8.0+
  • Xcode 7.3+

Installation

Carthage

Add the following line to your Cartfile

github "s-aska/Pinwheel"

CocoaPods

Add the following line to your Podfile

use_frameworks!
pod 'Pinwheel', :git => '[email protected]:s-aska/Pinwheel.git'

License

Pinwheel is released under the MIT license. See LICENSE for details.

pinwheel's People

Contributors

s-aska avatar

Stargazers

Kei Takahashi avatar Bob Edmonston avatar daichan4649 avatar Ryuzo Yamamoto avatar OKAMURA Naoki aka nyarla / kalaclista avatar

Watchers

 avatar

Forkers

wangpeng1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.