-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[image_picker] Update for UIScene compatibility #10677
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?
Conversation
Replaces the code that used the key window's root view controller with a call to the new registrar viewController method to get the actual Flutter content's view controller. Introduces the same protocol abstraction now used in a number of our plugins, so that a stub can be injected without having to mock (which would be a barrier to Swift migration) or fake (which is fragile since it would have to be complete, and methods can be added over time) the entire Flutter plugin registrar. Fixes flutter/flutter#174418
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.
Code Review
This pull request refactors the image_picker_ios plugin to improve UIScene compatibility by abstracting view controller access behind a FIPViewProvider protocol. This is a solid approach that also improves testability. The changes are mostly correct, but I've found a critical issue where many tests were not updated to use the new initializer, potentially masking issues and reducing test effectiveness. I've also included a couple of minor suggestions for improving code style and robustness.
| - (instancetype)initWithViewProvider:(NSObject<FIPViewProvider> *)viewProvider { | ||
| self = [super init]; | ||
| if (self) { | ||
| _viewProvider = viewProvider; | ||
| } | ||
| return self; | ||
| } |
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.
The introduction of this new initializer is a great step for testability. However, the default init is still available and used in many tests in ImagePickerPluginTests.m (e.g., testPluginPickImageDeviceBack, testPluginPickVideoDeviceFront, etc.). When [[FLTImagePickerPlugin alloc] init] is called, the viewProvider property remains nil. Since it's declared nonnull, this is incorrect and can lead to unexpected behavior or crashes. Currently, it seems to result in view controllers not being presented during tests because messages to the nil viewProvider are silently ignored. This makes those tests less effective.
To fix this, you should:
- Make the default
initunavailable by adding- (instancetype)init NS_UNAVAILABLE;to theFLTImagePickerPlugin's primary interface inFLTImagePickerPlugin.h. - Update all call sites of
[[FLTImagePickerPlugin alloc] init]in the tests to use the newinitWithViewProvider:, providing aStubViewProvideras is done intestPickVideoSetsCurrentRepresentationMode. This will ensure all tests correctly provide a view controller for presentation.
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.
Currently, it seems to result in view controllers not being presented during tests because messages to the
nilviewProviderare silently ignored. This makes those tests less effective.
This is what the tests will do anyway since the view controller will be null, which is why I didn't bother changing all the tests originally, but the point about violating the non-nullability annotation is fair. I added a bit of boilerplate to all of the tests so that won't need to be done as part of a Swift migration.
Replaces the code that used the key window's root view controller with a call to the new registrar viewController method to get the actual Flutter content's view controller.
Introduces the same protocol abstraction now used in a number of our plugins, so that a stub can be injected without having to mock (which would be a barrier to Swift migration) or fake (which is fragile since it would have to be complete, and methods can be added over time) the entire Flutter plugin registrar.
Fixes flutter/flutter#174418
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3