-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[file_selector] Migrate to UIScene #10429
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,14 +45,19 @@ public class FileSelectorPlugin: NSObject, FlutterPlugin, FileSelectorApi { | |
| var pendingCompletions: Set<PickerCompletionBridge> = [] | ||
| /// Overridden document picker, for testing. | ||
| var documentPickerViewControllerOverride: UIDocumentPickerViewController? | ||
| /// Overridden view presenter, for testing. | ||
| var viewPresenterOverride: ViewPresenter? | ||
| /// The view controller provider, for showing the document picker. | ||
| let viewPresenterProvider: ViewPresenterProvider | ||
|
|
||
| public static func register(with registrar: FlutterPluginRegistrar) { | ||
| let instance = FileSelectorPlugin() | ||
| let instance = FileSelectorPlugin( | ||
| viewPresenterProvider: DefaultViewPresenterProvider(registrar: registrar)) | ||
| FileSelectorApiSetup.setUp(binaryMessenger: registrar.messenger(), api: instance) | ||
| } | ||
|
|
||
| init(viewPresenterProvider: ViewPresenterProvider) { | ||
| self.viewPresenterProvider = viewPresenterProvider | ||
| } | ||
|
|
||
| func openFile(config: FileSelectorConfig, completion: @escaping (Result<[String], Error>) -> Void) | ||
| { | ||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let completionBridge = PickerCompletionBridge(completion: completion, owner: self) | ||
|
|
@@ -64,14 +69,12 @@ public class FileSelectorPlugin: NSObject, FlutterPlugin, FileSelectorApi { | |
| documentPicker.allowsMultipleSelection = config.allowMultiSelection | ||
| documentPicker.delegate = completionBridge | ||
|
|
||
| let presenter = | ||
| self.viewPresenterOverride ?? UIApplication.shared.delegate?.window??.rootViewController | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could keep this override structure instead of adding |
||
| if let presenter = presenter { | ||
| if let presenter = viewPresenterProvider.viewPresenter { | ||
| pendingCompletions.insert(completionBridge) | ||
| presenter.present(documentPicker, animated: true, completion: nil) | ||
| } else { | ||
| completion( | ||
| .failure(PigeonError(code: "error", message: "Missing root view controller.", details: nil)) | ||
| .failure(PigeonError(code: "error", message: "No view controller available.", details: nil)) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import Flutter | ||
| import UIKit | ||
|
|
||
| /// Protocol for UIViewController methods relating to presenting a controller. | ||
|
|
@@ -18,3 +19,26 @@ protocol ViewPresenter { | |
|
|
||
| /// ViewPresenter is intentionally a direct passthroguh to UIViewController. | ||
| extension UIViewController: ViewPresenter {} | ||
|
|
||
| /// Protocol for FlutterPluginRegistrar method for accessing the view controller. | ||
| /// | ||
| /// This is necessary because Swift doesn't allow for only partially implementing a protocol, so | ||
| /// a stub implementation of FlutterPluginRegistrar for tests would break any time something was | ||
| /// added to that protocol. | ||
| protocol ViewPresenterProvider { | ||
| /// Returns the view controller associated with the Flutter content. | ||
| var viewPresenter: ViewPresenter? { get } | ||
| } | ||
|
|
||
| /// Non-test implementation of ViewControllerProvider that forwards to the plugin registrar. | ||
stuartmorgan-g marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| class DefaultViewPresenterProvider: ViewPresenterProvider { | ||
stuartmorgan-g marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private let registrar: FlutterPluginRegistrar | ||
|
|
||
| init(registrar: FlutterPluginRegistrar) { | ||
| self.registrar = registrar | ||
| } | ||
|
|
||
| var viewPresenter: ViewPresenter? { | ||
| registrar.viewController | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.