Skip to content

Conversation

@stuartmorgan-g
Copy link
Collaborator

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

Footnotes

  1. 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

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

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +56 to +62
- (instancetype)initWithViewProvider:(NSObject<FIPViewProvider> *)viewProvider {
self = [super init];
if (self) {
_viewProvider = viewProvider;
}
return self;
}

Choose a reason for hiding this comment

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

critical

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:

  1. Make the default init unavailable by adding - (instancetype)init NS_UNAVAILABLE; to the FLTImagePickerPlugin's primary interface in FLTImagePickerPlugin.h.
  2. Update all call sites of [[FLTImagePickerPlugin alloc] init] in the tests to use the new initWithViewProvider:, providing a StubViewProvider as is done in testPickVideoSetsCurrentRepresentationMode. This will ensure all tests correctly provide a view controller for presentation.

Copy link
Collaborator Author

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 nil viewProvider are 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[image_picker_ios][UIScene] Migrate to scene APIs

1 participant