-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[file_selector] Convert iOS to Swift and SPM #6755
[file_selector] Convert iOS to Swift and SPM #6755
Conversation
This is the easiest way to remove the use of modulemaps, right? 😁 Let me know if you want me to actually break this up into separate PRs. The overall change isn't actually that big so this seemed potentially easier, but I could easily split it along commit lines. |
eb6df7f
to
cb91c01
Compare
cb91c01
to
6ce49a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hellohuanlin could you review just the files FileSelectorPlugin.swift
ViewPresenter.swift
for idiomatic Swift?
LGTM
|
||
@testable import file_selector_ios | ||
|
||
class TestViewPresenter: ViewPresenter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: final
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
sendResult( | ||
urls.map({ document in | ||
document.path | ||
})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: sendResult(urls.map { $0.path })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I forgot Swift has shorthand for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can also use key path urls.map(\.path)
which is even shorter. sometimes i forget about it (no need to change tho)
?? UIDocumentPickerViewController( | ||
documentTypes: config.utis.map({ uti in | ||
// See comment in messages.dart for why this is safe. | ||
uti! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can cast directly config.utis as! [TypeOfThis]
without the loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I guess I've internalized the Dart model of having to cast elements rather than the collections themselves.
documentTypes: config.utis.map({ uti in | ||
// See comment in messages.dart for why this is safe. | ||
uti! | ||
}), in: UIDocumentPickerMode.import) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: in: .import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Someday I'll internalize this one.
documentPicker.delegate = completionBridge | ||
|
||
let presenter = | ||
self.viewPresenterOverride ?? UIApplication.shared.delegate?.window??.rootViewController |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is viewPresenterOverride
created for testing purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, both to avoid actually having modal UI pop up (which causes issues when running multiple tests since we can't dismiss it) and to assert that it's called with expected values.
flutter/packages@6525441...1008d9e 2024-05-23 [email protected] Roll Flutter from 73bf206 to 8d955cd (24 revisions) (flutter/packages#6786) 2024-05-23 [email protected] Roll Flutter (stable) from 5dcb86f to a14f74f (3 revisions) (flutter/packages#6784) 2024-05-23 [email protected] [file_selector] Convert iOS to Swift and SPM (flutter/packages#6755) 2024-05-23 49699333+dependabot[bot]@users.noreply.github.com [webview]: Bump androidx.webkit:webkit from 1.7.0 to 1.10.0 in /packages/webview_flutter/webview_flutter_android/android (flutter/packages#5996) 2024-05-23 [email protected] Roll Flutter from d02292d to 73bf206 (31 revisions) (flutter/packages#6780) 2024-05-23 [email protected] [rfw] Adds support for `DecorationImage.filterQuality`. (flutter/packages#6781) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…r#148980) flutter/packages@6525441...1008d9e 2024-05-23 [email protected] Roll Flutter from 73bf206 to 8d955cd (24 revisions) (flutter/packages#6786) 2024-05-23 [email protected] Roll Flutter (stable) from 5dcb86f to a14f74f (3 revisions) (flutter/packages#6784) 2024-05-23 [email protected] [file_selector] Convert iOS to Swift and SPM (flutter/packages#6755) 2024-05-23 49699333+dependabot[bot]@users.noreply.github.com [webview]: Bump androidx.webkit:webkit from 1.7.0 to 1.10.0 in /packages/webview_flutter/webview_flutter_android/android (flutter/packages#5996) 2024-05-23 [email protected] Roll Flutter from d02292d to 73bf206 (31 revisions) (flutter/packages#6780) 2024-05-23 [email protected] [rfw] Adds support for `DecorationImage.filterQuality`. (flutter/packages#6781) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Converts the plugin and its tests to Swift, and re-adds the SPM support that was reverted due to modulemap issues. In order to avoid the ugliness and loss of type saftey of using associated objects in the Swift version, this replaces that with a bridge object that serves as a delegate instead of the plugin, and manages its own lifetime in coordination with the plugin. While this is one PR, the conversion was done in individual steps, each of which is a commit: - Rewrite just the tests in Swift, with no implementation changes, ensuring that everything still passed. - Rewrite the implementation in Swift, changing the tests only as necessary for the structural changes to the implementation due to the removal of associated objects - Re-add SPM The changes in the generated Dart files are just due to updating to the latest version of Pigeon (to avoid writing the Swift implementation against an older version of the Swift API, and then having to update again later for breaking changes). Part of flutter/flutter#119015 Fixes flutter/flutter#146903
Converts the plugin and its tests to Swift, and re-adds the SPM support that was reverted due to modulemap issues.
In order to avoid the ugliness and loss of type saftey of using associated objects in the Swift version, this replaces that with a bridge object that serves as a delegate instead of the plugin, and manages its own lifetime in coordination with the plugin.
While this is one PR, the conversion was done in individual steps, each of which is a commit:
The changes in the generated Dart files are just due to updating to the latest version of Pigeon (to avoid writing the Swift implementation against an older version of the Swift API, and then having to update again later for breaking changes).
Part of flutter/flutter#119015
Fixes flutter/flutter#146903
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).