Skip to content

Commit

Permalink
Allow setting custom activities to SVWebViewController and SVModalWeb…
Browse files Browse the repository at this point in the history
…ViewController.

- Enable readonly access to SVWebViewController from SVModalWebViewController to allow more customization of it
  • Loading branch information
juliensaad committed Oct 12, 2017
1 parent 70e87d9 commit 3daf9e0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions SVWebViewController/SVModalWebViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <UIKit/UIKit.h>

@class SVWebViewController;
@class SVModalWebViewController;

typedef NS_ENUM(NSUInteger, SVWebViewControllerDismissButtonStyle) {
Expand All @@ -28,6 +29,8 @@ typedef NS_ENUM(NSUInteger, SVWebViewControllerDismissButtonStyle) {
- (instancetype)initWithURL:(NSURL *)URL;
- (instancetype)initWithURLRequest:(NSURLRequest *)request;

@property (nonatomic, readonly) SVWebViewController *webViewController;

@property (nonatomic, strong) UIColor *barsTintColor;
@property (nonatomic, weak) id<SVModalWebViewControllerDelegate> webViewDelegate;
@property (nonatomic, assign) SVWebViewControllerDismissButtonStyle dismissButtonStyle;
Expand Down
6 changes: 4 additions & 2 deletions SVWebViewController/SVWebViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

@interface SVWebViewController : UIViewController

- (instancetype)initWithAddress:(NSString*)urlString;
- (instancetype)initWithURL:(NSURL*)URL;
- (instancetype)initWithAddress:(NSString *)urlString;
- (instancetype)initWithURL:(NSURL *)URL;
- (instancetype)initWithURLRequest:(NSURLRequest *)request;

@property (nonatomic, weak) id<UIWebViewDelegate> delegate;

@property (nonatomic, strong) NSMutableArray<UIActivity *> *activities;

@end
15 changes: 12 additions & 3 deletions SVWebViewController/SVWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,11 @@ - (void)stopTapped:(UIBarButtonItem *)sender {
- (void)actionButtonTapped:(id)sender {
NSURL *url = self.webView.request.URL ? self.webView.request.URL : self.request.URL;
if (url != nil) {
NSArray *activities = @[[SVWebViewControllerActivitySafari new], [SVWebViewControllerActivityChrome new]];

if ([[url absoluteString] hasPrefix:@"file:///"]) {
UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:url];
[dc presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
} else {
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:activities];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:self.activities];

#ifdef __IPHONE_8_0
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1 &&
Expand All @@ -308,4 +306,15 @@ - (void)doneButtonTapped:(id)sùender {
[self dismissViewControllerAnimated:YES completion:NULL];
}

- (NSMutableArray<UIActivity *> *)activities {
if (!_activities) {
_activities = [NSMutableArray arrayWithArray:SVWebViewController.defaultActivities];
}
return _activities;
}

+ (NSArray<UIActivity *> *)defaultActivities {
return @[[SVWebViewControllerActivitySafari new], [SVWebViewControllerActivityChrome new]];
}

@end

0 comments on commit 3daf9e0

Please sign in to comment.