Skip to content
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

[image_picker] Add limit parameter to pickMultiImage and pickMultipleMedia to ios and Android #6201

Merged
merged 45 commits into from
Apr 16, 2024

Conversation

pdenert
Copy link
Contributor

@pdenert pdenert commented Feb 25, 2024

Adds limit parameter to MediaOptions and MultiImagePickerOptions and supports its use on iOS and Android. The limit argument defines how many images or media files can be select.

Fixes: flutter/flutter#85772

Pre-launch Checklist

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

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

Seems like a solid change once the method deprecation is changed. Thanks for putting this together, and let me know if you need any help/guidance with anything!

This isn't a full review, I'll double back around once these changes are made.

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

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

I think that this PR could be much simplified if it were: "add a new parameter to MultiImagePickerOptions, and then use it in iOS and Android". For example, the web package wouldn't need any changes, because it doesn't care about the new parameter of that object at all.

There's a lot of extra code because this is updating a bunch of deprecated methods (as @tarrinneal mentioned in his review above!), which... we might be even able to delete...

@pdenert
Copy link
Contributor Author

pdenert commented Feb 29, 2024

I've cleaned up packages which remain unchanged.
I've removed limit from deprecated methods.
I've updated iOS and Android implementations

@ditman
Copy link
Member

ditman commented Feb 29, 2024

Thanks for reverting the web package @pdenert!

I checked the web APIs again and there's nothing new to limit the number of files that the user selects (as in: disable file selection once the user selects limit files).

We could count how many they've selected and throw an exception, or discard extras if they've picked too many, but that's probably confusing, and can be implemented on the application layer too.

@pdenert
Copy link
Contributor Author

pdenert commented Feb 29, 2024

We could count how many they've selected and throw an exception, or discard extras if they've picked too many, but that's probably confusing, and can be implemented on the application layer too.

Yeah, I feel the same way. If we can't limit choice on the UI side, then it's better to do nothing.

@pdenert
Copy link
Contributor Author

pdenert commented Mar 4, 2024

@tarrinneal do you mind look at this again?

Copy link
Contributor

@vashworth vashworth left a comment

Choose a reason for hiding this comment

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

The iOS side looks good, however, the usage of pickMultiImageWithMaxSize and makeWithMaxSize within image_picker_ios/example/ios/RunnerTests/ImagePickerPluginTests.m will need to be updated to use new parameter.

Also, additional tests should be added to test the new limit parameter correctly sets the maxImageCount. I've included an example you can use below. You should also add ones where the limit is nil.

Test example
- (void)testPickMultiImageWithLimit {
  FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init];
  [plugin pickMultiImageWithMaxSize:[[FLTMaxSize alloc] init]
                            quality:nil
                       fullMetadata:NO
                              limit:@(2)
                         completion:^(NSArray<NSString *> *_Nullable result,
                                      FlutterError *_Nullable error){
                         }];
  XCTAssertEqual(plugin.callContext.maxImageCount, 2);
}

- (void)testPickMediaWithLimitAllowsMultiple {
  FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init];
  FLTMediaSelectionOptions *mediaSelectionOptions =
      [FLTMediaSelectionOptions makeWithMaxSize:[FLTMaxSize makeWithWidth:@(100) height:@(200)]
                                   imageQuality:nil
                            requestFullMetadata:NO
                                  allowMultiple:YES
                                          limit:@(2)];

  [plugin pickMediaWithMediaSelectionOptions:mediaSelectionOptions
                                  completion:^(NSArray<NSString *> *_Nullable result,
                                               FlutterError *_Nullable error){
                                  }];

  XCTAssertEqual(plugin.callContext.maxImageCount, 2);
}

- (void)testPickMediaWithLimitMultipleNotAllowed {
  FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init];
  FLTMediaSelectionOptions *mediaSelectionOptions =
      [FLTMediaSelectionOptions makeWithMaxSize:[FLTMaxSize makeWithWidth:@(100) height:@(200)]
                                   imageQuality:nil
                            requestFullMetadata:NO
                                  allowMultiple:NO
                                          limit:@(2)];

  [plugin pickMediaWithMediaSelectionOptions:mediaSelectionOptions
                                  completion:^(NSArray<NSString *> *_Nullable result,
                                               FlutterError *_Nullable error){
                                  }];

  XCTAssertEqual(plugin.callContext.maxImageCount, 1);
}

packages/image_picker/image_picker_ios/CHANGELOG.md Outdated Show resolved Hide resolved
@pdenert
Copy link
Contributor Author

pdenert commented Mar 4, 2024

@vashworth thanks for the test examples. I've also added tests for variants where the limit is nil

@pdenert pdenert requested a review from vashworth March 4, 2024 23:13
Copy link
Contributor

@vashworth vashworth left a comment

Choose a reason for hiding this comment

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

@pdenert
Copy link
Contributor Author

pdenert commented Apr 16, 2024

@tarrinneal may you look at this soon?

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

Thanks for putting in the time and effort on this pr.

(and sorry for the delays in approval)

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 16, 2024
@auto-submit auto-submit bot merged commit 43f1979 into flutter:main Apr 16, 2024
78 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 17, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Apr 17, 2024
flutter/packages@90c876d...d39830e

2024-04-16 engine-flutter-autoroll@skia.org Manual roll Flutter from 2e748e8 to 3882afb (16 revisions) (flutter/packages#6549)
2024-04-16 pdenert09@gmail.com [image_picker] Add limit parameter to pickMultiImage and pickMultipleMedia to ios and Android (flutter/packages#6201)
2024-04-16 stuartmorgan@google.com [camera] Remove iOS thread-safe result class (flutter/packages#6498)
2024-04-16 rrpadilla@gmail.com [google_maps_flutter] update ios privacy manifest (flutter/packages#6511)

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
gilnobrega pushed a commit to gilnobrega/flutter that referenced this pull request Apr 22, 2024
…r#146895)

flutter/packages@90c876d...d39830e

2024-04-16 engine-flutter-autoroll@skia.org Manual roll Flutter from 2e748e8 to 3882afb (16 revisions) (flutter/packages#6549)
2024-04-16 pdenert09@gmail.com [image_picker] Add limit parameter to pickMultiImage and pickMultipleMedia to ios and Android (flutter/packages#6201)
2024-04-16 stuartmorgan@google.com [camera] Remove iOS thread-safe result class (flutter/packages#6498)
2024-04-16 rrpadilla@gmail.com [google_maps_flutter] update ios privacy manifest (flutter/packages#6511)

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
TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this pull request May 22, 2024
Adds limit parameter to `MediaOptions` and `MultiImagePickerOptions`. The `limit` argument defines how many images or media files can be select.

Only platform interface package changes taken from: flutter#6201

Fixes: [flutter/flutter#85772](flutter/flutter#85772)
TecHaxter pushed a commit to TecHaxter/flutter_packages that referenced this pull request May 22, 2024
…Media to ios and Android (flutter#6201)

Adds limit parameter to `MediaOptions` and `MultiImagePickerOptions` and supports its use on iOS and Android. The `limit` argument defines how many images or media files can be select.

Fixes: [flutter/flutter#85772](flutter/flutter#85772)
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
Adds limit parameter to `MediaOptions` and `MultiImagePickerOptions`. The `limit` argument defines how many images or media files can be select.

Only platform interface package changes taken from: flutter#6201

Fixes: [flutter/flutter#85772](flutter/flutter#85772)
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…Media to ios and Android (flutter#6201)

Adds limit parameter to `MediaOptions` and `MultiImagePickerOptions` and supports its use on iOS and Android. The `limit` argument defines how many images or media files can be select.

Fixes: [flutter/flutter#85772](flutter/flutter#85772)
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: image_picker platform-android platform-ios
Projects
None yet
6 participants