Giter Site home page Giter Site logo

bonavigationpulltorefresh's Introduction

BONavigationPullToRefresh

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

The Demo project requires iOS9

Requirements

Installation

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

pod "BONavigationPullToRefresh"

To start using simply configure the current ViewController import:

import BONavigationPullToRefresh

Simple usecase

class ExampleViewController: UIViewController, NavigationPullRefreshable {
  let fakeLoadingTime = dispatch_time(DISPATCH_TIME_NOW, Int64(4 * NSEC_PER_SEC))
  @IBOutlet weak var scrollView: UIScrollView!

  override func viewDidLoad() {
    super.viewDidLoad()

    // Maximum height for the loading view
    let maxHeight: CGFloat = self.navigationController?.navigationBar.absoluteHeight ?? 10

    // Configurations to animate the default RefreshableView
    let configurations = DefaultRefreshingViewConfigurations(maxHeight: maxHeight,
                                                             image: UIImage(named: "sample"))

    let refreshableView = DefaultRefreshingView(configurations: configurations)


    addNavigationPullToRefresh(toScrollView: self.scrollView, refreshingView: refreshableView) {
      let fakeLoadingTime = dispatch_time(DISPATCH_TIME_NOW, Int64(10 * NSEC_PER_SEC))
      dispatch_after(fakeLoadingTime, dispatch_get_main_queue()) {
        self.endRefreshing()
      }
    }
  }
}

RefreshingView

The refreshingView is a UIView that conforms to protocol RefreshableView:

public protocol RefreshableView {
  // View will start refreshing
  func startRefreshing()

  // Loading has beed canceled due to ViewController disapear
  func cancelRefreshing()

  // Loading has finished successfully
  func endRefreshing()

  // View needs to be updated to the percentage of loading given (bettween 0 - 1)
  func updateLoadingItem(percentage: CGFloat)
}

You can use the DefaultRefreshingView that only updates its alpha as it is shown in the example.

DefaultRefreshingView

  // configurations is a DefaultRefreshingViewConfigurations
  DefaultRefreshingView(configurations: configurations)

DefaultRefreshingViewConfigurations

public struct DefaultRefreshingViewConfigurations {

// Maximum view Size
var maxHeight: CGFloat = 80

  // View inset
  var inset = CGPoint.zero

  // Image to be shown
  var image: UIImage?

  // Scaling option of the UIImageView
  var imageOptions = UIViewContentMode.ScaleToFill

  // Animation time
  var animationTime: NSTimeInterval = 1

  // Fade animation Time
  var animationFadeTime: NSTimeInterval = 0.5
}

End refreshing

self.endRefreshing()

Lifecycle

To keep the viewControllers stack lifecycle its needed to call three more methods on your ViewController:

override func viewWillAppear(animated: Bool) {
  super.viewWillAppear(animated)
  viewControllerWillShow()
}

override func viewDidAppear(animated: Bool) {
  super.viewDidAppear(animated)
  viewControllerDidShow()
}

override func viewWillDisappear(animated: Bool) {
  super.viewWillDisappear(animated)
  viewControllerWillDisappear()
}

All the supported methods in the NavigationPullRefreshable are :

public protocol NavigationPullRefreshable {
  // Configure the NavigationPullToRefresh
  func addNavigationPullToRefresh(toScrollView scrollView: UIScrollView,
                                               refreshingView: RefreshableView,
                                               startLoading: () -> Void)

  // You must call when the ViewController appears to pause loader when viewController is pushed
  func viewControllerWillShow()

  // You must call when the ViewController didAppear to set the refreshable view below the title
  func viewControllerDidShow()

  // You must call when the ViewController will disappear to pause loader when viewController is popped
  // or pushed
  func viewControllerWillDisappear()

  func endRefreshing()
}

Configurations

  // Distance needed to trigger refresh
  public var triggerDistance: CGFloat = 80

Author

Bruno Oliveira, [email protected]

License

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

bonavigationpulltorefresh's People

Contributors

bmoliveira avatar ivanbruel avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

ivanbruel

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.