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

[fix/open-in-on-ipad] Share sheet not visible on iPad #570

Merged
merged 3 commits into from
Dec 4, 2019
Merged
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
4 changes: 3 additions & 1 deletion ownCloud/Client/Actions/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ class ActionContext: OCExtensionContext {
weak var core: OCCore?
weak var query: OCQuery?
var items: [OCItem]
weak var sender: AnyObject?

// MARK: - Init & Deinit.
init(viewController: UIViewController, core: OCCore, query: OCQuery? = nil, items: [OCItem], location: OCExtensionLocation, requirements: [String : Any]? = nil, preferences: [String : Any]? = nil) {
init(viewController: UIViewController, core: OCCore, query: OCQuery? = nil, items: [OCItem], location: OCExtensionLocation, sender: AnyObject? = nil, requirements: [String : Any]? = nil, preferences: [String : Any]? = nil) {
self.items = items

super.init()

self.viewController = viewController
self.sender = sender
self.core = core
self.location = location

Expand Down
33 changes: 30 additions & 3 deletions ownCloud/Client/Actions/Actions+Extensions/OpenInAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class OpenInAction: Action {
hostViewController?.present(alertController, animated: true)
} else {
guard let files = files, files.count > 0, let viewController = hostViewController else { return }

// UIDocumentInteractionController can only be used with a single file
if files.count == 1 {
if let fileURL = files.first?.url {
Expand All @@ -68,7 +67,24 @@ class OpenInAction: Action {
// Present UIDocumentInteractionController
self.interactionController = UIDocumentInteractionController(url: fileURL)
self.interactionController?.delegate = self
self.interactionController?.presentOptionsMenu(from: .zero, in: viewController.view, animated: true)

if let sender = self.context.sender as? UITabBarController {
var sourceRect = sender.view.frame
sourceRect.origin.y = viewController.view.frame.size.height
sourceRect.size.width = 0.0
sourceRect.size.height = 0.0

self.interactionController?.presentOptionsMenu(from: sourceRect, in: sender.view, animated: true)
} else if let barButtonItem = self.context.sender as? UIBarButtonItem {
self.interactionController?.presentOptionsMenu(from: barButtonItem, animated: true)
} else if let cell = self.context.sender as? UITableViewCell, let clientQueryViewController = viewController as? ClientQueryViewController {
if let indexPath = clientQueryViewController.tableView.indexPath(for: cell) {
let cellRect = clientQueryViewController.tableView.rectForRow(at: indexPath)
self.interactionController?.presentOptionsMenu(from: cellRect, in: clientQueryViewController.tableView, animated: true)
}
} else {
self.interactionController?.presentOptionsMenu(from: viewController.view.frame, in: viewController.view, animated: true)
}
}
} else {
// Handle multiple files with a fallback solution
Expand All @@ -78,7 +94,18 @@ class OpenInAction: Action {
let activityController = UIActivityViewController(activityItems: urls, applicationActivities: nil)

if UIDevice.current.isIpad() {
activityController.popoverPresentationController?.sourceView = viewController.view
if let sender = self.context.sender as? UITabBarController {
var sourceRect = sender.view.frame
sourceRect.origin.y = viewController.view.frame.size.height
sourceRect.size.width = 0.0
sourceRect.size.height = 0.0

activityController.popoverPresentationController?.sourceView = sender.view
activityController.popoverPresentationController?.sourceRect = sourceRect
} else {
activityController.popoverPresentationController?.sourceView = viewController.view
activityController.popoverPresentationController?.sourceRect = viewController.view.frame
}
}

viewController.present(activityController, animated: true, completion: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class ClientDirectoryPickerViewController: ClientQueryViewController {
// Actions for Create Folder
if let core = self.core, let rootItem = query.rootItem {
let actionsLocation = OCExtensionLocation(ofType: .action, identifier: .folderAction)
let actionContext = ActionContext(viewController: self, core: core, items: [rootItem], location: actionsLocation)
let actionContext = ActionContext(viewController: self, core: core, items: [rootItem], location: actionsLocation, sender: sender)

let actions = Action.sortedApplicableActions(for: actionContext).filter { (action) -> Bool in
if action.actionExtension.identifier == OCExtensionIdentifier("com.owncloud.action.createFolder") {
Expand Down
9 changes: 5 additions & 4 deletions ownCloud/Client/ClientQueryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ class ClientQueryViewController: QueryFileListTableViewController, UIDropInterac
}

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let core = self.core, let item : OCItem = itemAt(indexPath: indexPath) else {
guard let core = self.core, let item : OCItem = itemAt(indexPath: indexPath), let cell = tableView.cellForRow(at: indexPath) else {
return nil
}

let actionsLocation = OCExtensionLocation(ofType: .action, identifier: .tableRow)
let actionContext = ActionContext(viewController: self, core: core, items: [item], location: actionsLocation)
let actionContext = ActionContext(viewController: self, core: core, items: [item], location: actionsLocation, sender: cell)
let actions = Action.sortedApplicableActions(for: actionContext)
actions.forEach({
$0.progressHandler = makeActionProgressHandler()
Expand Down Expand Up @@ -443,6 +443,7 @@ class ClientQueryViewController: QueryFileListTableViewController, UIDropInterac
// Find associated action
if let action = self.actions?.first(where: {type(of:$0).identifier == sender.actionIdentifier}) {
// Configure progress handler
action.context.sender = self.tabBarController
action.progressHandler = makeActionProgressHandler()

action.completionHandler = { [weak self] (_, _) in
Expand Down Expand Up @@ -513,7 +514,7 @@ class ClientQueryViewController: QueryFileListTableViewController, UIDropInterac
// Actions for folderAction
if let core = self.core, let rootItem = query.rootItem {
let actionsLocation = OCExtensionLocation(ofType: .action, identifier: .folderAction)
let actionContext = ActionContext(viewController: self, core: core, items: [rootItem], location: actionsLocation)
let actionContext = ActionContext(viewController: self, core: core, items: [rootItem], location: actionsLocation, sender: sender)

let actions = Action.sortedApplicableActions(for: actionContext)

Expand Down Expand Up @@ -542,7 +543,7 @@ class ClientQueryViewController: QueryFileListTableViewController, UIDropInterac
}

let actionsLocation = OCExtensionLocation(ofType: .action, identifier: .moreFolder)
let actionContext = ActionContext(viewController: self, core: core, query: query, items: [rootItem], location: actionsLocation)
let actionContext = ActionContext(viewController: self, core: core, query: query, items: [rootItem], location: actionsLocation, sender: sender)

if let moreViewController = Action.cardViewController(for: rootItem, with: actionContext, progressHandler: makeActionProgressHandler()) {
self.present(asCard: moreViewController, animated: true)
Expand Down
4 changes: 2 additions & 2 deletions ownCloud/Client/Viewer/DisplayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,13 @@ class DisplayViewController: UIViewController, OCQueryDelegate {
self.showPreviewButton?.isHidden = false
}

@objc func optionsBarButtonPressed() {
@objc func optionsBarButtonPressed(_ sender: UIBarButtonItem) {
guard let core = core, let item = item else {
return
}

let actionsLocation = OCExtensionLocation(ofType: .action, identifier: .moreItem)
let actionContext = ActionContext(viewController: self, core: core, items: [item], location: actionsLocation)
let actionContext = ActionContext(viewController: self, core: core, items: [item], location: actionsLocation, sender: sender)

if let moreViewController = Action.cardViewController(for: item, with: actionContext, completionHandler: nil) {
self.present(asCard: moreViewController, animated: true)
Expand Down
2 changes: 1 addition & 1 deletion ownCloud/FileLists/FileListTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class FileListTableViewController: UITableViewController, ClientItemCellDelegate
}

let actionsLocation = OCExtensionLocation(ofType: .action, identifier: .moreItem)
let actionContext = ActionContext(viewController: self, core: core, query: query, items: [item], location: actionsLocation)
let actionContext = ActionContext(viewController: self, core: core, query: query, items: [item], location: actionsLocation, sender: cell)

if let moreViewController = Action.cardViewController(for: item, with: actionContext, progressHandler: makeActionProgressHandler()) {
self.present(asCard: moreViewController, animated: true)
Expand Down