Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[image_picker] Support reading WebP images for iOS #4448

Merged
merged 18 commits into from
Feb 25, 2022

Conversation

TrGiLong
Copy link
Contributor

@TrGiLong TrGiLong commented Oct 23, 2021

Hi,

This PR adds separate handling for WebP images. The reason is that the loadObjectOfClass:completionHandler: method of NSItemProvider class doesn't support direct reading of WebP images and returns Could not coerce an item to class UIImage error.

Before adding this handling, the platform code doesn't emit any WebP images to the flutter app. After adding this handling, the platform emits WebP images.

Fixes #88094

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@TrGiLong TrGiLong requested a review from cyanglaz as a code owner October 23, 2021 22:35
@google-cla google-cla bot added the cla: yes label Oct 23, 2021
@TrGiLong TrGiLong changed the title [image_picker] Support adding WebP images for iOS [image_picker] Support reading WebP images for iOS Oct 24, 2021
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

The meat of the PR looks good.
Test are required for this PR to move forward

@TrGiLong
Copy link
Contributor Author

@cyanglaz
Thank you for your feedback!

I think a const already exist: https://developer.apple.com/documentation/uniformtypeidentifiers/uttypewebp?language=objc

I have replaced the WebP identifier with apple's const value.

I'm not sure how I can write a good test here. My idea was to pick an image from the library (PHPickerResult) and give it to FLTPHPickerSaveImageToPathOperation, but then we should provide a WebP photo to iOS Photos App because there aren't any WebP photos there. How do you think?

@cyanglaz
Copy link
Contributor

@TrGiLong I'm not sure if there's a way to programmatically add photos to camera roll in XCUITests.

At minimum, we can probably unit test this with a mock image picker result?

@TrGiLong
Copy link
Contributor Author

TrGiLong commented Oct 25, 2021

@cyanglaz

I have added the test for the FLTPHPickerSaveImageToPathOperation class. The test case for WebP image works but if I try to use JPEG or PNG images, the test will be failed. I can not say the reason for that since I didn't change any code for handling those images. Maybe the instance of NSItemProvider, that I have loaded from the bundle, it's not identical with instance, that PHPickerViewControllerDelegate returns.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

cc @stuartmorgan For 2nd reviewer

@TrGiLong
Copy link
Contributor Author

@cyanglaz
Thank you for your feedback. I will be busy for the next 2 days. I will send a fix as soon as possible.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

A few more small notes. Also, this needs the autoformatter run on it.

@TrGiLong
Copy link
Contributor Author

TrGiLong commented Nov 9, 2021

Hi @stuartmorgan, @cyanglaz

The PR is ready to be reviewed. Can you please check it? 😅

@TrGiLong
Copy link
Contributor Author

Hi @cyanglaz,

Are you still working on this PR? 😅
Should anything else be done by me?

@cyanglaz
Copy link
Contributor

@TrGiLong I apologize for the delay. I will make sure to squeeze in some time this week to take a look at it. Thank you for being patient.

@wenboLee
Copy link

what's new on the PR? 😄

@TrGiLong
Copy link
Contributor Author

TrGiLong commented Dec 6, 2021

Hi @cyanglaz,

I have tried to improve error handling for image picking but it makes this PR enormous. I think we have to do it in separate PR. There reasons are:

  1. It requires to change the way, how we send the data back to flutter. Currently we receive a list of path of successful picking. Adding an error information to the list requires to change all data handling in Flutter side.
  2. It isn't clear how to send back error to invoker. Currently we use XFile and deprecated PickedFile classes. Adding the error field solves the problem, but I don't think it's a good idea from design perspective. I assume that error in File means a reading or writing problem. The picking error shouldn't been there. I still prefer to show a list of picking error in callback to minimise an affect to other projects.
  3. We also should apply those changes to Android. I'm not an expert there.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

You have formatting issues that need to be fixed.

You also need to update your unit tests for recent changes in the test structure of this package, as they are currently failing in CI.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM!

@stuartmorgan-g stuartmorgan-g added last mile waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. labels Feb 23, 2022
@fluttergithubbot
Copy link

This pull request is not suitable for automatic merging in its current state.

  • This pull request has changes requested by @stuartmorgan. Please resolve those before re-applying the label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 23, 2022
@stuartmorgan-g stuartmorgan-g added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 23, 2022
@fluttergithubbot
Copy link

This pull request is not suitable for automatic merging in its current state.

  • This pull request has changes requested by @stuartmorgan. Please resolve those before re-applying the label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 23, 2022
@stuartmorgan-g
Copy link
Contributor

Filed flutter/flutter#99033 to investigate why the bot won't land this. (Other team members: please don't land it manually for now.)

@godofredoc godofredoc added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 25, 2022
@fluttergithubbot
Copy link

This pull request is not suitable for automatic merging in its current state.

  • This pull request has changes requested by @stuartmorgan. Please resolve those before re-applying the label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 25, 2022
@godofredoc godofredoc added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 25, 2022
@fluttergithubbot
Copy link

This pull request is not suitable for automatic merging in its current state.

  • This pull request has changes requested by @stuartmorgan. Please resolve those before re-applying the label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 25, 2022
@godofredoc godofredoc added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 25, 2022
@fluttergithubbot
Copy link

This pull request is not suitable for automatic merging in its current state.

  • This pull request has changes requested by @stuartmorgan. Please resolve those before re-applying the label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 25, 2022
@godofredoc godofredoc added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 25, 2022
@fluttergithubbot fluttergithubbot merged commit f96d633 into flutter:main Feb 25, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes p: image_picker platform-ios waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[image_picker] Unable to pick a WebP image on iOS
6 participants