Replaces UIAlertController with UIMenu for importing games
This commit is contained in:
parent
836297718b
commit
25afda3b60
@ -135,7 +135,21 @@ extension GamesViewController
|
||||
}
|
||||
}
|
||||
|
||||
self.importController.barButtonItem = self.importButton
|
||||
if #available(iOS 14, *)
|
||||
{
|
||||
self.importController.presentingViewController = self
|
||||
|
||||
let importActions = self.importController.makeActions().menuActions
|
||||
let importMenu = UIMenu(title: NSLocalizedString("Import From…", comment: ""), image: UIImage(systemName: "square.and.arrow.down"), children: importActions)
|
||||
self.importButton.menu = importMenu
|
||||
|
||||
self.importButton.action = nil
|
||||
self.importButton.target = nil
|
||||
}
|
||||
else
|
||||
{
|
||||
self.importController.barButtonItem = self.importButton
|
||||
}
|
||||
|
||||
self.prepareSearchController()
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ import DeltaCore
|
||||
struct iTunesImportOption: ImportOption
|
||||
{
|
||||
let title = NSLocalizedString("iTunes", comment: "")
|
||||
let image: UIImage? = nil
|
||||
let image: UIImage? = UIImage(symbolNameIfAvailable: "music.note")
|
||||
|
||||
private let presentingViewController: UIViewController
|
||||
|
||||
|
||||
@ -37,11 +37,11 @@ class ImportController: NSObject
|
||||
var delegate: ImportControllerDelegate?
|
||||
var importOptions: [ImportOption]?
|
||||
|
||||
weak var presentingViewController: UIViewController?
|
||||
|
||||
weak var barButtonItem: UIBarButtonItem?
|
||||
weak var sourceView: UIView?
|
||||
|
||||
private weak var presentingViewController: UIViewController?
|
||||
|
||||
// Store presentedViewController separately, since when we dismiss we don't know if it has already been dismissed.
|
||||
// Calling dismiss on presentingViewController in that case would dismiss presentingViewController, which is bad.
|
||||
private weak var presentedViewController: UIViewController?
|
||||
@ -64,26 +64,44 @@ class ImportController: NSObject
|
||||
super.init()
|
||||
}
|
||||
|
||||
func makeActions() -> [Action]
|
||||
{
|
||||
assert(self.presentingViewController != nil, "presentingViewController must be set before calling makeActions()")
|
||||
|
||||
var actions = (self.importOptions ?? []).map { (option) -> Action in
|
||||
let action = Action(title: option.title, style: .default, image: option.image) { _ in
|
||||
option.import { importedURLs in
|
||||
self.finish(with: importedURLs, errors: [])
|
||||
}
|
||||
}
|
||||
|
||||
return action
|
||||
}
|
||||
|
||||
let filesAction = Action(title: NSLocalizedString("Files", comment: ""), style: .default, image: UIImage(symbolNameIfAvailable: "doc")) { action in
|
||||
self.presentDocumentBrowser()
|
||||
}
|
||||
actions.append(filesAction)
|
||||
|
||||
return actions
|
||||
}
|
||||
|
||||
fileprivate func presentImportController(from presentingViewController: UIViewController, animated: Bool, completionHandler: (() -> Void)?)
|
||||
{
|
||||
self.presentingViewController = presentingViewController
|
||||
|
||||
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
alertController.addAction(UIAlertAction.cancel)
|
||||
let actions = self.makeActions()
|
||||
|
||||
if let importOptions = self.importOptions
|
||||
if actions.count > 1
|
||||
{
|
||||
for importOption in importOptions
|
||||
{
|
||||
alertController.add(importOption) { [unowned self] (urls) in
|
||||
self.finish(with: urls, errors: [])
|
||||
}
|
||||
}
|
||||
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
alertController.addAction(UIAlertAction.cancel)
|
||||
|
||||
let filesAction = UIAlertAction(title: NSLocalizedString("Files", comment: ""), style: .default) { (action) in
|
||||
self.presentDocumentBrowser()
|
||||
let alertActions = actions.map { UIAlertAction($0) }
|
||||
for action in alertActions
|
||||
{
|
||||
alertController.addAction(action)
|
||||
}
|
||||
alertController.addAction(filesAction)
|
||||
|
||||
if let sourceView = self.sourceView
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user