diff --git a/packages/ios_platform_images/example/assets/2.0x/multisize.png b/packages/ios_platform_images/example/assets/2.0x/multisize.png new file mode 100644 index 0000000000000..508b77122d87d Binary files /dev/null and b/packages/ios_platform_images/example/assets/2.0x/multisize.png differ diff --git a/packages/ios_platform_images/example/assets/monosize.png b/packages/ios_platform_images/example/assets/monosize.png new file mode 100644 index 0000000000000..28e7367f14516 Binary files /dev/null and b/packages/ios_platform_images/example/assets/monosize.png differ diff --git a/packages/ios_platform_images/example/assets/multisize.png b/packages/ios_platform_images/example/assets/multisize.png new file mode 100644 index 0000000000000..28e7367f14516 Binary files /dev/null and b/packages/ios_platform_images/example/assets/multisize.png differ diff --git a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj index d6b4ef94bcef3..acea2f5253f1a 100644 --- a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 0DE21BF72447752100097E3A /* textfile in Resources */ = {isa = PBXBuildFile; fileRef = 0DE21BF62447752100097E3A /* textfile */; }; 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 33B0E32C2AB348FF0006F0C1 /* UIImage+ios_platform_imagesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33B0E32B2AB348FF0006F0C1 /* UIImage+ios_platform_imagesTests.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; @@ -48,6 +49,7 @@ 0EF1CD9A3A3064B5289EF22E /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 33B0E32B2AB348FF0006F0C1 /* UIImage+ios_platform_imagesTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ios_platform_imagesTests.m"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 4B56C310C5932F84CD6C17AC /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; @@ -165,6 +167,7 @@ children = ( F76AC1C0266713D00040C8BC /* IosPlatformImagesTests.m */, F76AC1C2266713D00040C8BC /* Info.plist */, + 33B0E32B2AB348FF0006F0C1 /* UIImage+ios_platform_imagesTests.m */, ); path = RunnerTests; sourceTree = ""; @@ -299,10 +302,12 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/integration_test/integration_test.framework", "${BUILT_PRODUCTS_DIR}/ios_platform_images/ios_platform_images.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/integration_test.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ios_platform_images.framework", ); runOnlyForDeploymentPostprocessing = 0; @@ -385,6 +390,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 33B0E32C2AB348FF0006F0C1 /* UIImage+ios_platform_imagesTests.m in Sources */, F76AC1C1266713D00040C8BC /* IosPlatformImagesTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -482,7 +488,10 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", @@ -614,7 +623,10 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", @@ -641,7 +653,10 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", @@ -662,7 +677,11 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = S8QB4VV633; INFOPLIST_FILE = RunnerTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; @@ -677,7 +696,11 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = S8QB4VV633; INFOPLIST_FILE = RunnerTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; @@ -692,7 +715,11 @@ CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = S8QB4VV633; INFOPLIST_FILE = RunnerTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; diff --git a/packages/ios_platform_images/example/ios/RunnerTests/UIImage+ios_platform_imagesTests.m b/packages/ios_platform_images/example/ios/RunnerTests/UIImage+ios_platform_imagesTests.m new file mode 100644 index 0000000000000..d107ac4bd34f9 --- /dev/null +++ b/packages/ios_platform_images/example/ios/RunnerTests/UIImage+ios_platform_imagesTests.m @@ -0,0 +1,43 @@ +// 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 ios_platform_images; +@import XCTest; + +// The tests test the UIImage extension which is a public API intended for use from native code +// outside of the plugin (see package README). Any change that requires changing existing tests +// in this file (unless it's just to reflect changes to the test assets) is a BREAKING CHANGE for +// the package. +@interface UIImageExtensionTests : XCTestCase +@end + +@implementation UIImageExtensionTests + +- (void)testMultiResolutionImageUsesBest { + UIImage *image = [UIImage flutterImageWithName:@"assets/multisize.png"]; + XCTAssertNotNil(image); + const double height1x = 125; // The height of assets/multisize.png. + const double height2x = 250; // The height of assets/2.0x/multisize.png. + // Loading assets should get the best available asset for the screen scale when resolution-aware + // assets are available (and the example app has 1x and 2x for this asset). See + // https://docs.flutter.dev/ui/assets/assets-and-images#resolution-aware + if (UIScreen.mainScreen.scale > 1.0) { + XCTAssertEqualWithAccuracy(image.size.height, height2x, 0.00001); + } else { + XCTAssertEqualWithAccuracy(image.size.height, height1x, 0.00001); + } +} + +- (void)testSingleResolutionFindsImage { + // When there is no resolution-aware asset, the main asset should be used. + UIImage *image = [UIImage flutterImageWithName:@"assets/monosize.png"]; + XCTAssertNotNil(image); +} + +- (void)testMissingImageReturnsNil { + UIImage *image = [UIImage flutterImageWithName:@"assets/no_such_image.png"]; + XCTAssertNil(image); +} + +@end diff --git a/packages/ios_platform_images/example/pubspec.yaml b/packages/ios_platform_images/example/pubspec.yaml index 6674a3a04ae16..f8511e6e9c183 100644 --- a/packages/ios_platform_images/example/pubspec.yaml +++ b/packages/ios_platform_images/example/pubspec.yaml @@ -25,4 +25,6 @@ dev_dependencies: sdk: flutter flutter: + assets: + - assets/ uses-material-design: true