-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker] Default to gallery instead of camera when picking multiple images on pre-iOS 14 devices. #4718
Conversation
284076e
to
9d15c59
Compare
packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker/example/ios/RunnerTests/ImagePickerPluginTests.m
Outdated
Show resolved
Hide resolved
Hi @stuartmorgan, I fully agree with your comments and I have been struggling with this too. Ideally we'd separate the method channel implementation from the code that interacts directly with the
This would make testing the API surface between Dart and Native a lot easier. However this is also a large refactor. My reasoning was to solve this bug now by not introducing new parameters, ivars or logic but instead simply fixing the existing implementation (and add some tests to ensure it works) and discuss a bigger refactor with you offline. |
Sounds like a good way to go longer term, but it shouldn't actually be necessary for what I'm suggesting. Look at the local_auth iOS tests for instance, which have a single class but still do method-call-to-mock-system-API testing.
Well, there's obviously new logic here. But I'm fine with the short term fix itself being pretty minimal (the non-tests changes I asked for should be quite small), the issue is that the change you made to the tests make the code worse. They make fixing the root problem harder, because they enshrine and encourage an anti-pattern. Small incremental changes are fine but they need to take us in the right direction.
I think "ensure it works" is highly arguable. As an experiment I tried moving They ensure that part of the anti-pattern is being followed at some point, but not that it's the right point, or that it's used correctly. |
Refactored the existing unit tests to expose private interfaces in a separate test header instead of an inline interface. This was first introduced in the google_sign_in plugin (flutter#4157) and after that also applied in the camera plugin (flutter#4426) and the webview_flutter plugin (flutter#4480).
09d29ea
to
8707cd8
Compare
Refactored the existing unit tests to expose private interfaces in a separate test header instead of an inline interface. This was first introduced in the google_sign_in plugin (flutter#4157) and after that also applied in the camera plugin (flutter#4426) and the webview_flutter plugin (flutter#4480).
packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
Outdated
Show resolved
Hide resolved
@@ -146,6 +146,32 @@ - (void)testPluginPickVideoDeviceFront { | |||
UIImagePickerControllerCameraDeviceFront); | |||
} | |||
|
|||
- (void)testPickMultiImageShouldUseUIImagePickerControllerOnPreiOS14 { | |||
if (@available(iOS 14, *)) { |
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.
@jmagman Relevant to our discussions about test matrixes in this repository: we won't ever actually test this in CI currently.
packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
Outdated
Show resolved
Hide resolved
packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
Outdated
Show resolved
Hide resolved
_imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext; | ||
_imagePickerController.delegate = self; | ||
_imagePickerController.mediaTypes = @[ | ||
UIImagePickerController *imagePickerController = [self createImagePickerController]; |
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.
Shouldn't this be self.imagePickerController
?
If we need a stateful controller, I'm very concerned about our test coverage if this didn't break anything. Does it not actually need to be stateful?
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.
With some refactoring it is not necessary to keep the imagePickerController
as state. I did the refactoring necessary which involves passing the current copy of the imagePickerController
around to some other methods. Please have a look if you agree with 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.
Looks great, thanks! (Now we just need to do the same with arguments, and ideally result, but those are definitely out of scope.)
if (image == nil) { | ||
image = [info objectForKey:UIImagePickerControllerOriginalImage]; | ||
image = info[UIImagePickerControllerOriginalImage]; |
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.
Thanks for fixing this everywhere :)
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.
LGTM with nits, thanks for all the iteration and test work here!
packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
Outdated
Show resolved
Hide resolved
_imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext; | ||
_imagePickerController.delegate = self; | ||
_imagePickerController.mediaTypes = @[ | ||
UIImagePickerController *imagePickerController = [self createImagePickerController]; |
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.
Looks great, thanks! (Now we just need to do the same with arguments, and ideally result, but those are definitely out of scope.)
packages/image_picker/image_picker/ios/Classes/FLTImagePickerPlugin.m
Outdated
Show resolved
Hide resolved
…cking multiple images on pre-iOS 14 devices. (flutter/plugins#4718)
…cking multiple images on pre-iOS 14 devices. (flutter/plugins#4718)
…cking multiple images on pre-iOS 14 devices. (flutter/plugins#4718)
…cking multiple images on pre-iOS 14 devices. (flutter/plugins#4718)
Solves two problems when using the
ImagePicker.pickMultiImage
method on pre-iOS 14 devices:_picker.pickMultiImage
launches camera instead of gallery on IOS 12 flutter#96903);arguments
andresult
callback are made available to theUIImagePicker
when picking images on devices running iOS 13 and lower.Resolves flutter/flutter#96903
Replaces and closes #4706
EDIT: Converted this PR to draft as it depends on changes from PR #4722.
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].///
).