This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker] Support reading WebP images for iOS #4448
Merged
fluttergithubbot
merged 18 commits into
flutter:main
from
TrGiLong:support-webp-for-ios
Feb 25, 2022
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a35b4bb
support WebP for iOS
TrGiLong 6ceddd6
update CHANGELOG
TrGiLong c7e886d
update Pubspec
TrGiLong c15c261
use const insteed of self-defined string
TrGiLong 88b25f7
add test
TrGiLong 53f5319
fix style and add more tests
TrGiLong aa57cf4
fix style
TrGiLong 96e358d
improve method name and add documentation
TrGiLong 6dcb8a9
fix changelog
TrGiLong c28ccf7
revert FLTImagePickerPlugin
TrGiLong 864e5db
revert
TrGiLong 5839c19
improve method name and add documentation
TrGiLong 0602ef4
Merge branch 'master' into support-webp-for-ios
TrGiLong 479d6b6
fix
TrGiLong 16ae49b
fix code style
TrGiLong b283bf7
fix null checking
TrGiLong 3e9d372
fix test
TrGiLong bd1720c
Merge branch 'main' into support-webp-for-ios
stuartmorgan-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...s/image_picker/image_picker/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import <OCMock/OCMock.h> | ||
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h> | ||
|
||
@import image_picker; | ||
@import image_picker.Test; | ||
@import XCTest; | ||
|
||
@interface PickerSaveImageToPathOperationTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation PickerSaveImageToPathOperationTests | ||
|
||
- (void)testSaveWebPImage API_AVAILABLE(ios(14)) { | ||
NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"webpImage" | ||
withExtension:@"webp"]; | ||
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL]; | ||
PHPickerResult *result = [self createPickerResultWithProvider:itemProvider | ||
withIdentifier:UTTypeWebP.identifier]; | ||
|
||
[self verifySavingImageWithPickerResult:result]; | ||
} | ||
|
||
- (void)testSavePNGImage API_AVAILABLE(ios(14)) { | ||
NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"pngImage" | ||
TrGiLong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
withExtension:@"png"]; | ||
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL]; | ||
PHPickerResult *result = [self createPickerResultWithProvider:itemProvider | ||
withIdentifier:UTTypeWebP.identifier]; | ||
|
||
[self verifySavingImageWithPickerResult:result]; | ||
} | ||
|
||
- (void)testSaveJPGImage API_AVAILABLE(ios(14)) { | ||
NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"jpgImage" | ||
withExtension:@"jpg"]; | ||
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL]; | ||
PHPickerResult *result = [self createPickerResultWithProvider:itemProvider | ||
withIdentifier:UTTypeWebP.identifier]; | ||
|
||
[self verifySavingImageWithPickerResult:result]; | ||
} | ||
|
||
- (void)testSaveGIFImage API_AVAILABLE(ios(14)) { | ||
NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"gifImage" | ||
withExtension:@"gif"]; | ||
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL]; | ||
PHPickerResult *result = [self createPickerResultWithProvider:itemProvider | ||
withIdentifier:UTTypeWebP.identifier]; | ||
|
||
[self verifySavingImageWithPickerResult:result]; | ||
} | ||
|
||
/** | ||
* Creates a mock picker result using NSItemProvider. | ||
* | ||
* @param itemProvider an item provider that will be used as picker result | ||
* @param identifier local identifier of the asset | ||
*/ | ||
- (PHPickerResult *)createPickerResultWithProvider:(NSItemProvider *)itemProvider | ||
withIdentifier:(NSString *)identifier API_AVAILABLE(ios(14)) { | ||
PHPickerResult *result = OCMClassMock([PHPickerResult class]); | ||
|
||
OCMStub([result itemProvider]).andReturn(itemProvider); | ||
OCMStub([result assetIdentifier]).andReturn(identifier); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Validates a saving process of FLTPHPickerSaveImageToPathOperation. | ||
* | ||
* FLTPHPickerSaveImageToPathOperation is responsible for saving a picked image to the disk for | ||
* later use. It is expected that the saving is always successful. | ||
* | ||
* @param result the picker result | ||
*/ | ||
- (void)verifySavingImageWithPickerResult:(PHPickerResult *)result API_AVAILABLE(ios(14)) { | ||
XCTestExpectation *pathExpectation = [self expectationWithDescription:@"Path was created"]; | ||
|
||
FLTPHPickerSaveImageToPathOperation *operation = [[FLTPHPickerSaveImageToPathOperation alloc] | ||
initWithResult:result | ||
maxHeight:@100 | ||
maxWidth:@100 | ||
desiredImageQuality:@100 | ||
savedPathBlock:^(NSString *savedPath) { | ||
if ([[NSFileManager defaultManager] fileExistsAtPath:savedPath]) { | ||
[pathExpectation fulfill]; | ||
} | ||
}]; | ||
|
||
[operation start]; | ||
[self waitForExpectations:@[ pathExpectation ] timeout:30]; | ||
} | ||
|
||
@end |
Binary file added
BIN
+2.56 KB
packages/image_picker/image_picker/example/ios/TestImages/webpImage.webp
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.