Skip to content

[file_selector] Convert iOS to Swift and SPM #6755

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

Merged
merged 6 commits into from
May 23, 2024

Conversation

stuartmorgan-g
Copy link
Contributor

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

Pre-launch Checklist

@stuartmorgan-g
Copy link
Contributor Author

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.

@stuartmorgan-g stuartmorgan-g force-pushed the file-selector-ios-swift branch from cb91c01 to 6ce49a3 Compare May 17, 2024 17:10
@stuartmorgan-g stuartmorgan-g removed the request for review from bparrishMines May 17, 2024 17:20
Copy link
Member

@jmagman jmagman left a 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

@jmagman jmagman requested a review from hellohuanlin May 22, 2024 19:49

@testable import file_selector_ios

class TestViewPresenter: ViewPresenter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: final

Copy link
Contributor Author

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
}))
Copy link
Contributor

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 })

Copy link
Contributor Author

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.

Copy link
Contributor

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!
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in: .import

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label May 23, 2024
@auto-submit auto-submit bot merged commit df16d4e into flutter:main May 23, 2024
74 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 23, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 23, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 23, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 23, 2024
flutter/packages@6525441...1008d9e

2024-05-23 engine-flutter-autoroll@skia.org Roll Flutter from 73bf206 to 8d955cd (24 revisions) (flutter/packages#6786)
2024-05-23 engine-flutter-autoroll@skia.org Roll Flutter (stable) from 5dcb86f to a14f74f (3 revisions) (flutter/packages#6784)
2024-05-23 stuartmorgan@google.com [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 engine-flutter-autoroll@skia.org Roll Flutter from d02292d to 73bf206 (31 revisions) (flutter/packages#6780)
2024-05-23 goderbauer@google.com [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 flutter-ecosystem@google.com,rmistry@google.com 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
victorsanni pushed a commit to victorsanni/flutter that referenced this pull request May 31, 2024
flutter/packages@6525441...1008d9e

2024-05-23 engine-flutter-autoroll@skia.org Roll Flutter from 73bf206 to 8d955cd (24 revisions) (flutter/packages#6786)
2024-05-23 engine-flutter-autoroll@skia.org Roll Flutter (stable) from 5dcb86f to a14f74f (3 revisions) (flutter/packages#6784)
2024-05-23 stuartmorgan@google.com [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 engine-flutter-autoroll@skia.org Roll Flutter from d02292d to 73bf206 (31 revisions) (flutter/packages#6780)
2024-05-23 goderbauer@google.com [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 flutter-ecosystem@google.com,rmistry@google.com 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: file_selector platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[file_selector] Add Swift Package Manager compatibility to file_selector_ios and file_selector_macos
3 participants