Coder Social home page Coder Social logo

mspulltorefreshcontroller's Introduction

Miso's Pull To Refresh Library (blog post here)

Authors

Me and Tim Lee

Pull To Refresh Demo

I've put together a simple sample project that recreates our familiar rainbow loading in the Miso App. The sample artificially creates async work by finding the next largest prime and putting the results into a regular uitableview.

Features

  • does not steal your scrollview's delegate (intrusive), but merely observes the scrollview's contentOffset property (non-intrusive)
  • allows refreshing in all 4 directions (pull down to refresh, pull up to load more?)

How To Use

Note that this library merely abstracts away the refresh cycle logic. It is up to the developer to use this class combined with custom views to create a complete, visually satisfactory solution.

There's only one constructor:

MSPullToRefreshController *ptrc = [[MSPullToRefreshController alloc] initWithScrollView:scrollView delegate:self];

As the Delegate, you must implement these methods to inform the library of your specific refresh requirements:

/*
 * asks the delegate which refresh directions it would like enabled
 */
- (BOOL) pullToRefreshController:(MSPullToRefreshController *) controller canRefreshInDirection:(MSRefreshDirection)direction;

/*
 * inset threshold to engage refresh
 */
- (CGFloat) pullToRefreshController:(MSPullToRefreshController *) controller refreshableInsetForDirection:(MSRefreshDirection) direction;

/*
 * inset that the direction retracts back to after refresh started
 */
- (CGFloat) pullToRefreshController:(MSPullToRefreshController *)controller refreshingInsetForDirection:(MSRefreshDirection)direction;

You may (it is in your best interest to) to implement these methods in order to transform your custom views based on where you are in the refresh cycle:

/*
 * informs the delegate that lifting your finger will trigger a refresh
 * in that direction. This is only called when you cross the refreshable
 * offset defined in the respective MSInflectionOffsets.
 */
- (void) pullToRefreshController:(MSPullToRefreshController *) controller canEngageRefreshDirection:(MSRefreshDirection) direction;

/*
 * informs the delegate that lifting your finger will NOT trigger a refresh
 * in that direction. This is only called when you cross the refreshable
 * offset defined in the respective MSInflectionOffsets.
 */
- (void) pullToRefreshController:(MSPullToRefreshController *) controller didDisengageRefreshDirection:(MSRefreshDirection) direction;

/*
 * informs the delegate that refresh sequence has been started by the user
 * in the specified direction. A good place to start any async work.
 */
- (void) pullToRefreshController:(MSPullToRefreshController *) controller didEngageRefreshDirection:(MSRefreshDirection) direction;

Note that you must manually end a refresh cycle in any direction:

[ptrc finishRefreshingDirection:MSRefreshDirectionTop animated:NO];

You can also programatically start a refresh cycle in any direction:

[ptrc startRefreshingDirection:MSRefreshDirectionTop animated:YES];

Caution

This library will break down if the area of the scrollView's contentSize is smaller (strict) than the area of the scrollView's frame. It is up to the developer to ensure the converse.

License

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

mspulltorefreshcontroller's People

Contributors

bogardon avatar

Watchers

James Cloos avatar Janak Nirmal avatar

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.