Skip to content

Commit

Permalink
Update TKWebViewController to use WKWebView
Browse files Browse the repository at this point in the history
  • Loading branch information
devinross committed Nov 10, 2020
1 parent 7dbe4df commit 57c0419
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 51 deletions.
4 changes: 3 additions & 1 deletion Examples/Examples/RootTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ @implementation RootTableViewController

- (void) viewDidLoad {
[super viewDidLoad];
self.items = @[@"Card Modal",@"Custom Text Fields",@"Gestures Blocks",@"Action Sheet Blocks",@"Custom Keyboards",@"Video View Controller",@"Screen Brightness",@"PDF Generation",@"Colors",@"Progress Task",@"Text View",@"Velocity"];
self.items = @[@"Card Modal",@"Custom Text Fields",@"Gestures Blocks",@"Action Sheet Blocks",@"Custom Keyboards",@"Video View Controller",@"Screen Brightness",@"PDF Generation",@"Colors",@"Progress Task",@"Text View",@"Velocity",@"Web"];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:IDENTIFIER];
self.title = NSLocalizedString(@"Curry", @"");
}
Expand Down Expand Up @@ -92,6 +92,8 @@ - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
ctr = TextViewViewController.new;
else if(indexPath.row == 11){
ctr = VelocityViewController.new;
}else if(indexPath.row == 12){
ctr = [[TKWebViewController alloc] initWithURL:[NSURL URLWithString:@"https://apple.com"]];
}

[self.navigationController pushViewController:ctr animated:YES];
Expand Down
8 changes: 4 additions & 4 deletions curry/ViewControllers/TKWebViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@


@import UIKit;
@import WebKit;


/** This class creates a `UIViewController` with a basic `UIWebView` as the focal point view. */
@interface TKWebViewController : UIViewController <UIWebViewDelegate>
/** This class creates a `UIViewController` with a basic `WKWebView` as the focal point view. */
@interface TKWebViewController : UIViewController


/** Initializes a web view controller that will load the given `NSURL` object.
Expand All @@ -59,7 +59,7 @@
@property (nonatomic,strong) NSURLRequest *URLRequest;

/** Returns the `UIWebView` managed by the controller object. */
@property (nonatomic,strong) UIWebView *webView;
@property (nonatomic,strong) WKWebView *webView;

/** Returns the `UIBarButtonItem` that shows the share sheet. */
@property (nonatomic,strong) UIBarButtonItem *actionBarButtonItem;
Expand Down
92 changes: 46 additions & 46 deletions curry/ViewControllers/TKWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ - (instancetype) initWithURLRequest:(NSURLRequest*)URLRequest{
}

- (void) dealloc{
_webView.delegate = nil;
_webView.UIDelegate = nil;
_webView.navigationDelegate = nil;
[_webView stopLoading];
}

#pragma mark View Lifecycle
- (void) loadView{
[super loadView];
self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
self.webView.delegate = self;
self.webView.scalesPageToFit = YES;
self.webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
// self.webView.scalesPageToFit = YES;
self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.webView];
}
Expand All @@ -74,50 +74,50 @@ - (void) viewDidLoad{
}

#pragma mark Button Actions
- (void) showActionSheet:(UIBarButtonItem*)sender{
NSURL *currentURL = self.webView.request.URL;
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[currentURL] applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll, UIActivityTypeAssignToContact];


if([UIDevice currentDevice].padIdiom){

UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];
[popup presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}else{

[self presentViewController:activityVC animated:YES completion:nil];

}

}
//- (void) showActionSheet:(UIBarButtonItem*)sender{
// NSURL *currentURL = self.webView.request.URL;
// UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[currentURL] applicationActivities:nil];
// activityVC.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll, UIActivityTypeAssignToContact];
//
//
// if([UIDevice currentDevice].padIdiom){
//
// UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];
// [popup presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
//
// }else{
//
// [self presentViewController:activityVC animated:YES completion:nil];
//
// }
//
//}

#pragma mark UIWebviewDelegate
- (void) webViewDidStartLoad:(UIWebView *)webView{
if(self.navigationItem.rightBarButtonItem == _actionBarButtonItem)
self.navigationItem.rightBarButtonItem = self.loadingActivityBarButtonItem;
}
- (void) webViewDidFinishLoad:(UIWebView *)webView {
if(self.navigationItem.rightBarButtonItem == _loadingActivityBarButtonItem)
self.navigationItem.rightBarButtonItem = self.actionBarButtonItem;
self.title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
}
- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
if(self.navigationItem.rightBarButtonItem == _loadingActivityBarButtonItem)
self.navigationItem.rightBarButtonItem = self.actionBarButtonItem;
self.title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
}
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

if(self.navigationController && (navigationType == UIWebViewNavigationTypeFormSubmitted || navigationType == UIWebViewNavigationTypeLinkClicked)){
TKWebViewController *vc = [[[self class] alloc] initWithURLRequest:request];
[self.navigationController pushViewController:vc animated:YES];
return NO;
}

return YES;
}
//- (void) webViewDidStartLoad:(UIWebView *)webView{
// if(self.navigationItem.rightBarButtonItem == _actionBarButtonItem)
// self.navigationItem.rightBarButtonItem = self.loadingActivityBarButtonItem;
//}
//- (void) webViewDidFinishLoad:(UIWebView *)webView {
// if(self.navigationItem.rightBarButtonItem == _loadingActivityBarButtonItem)
// self.navigationItem.rightBarButtonItem = self.actionBarButtonItem;
// self.title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
//}
//- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
// if(self.navigationItem.rightBarButtonItem == _loadingActivityBarButtonItem)
// self.navigationItem.rightBarButtonItem = self.actionBarButtonItem;
// self.title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
//}
//- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
//
// if(self.navigationController && (navigationType == UIWebViewNavigationTypeFormSubmitted || navigationType == UIWebViewNavigationTypeLinkClicked)){
// TKWebViewController *vc = [[[self class] alloc] initWithURLRequest:request];
// [self.navigationController pushViewController:vc animated:YES];
// return NO;
// }
//
// return YES;
//}


- (void) dismiss:(id)sender{
Expand Down

0 comments on commit 57c0419

Please sign in to comment.