Integrating WKWebView, closes #733. Still need to fix broken send to button.

This commit is contained in:
Samuel Clay 2015-09-17 15:56:09 -07:00
parent 5796c00a0b
commit ad3f714259
6 changed files with 99 additions and 150 deletions

View file

@ -1310,6 +1310,10 @@
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:operaURL]];
return;
} else {
if (!originalStoryViewController) {
originalStoryViewController = [[OriginalStoryViewController alloc] init];
}
self.activeOriginalStoryURL = url;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

View file

@ -42,7 +42,7 @@ UIGestureRecognizerDelegate> {
- (IBAction)webViewGoBack:(id)sender;
- (IBAction)webViewGoForward:(id)sender;
- (IBAction)webViewRefresh:(id)sender;
- (void)updateTitle:(UIWebView*)aWebView;
- (void)updateTitle:(WKWebView*)aWebView;
- (void)closeOriginalView;
@end

View file

@ -23,13 +23,76 @@
//@synthesize swiper;
@synthesize progressView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
[webView setNavigationDelegate:self];
[webView setUIDelegate:self];
self.view.layer.masksToBounds = NO;
self.view.layer.shadowRadius = 5;
self.view.layer.shadowOpacity = 0.5;
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;
UIImage *separatorImage = [UIImage imageNamed:@"bar-separator.png"];
UIBarButtonItem *separatorBarButton = [UIBarButtonItem barItemWithImage:separatorImage
target:nil
action:nil];
[separatorBarButton setEnabled:NO];
UIBarButtonItem *sendToBarButton = [UIBarButtonItem
barItemWithImage:[UIImage imageNamed:@"barbutton_sendto.png"]
target:self
action:@selector(doOpenActionSheet:)];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
closeButton = [UIBarButtonItem barItemWithImage:[UIImage imageNamed:@"ios7_back_button"]
target:self
action:@selector(closeOriginalView)];
self.navigationItem.leftBarButtonItem = closeButton;
}
return self;
backBarButton = [UIBarButtonItem
barItemWithImage:[UIImage imageNamed:@"barbutton_back.png"]
target:self
action:@selector(webViewGoBack:)];
backBarButton.enabled = NO;
titleView = [[UILabel alloc] init];
titleView.textColor = UIColorFromRGB(0x303030);
titleView.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0];
titleView.text = @"Loading...";
[titleView sizeToFit];
titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.navigationItem.titleView = titleView;
self.navigationItem.rightBarButtonItems = @[sendToBarButton,
separatorBarButton,
backBarButton
];
webView = [[WKWebView alloc] initWithFrame:self.view.frame];
[webView sizeToFit];
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[webView setNavigationDelegate:self];
[webView setUIDelegate:self];
[self.view addSubview:webView];
[self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:NULL];
CGFloat progressBarHeight = 2.f;
CGRect navigaitonBarBounds = self.navigationController.navigationBar.bounds;
CGRect barFrame = CGRectMake(0, navigaitonBarBounds.size.height - progressBarHeight, navigaitonBarBounds.size.width, progressBarHeight);
progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePanGesture:)];
gesture.delegate = self;
[self.webView.scrollView addGestureRecognizer:gesture];
}
[self.webView loadHTMLString:@"" baseURL:nil];
}
- (void)dealloc {
@ -88,72 +151,8 @@
[progressView setProgress:NJKInitialProgressValue animated:YES];
}
- (void)viewDidLoad {
// self.navigationItem.title = [[appDelegate activeStory] objectForKey:@"story_title"];
[super viewDidLoad];
self.view.layer.masksToBounds = NO;
self.view.layer.shadowRadius = 5;
self.view.layer.shadowOpacity = 0.5;
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.bounds].CGPath;
UIImage *separatorImage = [UIImage imageNamed:@"bar-separator.png"];
UIBarButtonItem *separatorBarButton = [UIBarButtonItem barItemWithImage:separatorImage
target:nil
action:nil];
[separatorBarButton setEnabled:NO];
UIBarButtonItem *sendToBarButton = [UIBarButtonItem
barItemWithImage:[UIImage imageNamed:@"barbutton_sendto.png"]
target:self
action:@selector(doOpenActionSheet:)];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
closeButton = [UIBarButtonItem barItemWithImage:[UIImage imageNamed:@"ios7_back_button"]
target:self
action:@selector(closeOriginalView)];
self.navigationItem.leftBarButtonItem = closeButton;
}
backBarButton = [UIBarButtonItem
barItemWithImage:[UIImage imageNamed:@"barbutton_back.png"]
target:self
action:@selector(webViewGoBack:)];
backBarButton.enabled = NO;
titleView = [[UILabel alloc] init];
titleView.textColor = UIColorFromRGB(0x303030);
titleView.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0];
titleView.text = @"Loading...";
[titleView sizeToFit];
titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.navigationItem.titleView = titleView;
self.navigationItem.rightBarButtonItems = @[sendToBarButton,
separatorBarButton,
backBarButton
];
[self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:NULL];
CGFloat progressBarHeight = 2.f;
CGRect navigaitonBarBounds = self.navigationController.navigationBar.bounds;
CGRect barFrame = CGRectMake(0, navigaitonBarBounds.size.height - progressBarHeight, navigaitonBarBounds.size.width, progressBarHeight);
progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePanGesture:)];
gesture.delegate = self;
[self.webView.scrollView addGestureRecognizer:gesture];
}
[self.webView loadHTMLString:@"" baseURL:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"estimatedProgress"] && object == self.webView) {
NSLog(@"%f", webView.estimatedProgress);
[progressView setProgress:webView.estimatedProgress animated:YES];
if (webView.estimatedProgress == NJKInteractiveProgressValue) {
@ -265,21 +264,23 @@
- (void)loadInitialStory {
finishedLoading = NO;
[self loadAddress:nil];
activeUrl = nil;
titleView.text = [[[appDelegate activeStory] objectForKey:@"story_title"]
stringByDecodingHTMLEntities];
[titleView sizeToFit];
[MBProgressHUD hideHUDForView:self.webView animated:YES];
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.webView animated:YES];
HUD.labelText = @"On its way...";
[HUD hide:YES afterDelay:2];
HUD.userInteractionEnabled = NO;
[self loadAddress:nil];
}
- (IBAction)webViewGoBack:(id)sender {
for (WKBackForwardListItem *item in webView.backForwardList.backList) {
NSLog(@"%@", item.URL);
}
[webView goBack];
NSLog(@" Current: %@", webView.URL);
}
- (IBAction)webViewGoForward:(id)sender {
@ -293,40 +294,23 @@
# pragma mark: -
# pragma mark: UIWebViewDelegate protocol
- (BOOL)webView:(UIWebView *)aWebView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
if ([aWebView canGoBack]) {
- (void)webView:(UIWebView *)aWebView didCommitNavigation:(null_unspecified WKNavigation *)navigation {
if ([webView canGoBack]) {
[backBarButton setEnabled:YES];
} else {
[backBarButton setEnabled:NO];
}
if ([[[request URL] scheme] isEqual:@"mailto"]) {
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
} else if (navigationType == UIWebViewNavigationTypeLinkClicked) {
activeUrl = [[request URL] absoluteString];
[self loadAddress:nil];
return NO;
}
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)aWebView
{
activeUrl = [[webView URL] absoluteString];
finishedLoading = NO;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)aWebView
{
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
[MBProgressHUD hideHUDForView:self.webView animated:YES];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[self updateTitle:aWebView];
[self updateTitle:self.webView];
finishedLoading = YES;
}
@ -345,7 +329,7 @@
- (void)updateTitle:(UIWebView*)aWebView
{
NSString *pageTitleValue = [aWebView stringByEvaluatingJavaScriptFromString:@"document.title"];
NSString *pageTitleValue = webView.title;
titleView.text = [pageTitleValue stringByDecodingHTMLEntities];
[titleView sizeToFit];
}
@ -354,6 +338,15 @@
if (!activeUrl) {
activeUrl = [appDelegate.activeOriginalStoryURL absoluteString];
}
if (![[appDelegate.activeStory objectForKey:@"story_permalink"] isEqualToString:activeUrl]) {
titleView.text = @"Loading...";
} else {
titleView.text = [[[appDelegate activeStory] objectForKey:@"story_title"]
stringByDecodingHTMLEntities];
}
[titleView sizeToFit];
NSString* urlString = activeUrl;
NSURL* url = [NSURL URLWithString:urlString];
// if ([urlString containsString:@"story_images"]) {
@ -374,8 +367,6 @@
// }
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
titleView.text = @"Loading...";
[titleView sizeToFit];
}
- (void)didReceiveMemoryWarning {

View file

@ -115,7 +115,6 @@
43B8F027156603180008733D /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 43B8F01D156603170008733D /* MainWindow.xib */; };
43B8F028156603180008733D /* MoveSiteViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 43B8F01E156603170008733D /* MoveSiteViewController.xib */; };
43B8F029156603180008733D /* NewsBlurViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 43B8F01F156603170008733D /* NewsBlurViewController.xib */; };
43B8F02A156603180008733D /* OriginalStoryViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 43B8F020156603170008733D /* OriginalStoryViewController.xib */; };
43B8F02B156603180008733D /* StoryDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 43B8F021156603170008733D /* StoryDetailViewController.xib */; };
43BC458915D9F75700205B69 /* twitter_button_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 43BC458515D9F75700205B69 /* twitter_button_on.png */; };
43BC458A15D9F75700205B69 /* twitter_button_on@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 43BC458615D9F75700205B69 /* twitter_button_on@2x.png */; };
@ -595,7 +594,6 @@
43B8F01D156603170008733D /* MainWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = "<group>"; };
43B8F01E156603170008733D /* MoveSiteViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MoveSiteViewController.xib; sourceTree = "<group>"; };
43B8F01F156603170008733D /* NewsBlurViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NewsBlurViewController.xib; sourceTree = "<group>"; };
43B8F020156603170008733D /* OriginalStoryViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OriginalStoryViewController.xib; sourceTree = "<group>"; };
43B8F021156603170008733D /* StoryDetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = StoryDetailViewController.xib; sourceTree = "<group>"; };
43BC458515D9F75700205B69 /* twitter_button_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = twitter_button_on.png; sourceTree = "<group>"; };
43BC458615D9F75700205B69 /* twitter_button_on@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "twitter_button_on@2x.png"; sourceTree = "<group>"; };
@ -1643,7 +1641,6 @@
43B8F01D156603170008733D /* MainWindow.xib */,
43B8F01E156603170008733D /* MoveSiteViewController.xib */,
43B8F01F156603170008733D /* NewsBlurViewController.xib */,
43B8F020156603170008733D /* OriginalStoryViewController.xib */,
43081E2115AFE84200B24D7A /* ShareViewController.xib */,
43B8F021156603170008733D /* StoryDetailViewController.xib */,
FF6A23361644903900E15989 /* StoryPageControl.xib */,
@ -2135,7 +2132,6 @@
43B8F027156603180008733D /* MainWindow.xib in Resources */,
43B8F028156603180008733D /* MoveSiteViewController.xib in Resources */,
43B8F029156603180008733D /* NewsBlurViewController.xib in Resources */,
43B8F02A156603180008733D /* OriginalStoryViewController.xib in Resources */,
FF03AFF219F87F2E0063002A /* safari~iPad@2x.png in Resources */,
FF62820E1A1160DD00271FDB /* add_tag.png in Resources */,
43B8F02B156603180008733D /* StoryDetailViewController.xib in Resources */,

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="14D87h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15A282b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="UIApplication">
@ -28,7 +28,6 @@
<outlet property="loginViewController" destination="102" id="103"/>
<outlet property="moveSiteViewController" destination="124" id="126"/>
<outlet property="navigationController" destination="39" id="45"/>
<outlet property="originalStoryViewController" destination="113" id="116"/>
<outlet property="shareViewController" destination="131" id="132"/>
<outlet property="storyDetailViewController" destination="92" id="173"/>
<outlet property="storyPageControl" destination="170" id="172"/>
@ -100,12 +99,6 @@
<outlet property="appDelegate" destination="3" id="175"/>
</connections>
</viewController>
<viewController nibName="OriginalStoryViewController" id="113" customClass="OriginalStoryViewController">
<extendedEdge key="edgesForExtendedLayout"/>
<connections>
<outlet property="appDelegate" destination="3" id="114"/>
</connections>
</viewController>
<viewController id="131" customClass="ShareViewController">
<extendedEdge key="edgesForExtendedLayout"/>
<connections>
@ -160,6 +153,7 @@
<window opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="12" customClass="EventWindow">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
</window>
@ -167,6 +161,7 @@
<extendedEdge key="edgesForExtendedLayout"/>
<navigationBar key="navigationBar" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="41">
<autoresizingMask key="autoresizingMask"/>
<animations/>
</navigationBar>
<viewControllers>
<viewController nibName="NewsBlurViewController" id="40" customClass="NewsBlurViewController">
@ -176,9 +171,4 @@
</viewControllers>
</navigationController>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>

View file

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="15A282b" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="OriginalStoryViewController">
<connections>
<outlet property="view" destination="1" id="39"/>
<outlet property="webView" destination="4" id="VUe-Qa-COg"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="1">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<webView multipleTouchEnabled="YES" contentMode="scaleToFill" scalesPageToFit="YES" id="4" customClass="WKWebView">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/>
<dataDetectorType key="dataDetectorTypes" phoneNumber="YES" link="YES" address="YES" calendarEvent="YES"/>
</webView>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
</view>
</objects>
</document>