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

Prettier URL in navigation bar and custom share items #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion KINWebBrowser/KINWebBrowserViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,21 @@
@property (nonatomic, assign) BOOL showsURLInNavigationBar;
@property (nonatomic, assign) BOOL showsPageTitleInNavigationBar;

//Allow for custom activities in the browser by populating this optional array
/*
Allow for custom activities in the browser by populating this optional array

Warning: Custom activities is actualy not the right name for this property.
This array will be used as applicationActivities in UIActivityViewController's initWithActivityItems:applicationActivities:, not as activityItems as the name suggests.
It should be renamed to something like customApplicationActivities, but this would be a breaking change.
*/
@property (nonatomic, strong) NSArray *customActivityItems;

/*
Allow for custom share items in the browser by populating this optional array
It will be used as activityItems in UIActivityViewController's initWithActivityItems:applicationActivities:
*/
@property (nonatomic, strong) NSArray *customShareItems;

#pragma mark - Public Interface


Expand Down
25 changes: 22 additions & 3 deletions KINWebBrowser/KINWebBrowserViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,21 @@ - (void)updateToolbarState {
URLString = [URLString stringByReplacingOccurrencesOfString:@"http://" withString:@""];
URLString = [URLString stringByReplacingOccurrencesOfString:@"https://" withString:@""];
URLString = [URLString substringToIndex:[URLString length]-1];
self.navigationItem.title = URLString;

UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.navigationController.navigationBar.bounds.size.width, 29.0f)];
titleView.backgroundColor = [UIColor colorWithRed:228/255.0f green:228/255.0f blue:230/255.0f alpha:1.0];
titleView.layer.cornerRadius = 5.0f;

UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:17.0f];
label.text = URLString;
label.textColor = [UIColor darkGrayColor];
label.textAlignment = NSTextAlignmentCenter;
label.frame = CGRectInset(titleView.frame, 10.0f, 0.0f);
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[titleView addSubview:label];

self.navigationItem.titleView = titleView;
}
}
else {
Expand Down Expand Up @@ -481,8 +495,13 @@ - (void)actionButtonPressed:(id)sender {
URLForActivityItem = self.uiWebView.request.URL;
URLTitle = [self.uiWebView stringByEvaluatingJavaScriptFromString:@"document.title"];
}
if (URLForActivityItem) {
if (URLForActivityItem || self.customShareItems) {
dispatch_async(dispatch_get_main_queue(), ^{
NSArray *shareItems = @[URLForActivityItem];
if (self.customShareItems) {
shareItems = self.customShareItems;
}

TUSafariActivity *safariActivity = [[TUSafariActivity alloc] init];
ARChromeActivity *chromeActivity = [[ARChromeActivity alloc] init];

Expand All @@ -493,7 +512,7 @@ - (void)actionButtonPressed:(id)sender {
[activities addObjectsFromArray:self.customActivityItems];
}

UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[URLForActivityItem] applicationActivities:activities];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:activities];

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if(self.actionPopoverController) {
Expand Down