Skip to content

Commit 3e96b33

Browse files
committed
网页进度条优化&任务、讨论评论支持复制
1 parent 5049b05 commit 3e96b33

7 files changed

Lines changed: 42 additions & 14 deletions

File tree

Coding_iOS/Coding_iOS-Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>3.3</string>
20+
<string>3.5</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleURLTypes</key>
@@ -36,7 +36,7 @@
3636
</dict>
3737
</array>
3838
<key>CFBundleVersion</key>
39-
<string>3.3.20151019190000</string>
39+
<string>3.5.102511191800</string>
4040
<key>LSApplicationQueriesSchemes</key>
4141
<array>
4242
<string>wechat</string>

Coding_iOS/Controllers/WebViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ - (void)viewDidLoad{
6464
@weakify(self);
6565
_progressProxy.progressBlock = ^(float progress) {
6666
@strongify(self);
67-
[self.progressView setProgress:progress animated:NO];
67+
[self.progressView setProgress:progress animated:YES];
6868
};
6969

7070
CGFloat progressBarHeight = 2.f;

Coding_iOS/Vendor/NJKWebViewProgress/NJKWebViewProgress.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
#import <Foundation/Foundation.h>
9+
#import <UIKit/UIKit.h>
910

1011
#undef njk_weak
1112
#if __has_feature(objc_arc_weak)

Coding_iOS/Vendor/NJKWebViewProgress/NJKWebViewProgress.m

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
#import "NJKWebViewProgress.h"
99

10-
NSString *completeRPCURL = @"webviewprogressproxy:///complete";
10+
NSString *completeRPCURLPath = @"/njkwebviewprogressproxy/complete";
1111

1212
const float NJKInitialProgressValue = 0.1f;
1313
const float NJKInteractiveProgressValue = 0.5f;
1414
const float NJKFinalProgressValue = 0.9f;
1515

16+
@interface NJKWebViewProgress ()
17+
@property (strong, nonatomic) NSTimer *timer;
18+
@end
19+
1620
@implementation NJKWebViewProgress
1721
{
1822
NSUInteger _loadingCount;
@@ -35,6 +39,7 @@ - (void)startProgress
3539
{
3640
if (_progress < NJKInitialProgressValue) {
3741
[self setProgress:NJKInitialProgressValue];
42+
[self startUpTimer];
3843
}
3944
}
4045

@@ -52,6 +57,7 @@ - (void)incrementProgress
5257
- (void)completeProgress
5358
{
5459
[self setProgress:1.0];
60+
[self invalidateTimer];
5561
}
5662

5763
- (void)setProgress:(float)progress
@@ -75,12 +81,33 @@ - (void)reset
7581
[self setProgress:0.0];
7682
}
7783

78-
#pragma mark -
84+
#pragma mark timer
85+
- (void)startUpTimer{
86+
NSTimeInterval timeStep = 0.1;
87+
self.timer = [NSTimer scheduledTimerWithTimeInterval:timeStep
88+
target:self
89+
selector:@selector(timerStep:)
90+
userInfo:nil
91+
repeats:YES];
92+
}
93+
94+
- (void)invalidateTimer{
95+
[self.timer invalidate];
96+
self.timer = nil;
97+
}
98+
99+
- (void)timerStep:(NSTimer *)timer {
100+
static float progressStep = 0.02;
101+
if (_progress + progressStep <= NJKFinalProgressValue) {
102+
self.progress += progressStep;
103+
}
104+
}
105+
79106
#pragma mark UIWebViewDelegate
80107

81108
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
82109
{
83-
if ([request.URL.absoluteString isEqualToString:completeRPCURL]) {
110+
if ([request.URL.path isEqualToString:completeRPCURLPath]) {
84111
[self completeProgress];
85112
return NO;
86113
}
@@ -98,9 +125,8 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
98125

99126
BOOL isTopLevelNavigation = [request.mainDocumentURL isEqual:request.URL];
100127

101-
BOOL isHTTP = [request.URL.scheme isEqualToString:@"http"] || [request.URL.scheme isEqualToString:@"https"];
102-
BOOL isFile = [request.URL.scheme isEqualToString:@"file"];//easeeeeeeeee modify
103-
if (ret && !isFragmentJump && (isHTTP || isFile) && isTopLevelNavigation) {
128+
BOOL isHTTPOrLocalFile = [request.URL.scheme isEqualToString:@"http"] || [request.URL.scheme isEqualToString:@"https"] || [request.URL.scheme isEqualToString:@"file"];
129+
if (ret && !isFragmentJump && isHTTPOrLocalFile && isTopLevelNavigation) {
104130
_currentURL = request.URL;
105131
[self reset];
106132
}
@@ -133,7 +159,7 @@ - (void)webViewDidFinishLoad:(UIWebView *)webView
133159
BOOL interactive = [readyState isEqualToString:@"interactive"];
134160
if (interactive) {
135161
_interactive = YES;
136-
NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@'; document.body.appendChild(iframe); }, false);", completeRPCURL];
162+
NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@://%@%@'; document.body.appendChild(iframe); }, false);", webView.request.mainDocumentURL.scheme, webView.request.mainDocumentURL.host, completeRPCURLPath];
137163
[webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS];
138164
}
139165

@@ -158,14 +184,13 @@ - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
158184
BOOL interactive = [readyState isEqualToString:@"interactive"];
159185
if (interactive) {
160186
_interactive = YES;
161-
NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@'; document.body.appendChild(iframe); }, false);", completeRPCURL];
187+
NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@://%@%@'; document.body.appendChild(iframe); }, false);", webView.request.mainDocumentURL.scheme, webView.request.mainDocumentURL.host, completeRPCURLPath];
162188
[webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS];
163189
}
164190

165191
BOOL isNotRedirect = _currentURL && [_currentURL isEqual:webView.request.mainDocumentURL];
166192
BOOL complete = [readyState isEqualToString:@"complete"];
167-
BOOL mainDocumentURLNotExist = !webView.request.mainDocumentURL;
168-
if ((complete && isNotRedirect) || mainDocumentURLNotExist) {
193+
if ((complete && isNotRedirect) || error) {
169194
[self completeProgress];
170195
}
171196
}

Coding_iOS/Vendor/NJKWebViewProgress/NJKWebViewProgressView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ -(void)configureViews
2828
{
2929
self.userInteractionEnabled = NO;
3030
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
31-
_progressBarView = [[UIView alloc] initWithFrame:self.bounds];
31+
_progressBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGRectGetHeight(self.bounds))];
3232
_progressBarView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
3333
UIColor *tintColor = [UIColor colorWithRed:22.f / 255.f green:126.f / 255.f blue:251.f / 255.f alpha:1.0]; // iOS7 Safari bar color
3434
if ([UIApplication.sharedApplication.delegate.window respondsToSelector:@selector(setTintColor:)] && UIApplication.sharedApplication.delegate.window.tintColor) {

Coding_iOS/Views/Cell/TaskCommentCell.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
6969
_contentLabel.font = kTaskCommentCell_FontContent;
7070
_contentLabel.linkAttributes = kLinkAttributes;
7171
_contentLabel.activeLinkAttributes = kLinkAttributesActive;
72+
[_contentLabel addLongPressForCopy];
7273
[self.contentView addSubview:_contentLabel];
7374
}
7475
if (!_timeLabel) {

Coding_iOS/Views/Cell/TopicCommentCell.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
4242
_contentLabel.font = kTopicCommentCell_FontContent;
4343
_contentLabel.linkAttributes = kLinkAttributes;
4444
_contentLabel.activeLinkAttributes = kLinkAttributesActive;
45+
[_contentLabel addLongPressForCopy];
4546
[self.contentView addSubview:_contentLabel];
4647
}
4748
CGFloat commentBtnWidth = 40;

0 commit comments

Comments
 (0)