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

Publicize web view progress constants. #17

Merged
merged 1 commit into from
Apr 9, 2014
Merged
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
4 changes: 4 additions & 0 deletions NJKWebViewProgress/NJKWebViewProgress.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#define njk_weak unsafe_unretained
#endif

extern const float NJKInitialProgressValue;
extern const float NJKInteractiveProgressValue;
extern const float NJKFinalProgressValue;

typedef void (^NJKWebViewProgressBlock)(float progress);
@protocol NJKWebViewProgressDelegate;
@interface NJKWebViewProgress : NSObject<UIWebViewDelegate>
Expand Down
12 changes: 6 additions & 6 deletions NJKWebViewProgress/NJKWebViewProgress.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

NSString *completeRPCURL = @"webviewprogressproxy:///complete";

static const float initialProgressValue = 0.1;
static const float beforeInteractiveMaxProgressValue = 0.5;
static const float afterInteractiveMaxProgressValue = 0.9;
const float NJKInitialProgressValue = 0.1f;
const float NJKInteractiveProgressValue = 0.5f;
const float NJKFinalProgressValue = 0.9f;

@implementation NJKWebViewProgress
{
Expand All @@ -33,15 +33,15 @@ - (id)init

- (void)startProgress
{
if (_progress < initialProgressValue) {
[self setProgress:initialProgressValue];
if (_progress < NJKInitialProgressValue) {
[self setProgress:NJKInitialProgressValue];
}
}

- (void)incrementProgress
{
float progress = self.progress;
float maxProgress = _interactive ? afterInteractiveMaxProgressValue : beforeInteractiveMaxProgressValue;
float maxProgress = _interactive ? NJKFinalProgressValue : NJKInteractiveProgressValue;
float remainPercent = (float)_loadingCount / (float)_maxLoadCount;
float increment = (maxProgress - progress) * remainPercent;
progress += increment;
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ progressProxy.progressBlock = ^(float progress) {
};
```

You can determine the current state of the document by comparing the `progress` value to one of the provided constants:

```objc
-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
if (progress == NJKInteractiveProgressValue) {
// The web view has finished parsing the document,
// but is still loading sub-resources
}
}
```

This repository contains iOS 7 Safari style bar `NJKWebViewProgressView`. You can choose `NJKWebViewProgressView`, `UIProgressView` or your custom bar.

# Install
Expand Down