forked from weiran/Hackers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added view comments action item to peek
- Loading branch information
Showing
4 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// SFSafariViewController+PreviewActionItems.swift | ||
// Hackers | ||
// | ||
// Created by Weiran Zhang on 30/04/2016. | ||
// Copyright © 2016 Glass Umbrella. All rights reserved. | ||
// | ||
|
||
import SafariServices | ||
import ObjectiveC | ||
|
||
private struct AssociatedKeys { | ||
static var PreviewActionItemsDelegateName = "previewActionItemsDelegate" | ||
static var InitialURL = "initialURL" | ||
} | ||
|
||
extension SFSafariViewController { | ||
private(set) public var initialURL: NSURL? { | ||
set { | ||
objc_setAssociatedObject(self, &AssociatedKeys.InitialURL, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) | ||
} | ||
get { | ||
return objc_getAssociatedObject(self, &AssociatedKeys.InitialURL) as? NSURL | ||
} | ||
} | ||
|
||
public convenience init(initialURL: NSURL, entersReaderIfAvailable: Bool) { | ||
self.init(URL: initialURL, entersReaderIfAvailable: entersReaderIfAvailable) | ||
self.initialURL = initialURL | ||
} | ||
} | ||
|
||
|
||
// Preview action items | ||
extension SFSafariViewController { | ||
weak var previewActionItemsDelegate: SFSafariViewControllerPreviewActionItemsDelegate? { | ||
set { | ||
objc_setAssociatedObject(self, &AssociatedKeys.PreviewActionItemsDelegateName, newValue, .OBJC_ASSOCIATION_ASSIGN) | ||
} | ||
get { | ||
return objc_getAssociatedObject(self, &AssociatedKeys.PreviewActionItemsDelegateName) as? SFSafariViewControllerPreviewActionItemsDelegate | ||
} | ||
} | ||
|
||
public override func previewActionItems() -> [UIPreviewActionItem] { | ||
return previewActionItemsDelegate?.safariViewControllerPreviewActionItems(self) ?? [] | ||
} | ||
} | ||
|
||
public protocol SFSafariViewControllerPreviewActionItemsDelegate: class { | ||
func safariViewControllerPreviewActionItems(controller: SFSafariViewController) -> [UIPreviewActionItem] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters