Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DragToLoad and InfiniteScroll handlers #10

Closed
wants to merge 6 commits into from

Conversation

jmstone617
Copy link

This update comes with two additional handlers. DragToLoad allows you to drag past the bottom content and trigger a refresh, similar to PullToRefresh. InfiniteScroll will automatically trigger the refresh when 80% of the content has been scrolled through. Additionally, you can set the sectionLoadLimit and the rowLoadLimit to tell your tableView how much content to load at a time. There is also a loadNextPortion method that will handle incrementing the loaded portions and refreshing your content for you; you just need to update your data source.

@Hackmodford
Copy link
Contributor

So essentially you added a pull to refresh to the bottom?
And the ability to load new data as you get closer to the bottom?

@jmstone617
Copy link
Author

Essentially. There are two additional actionHandler blocks for setting it up. One adds a "pull to refresh", as you called it, to the bottom. The other automatically triggers the action handler you specify once 80% of the scroll view's content is scrolled. The second one is similar to Twitter or Facebook, where content continuously appends itself as you scroll down. In SVPullToRefresh I also added a sectionLoadLimit and rowLoadLimit property for tableviews, so you can specify how much content to load at a time. For a scroll view, the contentSize.height just doubles.

@Hackmodford
Copy link
Contributor

That's pretty useful IMHO

@jmstone617
Copy link
Author

Well thank you! Now that I think about it, doubling the contentSize.height probably isn't the best approach, since you'll end up with an exponentially growing contentSize (i.e. 320_2 = 640, 640_2 = 1280, where it should really be contentSize.height + original height, so you get 320, 640, 960, 1280, etc.). I will make that update and update the pull request.

@Hackmodford
Copy link
Contributor

Yeah that is a better idea.

@samvermette
Copy link
Owner

This implementation isn't compliant with the MVC paradigm. You're mixing the dataSource with the pull-to-refresh view itself. The sectionDisplayLimit, rowDisplayLimit and portionsLoaded properties have no place in there. I want to add "infinite loading" functionality to SVPullToRefresh but this definitely isn't the right way to go, sorry.

@jmstone617
Copy link
Author

I'd be interested in your suggestions, as your original issue was wanting to keep everything inside SVPullToRefresh. The better solution would be to add a delegate method that sets these properties, similar to UITableView's data source methods, but I was trying to keep with your original request of one-line-calls and a single class.

@samvermette
Copy link
Owner

@jmstone617 the "load more" handler should be the one taking care of:

  1. fetch the new data
  2. add new data to data source
  3. reload the table view by calling [tableView reloadData]

Therefore, SVPullToRefresh should only implement a mechanism that detects when the scroll view hits bottom, which in turn calls the "load more" handler. Everything else should be implemented by the dev inside the "load more" handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants