Skip to content

Commit 3030620

Browse files
author
jlorich
committed
Merge pull request #78 from cloudspace/70447084_conditionally_hide_up_indicator
conditionally hide the up indicator
2 parents 59210b2 + 66d9fe5 commit 3030620

3 files changed

Lines changed: 95 additions & 35 deletions

File tree

EasyReader/Application/Controllers/Home/EZRHomeViewController.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
/// Displays website that hosts article
4343
@property (nonatomic, strong) EZRNestableWebView *webView_feedItem;
4444

45+
/// The up indicator displayed over the web view to assist in navigating to the top of the page
46+
@property (nonatomic, strong) UIImageView *upIndicatorView;
47+
4548

4649
# pragma mark - Properties
4750

@@ -60,9 +63,20 @@
6063
* @param feedItem The feed item to
6164
*/
6265
- (void) loadURLForFeedItem:(FeedItem *)feedItem;
66+
6367
/**
6468
* Resets the content of the web view
6569
*/
6670
- (void)resetWebView;
6771

72+
/**
73+
* Hides the scroll up indicator
74+
*/
75+
- (void)hideUpInidicator;
76+
77+
/**
78+
* Shows the scroll up indicator
79+
*/
80+
- (void)showUpInidicator;
81+
6882
@end

EasyReader/Application/Controllers/Home/EZRHomeViewController.m

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ @interface EZRHomeViewController()
5454
/// The social sharing toolbar
5555
@property (nonatomic, weak) IBOutlet CLDSocialShareToolbar *socialShareToolbar;
5656

57-
/// The up indicator displayed over the web view to assist in navigating to the top of the page
58-
@property (nonatomic, strong) UIImageView *upIndicatorView;
59-
6057
@end
6158

6259

@@ -90,11 +87,43 @@ @implementation EZRHomeViewController
9087
Feed *lastSelectedFeed;
9188
}
9289

90+
#pragma mark - Public Methods
91+
92+
- (void)loadURLForFeedItem:(FeedItem *)feedItem
93+
{
94+
NSURL *url = [NSURL URLWithString:feedItem.url];
95+
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];
96+
97+
[self.webView_feedItem loadRequest:request];
98+
}
99+
100+
- (void)resetWebView
101+
{
102+
[self.webView_feedItem stopLoading];
103+
104+
NSString *blankHTML = @"<html><head></head><body style=\"background-color: #000000;\"></body></html>";
105+
[self.webView_feedItem loadHTMLString:blankHTML
106+
baseURL:nil];
107+
}
108+
109+
- (void)hideUpInidicator {
110+
[UIView animateWithDuration:0.5f animations:^{
111+
[self.upIndicatorView setAlpha:0.0f];
112+
}];
113+
}
114+
115+
- (void)showUpInidicator {
116+
[UIView animateWithDuration:0.5f animations:^{
117+
[self.upIndicatorView setAlpha:1.0f];
118+
}];
119+
}
120+
93121
- (FeedItem *)currentFeedItem
94122
{
95123
return self.collectionView_feedItems.currentFeedItem;
96124
}
97125

126+
98127
#pragma mark - UIViewController Methods
99128

100129
/**
@@ -263,12 +292,7 @@ -(void)setUpWebView
263292
[self.upIndicatorView addGestureRecognizer:tapRecognizer];
264293
}
265294

266-
/**
267-
* Scrolls the main containing scroll view to the top (animated)
268-
*/
269-
- (void) scrollToTop {
270-
[self.scrollView_vertical setContentOffset:CGPointMake(0,0) animated:YES];
271-
}
295+
272296

273297

274298
#pragma mark - Observations
@@ -328,7 +352,7 @@ - (void) visibleFeedItemsDidChange:(EZRCurrentFeedsProvider *)currentFeedService
328352
}
329353

330354

331-
#pragma mark - IBActions
355+
#pragma mark - Actions
332356

333357
// Receives left menu link click
334358
- (IBAction)buttonLeftMenu_touchUpInside_goToMenu:(id)sender {
@@ -356,6 +380,15 @@ - (void)scrollToFeedItem:(FeedItem *)feedItem
356380
[_collectionView_feedItems scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
357381
}
358382

383+
/**
384+
* Scrolls the main containing scroll view to the top (animated)
385+
*/
386+
- (void) scrollToTop {
387+
[self.scrollView_vertical setContentOffset:CGPointMake(0,0) animated:YES];
388+
}
389+
390+
#pragma mark - Prefetching
391+
359392
/**
360393
* Fetches the current feed item image, then prefetches after
361394
*/
@@ -388,33 +421,9 @@ - (void)prefetchImagesNearIndex:(NSInteger)currentPageIndex count:(NSInteger)cou
388421
NSArray *itemsToPrefetch = [self.currentFeedsProvider.visibleFeedItems subarrayWithRange:fetchRange];
389422

390423
[[EZRFeedImageService shared] prefetchImagesForFeedItems:itemsToPrefetch];
391-
392424
}
393425

394-
/**
395-
* Loads the url for the new feed item in the web view
396-
*
397-
* @param feedItem The feed item to
398-
*/
399-
- (void) loadURLForFeedItem:(FeedItem *)feedItem
400-
{
401-
NSURL *url = [NSURL URLWithString:feedItem.url];
402-
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];
403426

404-
[self.webView_feedItem loadRequest:request];
405-
}
406-
407-
/**
408-
* Resets the content of the web view
409-
*/
410-
- (void)resetWebView
411-
{
412-
[self.webView_feedItem stopLoading];
413-
414-
NSString *blankHTML = @"<html><head></head><body style=\"background-color: #000000;\"></body></html>";
415-
[self.webView_feedItem loadHTMLString:blankHTML
416-
baseURL:nil];
417-
}
418427

419428
@end
420429

EasyReader/Application/Controllers/Home/EZRHomeWebViewDelegate.m

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@
1111

1212
@implementation EZRHomeWebViewDelegate
1313
{
14+
/// The home view controller
1415
EZRHomeViewController *controller;
15-
16+
17+
/// The bar progress view
1618
NJKWebViewProgressView *progressView;
19+
20+
/// Is the page currently being dragged
21+
BOOL dragging;
22+
23+
/// The staring point of the current drag
24+
CGPoint dragStart;
1725
}
1826

1927
- (instancetype)initWithController:(EZRHomeViewController *)homeController
@@ -29,6 +37,12 @@ - (instancetype)initWithController:(EZRHomeViewController *)homeController
2937
return self;
3038
}
3139

40+
41+
#pragma mark - NJKWebViewProgressDelegate methods
42+
43+
/**
44+
* Adds the progress view object if it doesn't exist, update the progress
45+
*/
3246
- (void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
3347
{
3448
if (!progressView) {
@@ -39,4 +53,27 @@ - (void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(fl
3953
[progressView setProgress:progress animated:NO];
4054
}
4155

56+
57+
#pragma mark - UIScrollViewDelegate methods
58+
59+
/**
60+
* Only allows the scroll-up indicator to be visible on the top 5% of the page or when the user is scrolling up
61+
*/
62+
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
63+
if (scrollView.contentOffset.y > dragStart.y && scrollView.contentOffset.y > scrollView.contentSize.height*.05) {
64+
[controller hideUpInidicator];
65+
} else {
66+
[controller showUpInidicator];
67+
}
68+
}
69+
70+
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
71+
dragging = YES;
72+
dragStart = scrollView.contentOffset;
73+
}
74+
75+
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
76+
dragging = NO;
77+
}
78+
4279
@end

0 commit comments

Comments
 (0)