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

Add support for optional streaming state #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed Demo/TableViewPull/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
typedef enum{
EGOOPullRefreshPulling = 0,
EGOOPullRefreshNormal,
EGOOPullRefreshLoading,
EGOOPullRefreshLoading,
EGOOPullRefreshStreaming,
} EGOPullRefreshState;

@protocol EGORefreshTableHeaderDelegate;
Expand All @@ -55,11 +56,14 @@ typedef enum{
- (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView;
- (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView;
- (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView;
- (void)egoRefreshScrollViewDataSourceDidBeginStreaming:(UIScrollView *)scrollView;
- (void)egoRefreshScrollViewDataSourceDidEndStreaming:(UIScrollView *)scrollView;

@end
@protocol EGORefreshTableHeaderDelegate
- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view;
- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view;
@optional
- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view;
- (BOOL)egoRefreshTableHeaderDataSourceIsStreaming:(EGORefreshTableHeaderView *)view;
@end
60 changes: 50 additions & 10 deletions EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ - (id)initWithFrame:(CGRect)frame arrowImageName:(NSString *)arrow textColor:(UI
_activityView = view;
[view release];


[self setState:EGOOPullRefreshNormal];

}
Expand All @@ -107,7 +106,11 @@ - (id)initWithFrame:(CGRect)frame {
#pragma mark Setters

- (void)refreshLastUpdatedDate {

if (_state == EGOOPullRefreshStreaming) {
_lastUpdatedLabel.text = nil;
return;
}

if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceLastUpdated:)]) {

NSDate *date = [_delegate egoRefreshTableHeaderDataSourceLastUpdated:self];
Expand Down Expand Up @@ -171,11 +174,22 @@ - (void)setState:(EGOPullRefreshState)aState{
[CATransaction commit];

break;
case EGOOPullRefreshStreaming:

_statusLabel.text = NSLocalizedString(@"Streaming...", @"Streaming status");
[_activityView startAnimating];
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
_arrowImage.hidden = YES;
[CATransaction commit];

break;
default:
break;
}

_state = aState;
[self refreshLastUpdatedDate];
}


Expand Down Expand Up @@ -214,11 +228,15 @@ - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView {
- (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView {

BOOL _loading = NO;
BOOL _streaming = NO;
if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceIsLoading:)]) {
_loading = [_delegate egoRefreshTableHeaderDataSourceIsLoading:self];
}
if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceIsStreaming:)]) {
_streaming = [_delegate egoRefreshTableHeaderDataSourceIsStreaming:self];
}

if (scrollView.contentOffset.y <= - 65.0f && !_loading) {
if (scrollView.contentOffset.y <= - 65.0f && !_loading && !_streaming) {

if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDidTriggerRefresh:)]) {
[_delegate egoRefreshTableHeaderDidTriggerRefresh:self];
Expand All @@ -235,14 +253,36 @@ - (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView {
}

- (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
[scrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];
[UIView commitAnimations];

[self setState:EGOOPullRefreshNormal];
if (_state == EGOOPullRefreshLoading) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
[scrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];
[UIView commitAnimations];
}

[self setState:EGOOPullRefreshNormal];
}

- (void)egoRefreshScrollViewDataSourceDidBeginStreaming:(UIScrollView *)scrollView {
if (_state == EGOOPullRefreshLoading) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
[scrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];
[UIView commitAnimations];
}

[self setState:EGOOPullRefreshStreaming];
}

- (void)egoRefreshScrollViewDataSourceDidEndStreaming:(UIScrollView *)scrollView {
if (_state == EGOOPullRefreshLoading) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
[scrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];
[UIView commitAnimations];
}

[self setState:EGOOPullRefreshNormal];
}


Expand Down