diff --git a/packages/ios_platform_images/AUTHORS b/packages/ios_platform_images/AUTHORS index 493a0b4ef9c2..0d1bfa6a90c7 100644 --- a/packages/ios_platform_images/AUTHORS +++ b/packages/ios_platform_images/AUTHORS @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> +Mairramer diff --git a/packages/ios_platform_images/CHANGELOG.md b/packages/ios_platform_images/CHANGELOG.md index 00259503a204..82b3b09b2281 100644 --- a/packages/ios_platform_images/CHANGELOG.md +++ b/packages/ios_platform_images/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.3 + +* Migrates to a Swift implementation. + ## 0.2.2+3 * Converts platform communication to Pigeon. diff --git a/packages/ios_platform_images/README.md b/packages/ios_platform_images/README.md index 9265b108595e..69dc63ace5ad 100644 --- a/packages/ios_platform_images/README.md +++ b/packages/ios_platform_images/README.md @@ -32,15 +32,15 @@ Widget build(BuildContext context) { } ``` -`IosPlatformImages.load` functions like [[UIImage imageNamed:]](https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed). +`IosPlatformImages.load` works similarly to [`UIImage(named:)`](https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed). ### Flutter->iOS Example -```objc -#import +```swift +import ios_platform_images -static UIImageView* MakeImage() { - UIImage* image = [UIImage flutterImageWithName:@"assets/foo.png"]; - return [[UIImageView alloc] initWithImage:image]; +func makeImage() -> UIImageView { + let image = UIImage.flutterImageWithName("assets/foo.png") + return UIImageView(image: image) } ``` 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 ba035186b2fc..0813ac0fc156 100644 --- a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj @@ -8,16 +8,17 @@ /* Begin PBXBuildFile section */ 0DE21BF72447752100097E3A /* textfile in Resources */ = {isa = PBXBuildFile; fileRef = 0DE21BF62447752100097E3A /* textfile */; }; + 101538FD877087FE0BE2EA00 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 70ED43CFA0E2E576A8AB8B24 /* Pods_Runner.framework */; }; 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 */; }; + 3131C9A32ADEFDA9000703FA /* UIImage+ios_platform_imagesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3131C9A22ADEFDA8000703FA /* UIImage+ios_platform_imagesTests.m */; }; + 31DC4A212AA8CC9300781E88 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; + 937254B9D43BF2078EE3DE65 /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A144F620445D38CD0FEB7B8E /* Pods_RunnerTests.framework */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; - A30D9778BC0D4D09580CF4BE /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 906079E3CC5A6FAB808EAF1E /* Pods_Runner.framework */; }; - F76AC1C1266713D00040C8BC /* IosPlatformImagesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F76AC1C0266713D00040C8BC /* IosPlatformImagesTests.m */; }; - FC73B055B2CD2E32A3E50B27 /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD2C5EF0E06B6EC7EBCB922C /* Pods_RunnerTests.framework */; }; + F76AC1C1266713D00040C8BC /* IosPlatformImagesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76AC1C0266713D00040C8BC /* IosPlatformImagesTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -49,14 +50,14 @@ 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 = ""; }; + 33B0E32B2AB348FF0006F0C1 /* UIImage+ios_platform_imagesTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ios_platform_imagesTests.m"; sourceTree = ""; }; 3153765C2AAA95AD009694AF /* libios_platform_images.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libios_platform_images.a; sourceTree = BUILT_PRODUCTS_DIR; }; 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 = ""; }; + 70ED43CFA0E2E576A8AB8B24 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 80830F517E3E8B75B2D3AC0A /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = ""; }; - 906079E3CC5A6FAB808EAF1E /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -64,11 +65,11 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - AD2C5EF0E06B6EC7EBCB922C /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + A144F620445D38CD0FEB7B8E /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D1A761179BC59B1BAEE63036 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; D36FEDC657E1CE88220062D7 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; F76AC1BE266713D00040C8BC /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - F76AC1C0266713D00040C8BC /* IosPlatformImagesTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IosPlatformImagesTests.m; sourceTree = ""; }; + F76AC1C0266713D00040C8BC /* IosPlatformImagesTests.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; path = IosPlatformImagesTests.swift; sourceTree = ""; }; F76AC1C2266713D00040C8BC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ @@ -77,7 +78,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - A30D9778BC0D4D09580CF4BE /* Pods_Runner.framework in Frameworks */, + 101538FD877087FE0BE2EA00 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -85,7 +86,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FC73B055B2CD2E32A3E50B27 /* Pods_RunnerTests.framework in Frameworks */, + 937254B9D43BF2078EE3DE65 /* Pods_RunnerTests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -156,8 +157,9 @@ DBEBA2309FD49D5C34798105 /* Frameworks */ = { isa = PBXGroup; children = ( - 906079E3CC5A6FAB808EAF1E /* Pods_Runner.framework */, - AD2C5EF0E06B6EC7EBCB922C /* Pods_RunnerTests.framework */, + 3153765C2AAA95AD009694AF /* libios_platform_images.a */, + 70ED43CFA0E2E576A8AB8B24 /* Pods_Runner.framework */, + A144F620445D38CD0FEB7B8E /* Pods_RunnerTests.framework */, ); name = Frameworks; sourceTree = ""; @@ -165,9 +167,9 @@ F76AC1BF266713D00040C8BC /* RunnerTests */ = { isa = PBXGroup; children = ( - F76AC1C0266713D00040C8BC /* IosPlatformImagesTests.m */, + 3131C9A22ADEFDA8000703FA /* UIImage+ios_platform_imagesTests.m */, + F76AC1C0266713D00040C8BC /* IosPlatformImagesTests.swift */, F76AC1C2266713D00040C8BC /* Info.plist */, - 33B0E32B2AB348FF0006F0C1 /* UIImage+ios_platform_imagesTests.m */, ); path = RunnerTests; sourceTree = ""; @@ -186,7 +188,7 @@ 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, - 54C54D6BB826835E8AB0FA51 /* [CP] Embed Pods Frameworks */, + B747922D12365ABBBA69BEA8 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -232,6 +234,7 @@ F76AC1BD266713D00040C8BC = { CreatedOnToolsVersion = 12.5; DevelopmentTeam = S8QB4VV633; + LastSwiftMigration = 1410; ProvisioningStyle = Automatic; TestTargetID = 97C146ED1CF9000F007C117D; }; @@ -273,6 +276,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 31DC4A212AA8CC9300781E88 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -295,26 +299,6 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; - 54C54D6BB826835E8AB0FA51 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - 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; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; 73331024E8B67D581A0862F0 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -339,8 +323,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; - alwaysOutOfDate = 1; - buildActionMask = 2147483647; + buildActionMask = 12; files = ( ); inputPaths = ( @@ -350,7 +333,25 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n"; + }; + B747922D12365ABBBA69BEA8 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/ios_platform_images/ios_platform_images.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ios_platform_images.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; }; C102F13F37851E08F0608EE5 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; @@ -390,8 +391,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 33B0E32C2AB348FF0006F0C1 /* UIImage+ios_platform_imagesTests.m in Sources */, - F76AC1C1266713D00040C8BC /* IosPlatformImagesTests.m in Sources */, + 3131C9A32ADEFDA9000703FA /* UIImage+ios_platform_imagesTests.m in Sources */, + F76AC1C1266713D00040C8BC /* IosPlatformImagesTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -448,6 +449,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -466,7 +468,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -527,6 +529,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -551,7 +554,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -582,6 +585,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -600,10 +604,11 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -674,8 +679,14 @@ baseConfigurationReference = 0B20D3254D8E1A2B01D83810 /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = S8QB4VV633; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"${PODS_CONFIGURATION_BUILD_DIR}/ios_platform_images/ios_platform_images.framework/Headers\"", + $CONFIGURATION_TEMP_DIR/YourProject.build/DerivedSources, + ); INFOPLIST_FILE = RunnerTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -684,6 +695,8 @@ ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; }; name = Debug; @@ -693,8 +706,14 @@ baseConfigurationReference = D36FEDC657E1CE88220062D7 /* Pods-RunnerTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = S8QB4VV633; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"${PODS_CONFIGURATION_BUILD_DIR}/ios_platform_images/ios_platform_images.framework/Headers\"", + $CONFIGURATION_TEMP_DIR/YourProject.build/DerivedSources, + ); INFOPLIST_FILE = RunnerTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -703,6 +722,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; }; name = Release; @@ -712,8 +732,14 @@ baseConfigurationReference = 80830F517E3E8B75B2D3AC0A /* Pods-RunnerTests.profile.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = S8QB4VV633; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"${PODS_CONFIGURATION_BUILD_DIR}/ios_platform_images/ios_platform_images.framework/Headers\"", + $CONFIGURATION_TEMP_DIR/YourProject.build/DerivedSources, + ); INFOPLIST_FILE = RunnerTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -722,6 +748,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; }; name = Profile; diff --git a/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000000..18d981003d68 --- /dev/null +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 51e700a5f8c5..42695972f4c0 100644 --- a/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/ios_platform_images/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -20,6 +20,20 @@ ReferencedContainer = "container:Runner.xcodeproj"> + + + + - -#import "messages.g.h" - -/// A plugin for Flutter that allows Flutter to load images in a platform -/// specific way on iOS. -@interface IosPlatformImagesPlugin : NSObject -@end diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m deleted file mode 100644 index b41ff9900d8e..000000000000 --- a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m +++ /dev/null @@ -1,40 +0,0 @@ -// 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 "IosPlatformImagesPlugin.h" - -#if !__has_feature(objc_arc) -#error ARC must be enabled! -#endif - -@interface IosPlatformImagesPlugin () -@end - -@implementation IosPlatformImagesPlugin - -+ (void)registerWithRegistrar:(NSObject *)registrar { - FPIPlatformImagesApiSetup(registrar.messenger, [[IosPlatformImagesPlugin alloc] init]); -} - -- (nullable FPIPlatformImageData *) - loadImageWithName:(nonnull NSString *)name - error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { - UIImage *image = [UIImage imageNamed:name]; - NSData *data = UIImagePNGRepresentation(image); - if (!data) { - return nil; - } - return [FPIPlatformImageData makeWithData:[FlutterStandardTypedData typedDataWithBytes:data] - scale:@(image.scale)]; -} - -- (nullable NSString *)resolveURLForResource:(nonnull NSString *)name - withExtension:(nullable NSString *)extension - error:(FlutterError *_Nullable __autoreleasing *_Nonnull) - error { - NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:extension]; - return url.absoluteString; -} - -@end diff --git a/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.swift b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.swift new file mode 100644 index 000000000000..a47f06733955 --- /dev/null +++ b/packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.swift @@ -0,0 +1,38 @@ +// 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 Flutter +import Foundation + +public final class IosPlatformImagesPlugin: NSObject, FlutterPlugin, PlatformImagesApi { + public static func register(with registrar: FlutterPluginRegistrar) { + let instance = IosPlatformImagesPlugin() + let messenger = registrar.messenger() + PlatformImagesApiSetup.setUp(binaryMessenger: messenger, api: instance) + } + + func loadImage(name: String) -> PlatformImageData? { + guard let image = UIImage(named: name), + let data = image.pngData() + else { + return nil + } + + return PlatformImageData( + data: FlutterStandardTypedData(bytes: data), scale: Double(image.scale)) + } + + func resolveUrl(resourceName: String, extension: String?) throws -> String? { + guard + let url = Bundle.main.url( + forResource: resourceName, + withExtension: `extension`) + else { + return nil + } + + return url.absoluteString + } + +} diff --git a/packages/ios_platform_images/ios/Classes/UIImage+ios_platform_images.h b/packages/ios_platform_images/ios/Classes/UIImage+ios_platform_images.h deleted file mode 100644 index 356a5f1cfe3e..000000000000 --- a/packages/ios_platform_images/ios/Classes/UIImage+ios_platform_images.h +++ /dev/null @@ -1,27 +0,0 @@ -// 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 - -@interface UIImage (ios_platform_images) - -/// Loads a UIImage from the embedded Flutter project's assets. -/// -/// This method loads the Flutter asset that is appropriate for the current -/// screen. If you are on a 2x retina device where usually `UIImage` would be -/// loading `@2x` assets, it will attempt to load the `2.0x` variant. It will -/// load the standard image if it can't find the `2.0x` variant. -/// -/// For example, if your Flutter project's `pubspec.yaml` lists "assets/foo.png" -/// and "assets/2.0x/foo.png", calling -/// `[UIImage flutterImageWithName:@"assets/foo.png"]` will load -/// "assets/2.0x/foo.png". -/// -/// See also https://flutter.dev/docs/development/ui/assets-and-images -/// -/// Note: We don't yet support images from package dependencies (ex. -/// `AssetImage('icons/heart.png', package: 'my_icons')`). -+ (UIImage *)flutterImageWithName:(NSString *)name; - -@end diff --git a/packages/ios_platform_images/ios/Classes/UIImage+ios_platform_images.m b/packages/ios_platform_images/ios/Classes/UIImage+ios_platform_images.m deleted file mode 100644 index f20bbcd08c9b..000000000000 --- a/packages/ios_platform_images/ios/Classes/UIImage+ios_platform_images.m +++ /dev/null @@ -1,25 +0,0 @@ -// 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 -#import "UIImage+ios_platform_images.h" - -@implementation UIImage (ios_platform_images) -+ (UIImage *)flutterImageWithName:(NSString *)name { - NSString *filename = [name lastPathComponent]; - NSString *path = [name stringByDeletingLastPathComponent]; - for (int screenScale = [UIScreen mainScreen].scale; screenScale > 1; --screenScale) { - NSString *key = [FlutterDartProject - lookupKeyForAsset:[NSString stringWithFormat:@"%@/%d.0x/%@", path, screenScale, filename]]; - UIImage *image = [UIImage imageNamed:key - inBundle:[NSBundle mainBundle] - compatibleWithTraitCollection:nil]; - if (image) { - return image; - } - } - NSString *key = [FlutterDartProject lookupKeyForAsset:name]; - return [UIImage imageNamed:key inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; -} -@end diff --git a/packages/ios_platform_images/ios/Classes/UIImageIosPlatformImages.swift b/packages/ios_platform_images/ios/Classes/UIImageIosPlatformImages.swift new file mode 100644 index 000000000000..2e9cdefe6731 --- /dev/null +++ b/packages/ios_platform_images/ios/Classes/UIImageIosPlatformImages.swift @@ -0,0 +1,41 @@ +// 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 Flutter +import Foundation +import UIKit + +@objc extension UIImage { + /// Loads a UIImage from the embedded Flutter project's assets. + /// + /// This method loads the Flutter asset that is appropriate for the current + /// screen. If you are on a 2x retina device where usually `UIImage` would be + /// loading `@2x` assets, it will attempt to load the `2.0x` variant. It will + /// load the standard image if it can't find the `2.0x` variant. + /// + /// For example, if your Flutter project's `pubspec.yaml` lists "assets/foo.png" + /// and "assets/2.0x/foo.png", calling + /// `[UIImage flutterImageWithName:@"assets/foo.png"]` will load + /// "assets/2.0x/foo.png". + /// + /// See also https://flutter.dev/docs/development/ui/assets-and-images + /// + /// Note: We don't yet support images from package dependencies (ex. + /// `AssetImage('icons/heart.png', package: 'my_icons')`). + public static func flutterImageWithName(_ name: String) -> UIImage? { + let filename = (name as NSString).lastPathComponent + let path = (name as NSString).deletingLastPathComponent + + for screenScale in stride(from: Int(UIScreen.main.scale), to: 1, by: -1) { + // TODO(hellohuanlin): Fix duplicate slashes in this path construction. + let key = FlutterDartProject.lookupKey(forAsset: "\(path)/\(screenScale).0x/\(filename)") + if let image = UIImage(named: key, in: Bundle.main, compatibleWith: nil) { + return image + } + } + + let key = FlutterDartProject.lookupKey(forAsset: name) + return UIImage(named: key, in: Bundle.main, compatibleWith: nil) + } +} diff --git a/packages/ios_platform_images/ios/Classes/messages.g.h b/packages/ios_platform_images/ios/Classes/messages.g.h deleted file mode 100644 index f4235cf9063b..000000000000 --- a/packages/ios_platform_images/ios/Classes/messages.g.h +++ /dev/null @@ -1,47 +0,0 @@ -// 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. -// Autogenerated from Pigeon (v11.0.1), do not edit directly. -// See also: https://pub.dev/packages/pigeon - -#import - -@protocol FlutterBinaryMessenger; -@protocol FlutterMessageCodec; -@class FlutterError; -@class FlutterStandardTypedData; - -NS_ASSUME_NONNULL_BEGIN - -@class FPIPlatformImageData; - -/// A serialization of a platform image's data. -@interface FPIPlatformImageData : NSObject -/// `init` unavailable to enforce nonnull fields, see the `make` class method. -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithData:(FlutterStandardTypedData *)data scale:(NSNumber *)scale; -/// The image data. -@property(nonatomic, strong) FlutterStandardTypedData *data; -/// The image's scale factor. -@property(nonatomic, strong) NSNumber *scale; -@end - -/// The codec used by FPIPlatformImagesApi. -NSObject *FPIPlatformImagesApiGetCodec(void); - -@protocol FPIPlatformImagesApi -/// Returns the URL for the given resource, or null if no such resource is -/// found. -- (nullable NSString *)resolveURLForResource:(NSString *)resourceName - withExtension:(nullable NSString *)extension - error:(FlutterError *_Nullable *_Nonnull)error; -/// Returns the data for the image resource with the given name, or null if -/// no such resource is found. -- (nullable FPIPlatformImageData *)loadImageWithName:(NSString *)name - error:(FlutterError *_Nullable *_Nonnull)error; -@end - -extern void FPIPlatformImagesApiSetup(id binaryMessenger, - NSObject *_Nullable api); - -NS_ASSUME_NONNULL_END diff --git a/packages/ios_platform_images/ios/Classes/messages.g.m b/packages/ios_platform_images/ios/Classes/messages.g.m deleted file mode 100644 index b96e65ea263b..000000000000 --- a/packages/ios_platform_images/ios/Classes/messages.g.m +++ /dev/null @@ -1,163 +0,0 @@ -// 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. -// Autogenerated from Pigeon (v11.0.1), do not edit directly. -// See also: https://pub.dev/packages/pigeon - -#import "messages.g.h" - -#if TARGET_OS_OSX -#import -#else -#import -#endif - -#if !__has_feature(objc_arc) -#error File requires ARC to be enabled. -#endif - -static NSArray *wrapResult(id result, FlutterError *error) { - if (error) { - return @[ - error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] - ]; - } - return @[ result ?: [NSNull null] ]; -} -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { - id result = array[key]; - return (result == [NSNull null]) ? nil : result; -} - -@interface FPIPlatformImageData () -+ (FPIPlatformImageData *)fromList:(NSArray *)list; -+ (nullable FPIPlatformImageData *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; -@end - -@implementation FPIPlatformImageData -+ (instancetype)makeWithData:(FlutterStandardTypedData *)data scale:(NSNumber *)scale { - FPIPlatformImageData *pigeonResult = [[FPIPlatformImageData alloc] init]; - pigeonResult.data = data; - pigeonResult.scale = scale; - return pigeonResult; -} -+ (FPIPlatformImageData *)fromList:(NSArray *)list { - FPIPlatformImageData *pigeonResult = [[FPIPlatformImageData alloc] init]; - pigeonResult.data = GetNullableObjectAtIndex(list, 0); - NSAssert(pigeonResult.data != nil, @""); - pigeonResult.scale = GetNullableObjectAtIndex(list, 1); - NSAssert(pigeonResult.scale != nil, @""); - return pigeonResult; -} -+ (nullable FPIPlatformImageData *)nullableFromList:(NSArray *)list { - return (list) ? [FPIPlatformImageData fromList:list] : nil; -} -- (NSArray *)toList { - return @[ - (self.data ?: [NSNull null]), - (self.scale ?: [NSNull null]), - ]; -} -@end - -@interface FPIPlatformImagesApiCodecReader : FlutterStandardReader -@end -@implementation FPIPlatformImagesApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [FPIPlatformImageData fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface FPIPlatformImagesApiCodecWriter : FlutterStandardWriter -@end -@implementation FPIPlatformImagesApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[FPIPlatformImageData class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface FPIPlatformImagesApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation FPIPlatformImagesApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[FPIPlatformImagesApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[FPIPlatformImagesApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *FPIPlatformImagesApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - FPIPlatformImagesApiCodecReaderWriter *readerWriter = - [[FPIPlatformImagesApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; -} - -void FPIPlatformImagesApiSetup(id binaryMessenger, - NSObject *api) { - /// Returns the URL for the given resource, or null if no such resource is - /// found. - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.ios_platform_images.PlatformImagesApi.resolveUrl" - binaryMessenger:binaryMessenger - codec:FPIPlatformImagesApiGetCodec()]; - if (api) { - NSCAssert([api respondsToSelector:@selector(resolveURLForResource:withExtension:error:)], - @"FPIPlatformImagesApi api (%@) doesn't respond to " - @"@selector(resolveURLForResource:withExtension:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSString *arg_resourceName = GetNullableObjectAtIndex(args, 0); - NSString *arg_extension = GetNullableObjectAtIndex(args, 1); - FlutterError *error; - NSString *output = [api resolveURLForResource:arg_resourceName - withExtension:arg_extension - error:&error]; - callback(wrapResult(output, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } - /// Returns the data for the image resource with the given name, or null if - /// no such resource is found. - { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.ios_platform_images.PlatformImagesApi.loadImage" - binaryMessenger:binaryMessenger - codec:FPIPlatformImagesApiGetCodec()]; - if (api) { - NSCAssert( - [api respondsToSelector:@selector(loadImageWithName:error:)], - @"FPIPlatformImagesApi api (%@) doesn't respond to @selector(loadImageWithName:error:)", - api); - [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSString *arg_name = GetNullableObjectAtIndex(args, 0); - FlutterError *error; - FPIPlatformImageData *output = [api loadImageWithName:arg_name error:&error]; - callback(wrapResult(output, error)); - }]; - } else { - [channel setMessageHandler:nil]; - } - } -} diff --git a/packages/ios_platform_images/ios/Classes/messages.g.swift b/packages/ios_platform_images/ios/Classes/messages.g.swift new file mode 100644 index 000000000000..30e14c742423 --- /dev/null +++ b/packages/ios_platform_images/ios/Classes/messages.g.swift @@ -0,0 +1,162 @@ +// 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. +// Autogenerated from Pigeon (v11.0.1), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details, + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)", + ] +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +/// A serialization of a platform image's data. +/// +/// Generated class from Pigeon that represents data sent in messages. +struct PlatformImageData { + /// The image data. + var data: FlutterStandardTypedData + /// The image's scale factor. + var scale: Double + + static func fromList(_ list: [Any?]) -> PlatformImageData? { + let data = list[0] as! FlutterStandardTypedData + let scale = list[1] as! Double + + return PlatformImageData( + data: data, + scale: scale + ) + } + func toList() -> [Any?] { + return [ + data, + scale, + ] + } +} +private class PlatformImagesApiCodecReader: FlutterStandardReader { + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 128: + return PlatformImageData.fromList(self.readValue() as! [Any?]) + default: + return super.readValue(ofType: type) + } + } +} + +private class PlatformImagesApiCodecWriter: FlutterStandardWriter { + override func writeValue(_ value: Any) { + if let value = value as? PlatformImageData { + super.writeByte(128) + super.writeValue(value.toList()) + } else { + super.writeValue(value) + } + } +} + +private class PlatformImagesApiCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return PlatformImagesApiCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return PlatformImagesApiCodecWriter(data: data) + } +} + +class PlatformImagesApiCodec: FlutterStandardMessageCodec { + static let shared = PlatformImagesApiCodec(readerWriter: PlatformImagesApiCodecReaderWriter()) +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol PlatformImagesApi { + /// Returns the URL for the given resource, or null if no such resource is + /// found. + func resolveUrl(resourceName: String, extension: String?) throws -> String? + /// Returns the data for the image resource with the given name, or null if + /// no such resource is found. + func loadImage(name: String) throws -> PlatformImageData? +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class PlatformImagesApiSetup { + /// The codec used by PlatformImagesApi. + static var codec: FlutterStandardMessageCodec { PlatformImagesApiCodec.shared } + /// Sets up an instance of `PlatformImagesApi` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: PlatformImagesApi?) { + /// Returns the URL for the given resource, or null if no such resource is + /// found. + let resolveUrlChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.ios_platform_images.PlatformImagesApi.resolveUrl", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + resolveUrlChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let resourceNameArg = args[0] as! String + let extensionArg: String? = nilOrValue(args[1]) + do { + let result = try api.resolveUrl(resourceName: resourceNameArg, extension: extensionArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + resolveUrlChannel.setMessageHandler(nil) + } + /// Returns the data for the image resource with the given name, or null if + /// no such resource is found. + let loadImageChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.ios_platform_images.PlatformImagesApi.loadImage", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + loadImageChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let nameArg = args[0] as! String + do { + let result = try api.loadImage(name: nameArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + loadImageChannel.setMessageHandler(nil) + } + } +} diff --git a/packages/ios_platform_images/ios/ios_platform_images.podspec b/packages/ios_platform_images/ios/ios_platform_images.podspec index 6b67de3f1338..d0428215e426 100644 --- a/packages/ios_platform_images/ios/ios_platform_images.podspec +++ b/packages/ios_platform_images/ios/ios_platform_images.podspec @@ -15,11 +15,14 @@ Downloaded by pub (not CocoaPods). s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/ios_platform_images' } s.documentation_url = 'https://pub.dev/packages/ios_platform_images' - s.source_files = 'Classes/**/*' + s.source_files = 'Classes/**/*.swift' s.dependency 'Flutter' s.platform = :ios, '11.0' - # Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported. - s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } + s.xcconfig = { + 'DEFINES_MODULE' => 'YES', + 'LIBRARY_SEARCH_PATHS' => '$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)/ $(SDKROOT)/usr/lib/swift', + 'LD_RUNPATH_SEARCH_PATHS' => '/usr/lib/swift', + } s.swift_version = '5.0' end diff --git a/packages/ios_platform_images/lib/ios_platform_images.dart b/packages/ios_platform_images/lib/ios_platform_images.dart index 22e0b84db033..70894f82c8d4 100644 --- a/packages/ios_platform_images/lib/ios_platform_images.dart +++ b/packages/ios_platform_images/lib/ios_platform_images.dart @@ -137,7 +137,7 @@ class IosPlatformImages { imageData.then((PlatformImageData? image) { if (image == null) { scaleCompleter.completeError( - Exception("Image couldn't be found: $name"), + Exception("Scale couldn't be found to load image: $name"), ); bytesCompleter.completeError( Exception("Image couldn't be found: $name"), diff --git a/packages/ios_platform_images/pigeons/messages.dart b/packages/ios_platform_images/pigeons/messages.dart index d0a8d3473171..36cd9931e5bd 100644 --- a/packages/ios_platform_images/pigeons/messages.dart +++ b/packages/ios_platform_images/pigeons/messages.dart @@ -6,9 +6,7 @@ import 'package:pigeon/pigeon.dart'; @ConfigurePigeon(PigeonOptions( dartOut: 'lib/src/messages.g.dart', - objcOptions: ObjcOptions(prefix: 'FPI'), - objcHeaderOut: 'ios/Classes/messages.g.h', - objcSourceOut: 'ios/Classes/messages.g.m', + swiftOut: 'ios/Classes/messages.g.swift', copyrightHeader: 'pigeons/copyright.txt', )) @@ -27,11 +25,9 @@ class PlatformImageData { abstract class PlatformImagesApi { /// Returns the URL for the given resource, or null if no such resource is /// found. - @ObjCSelector('resolveURLForResource:withExtension:') String? resolveUrl(String resourceName, String? extension); /// Returns the data for the image resource with the given name, or null if /// no such resource is found. - @ObjCSelector('loadImageWithName:') PlatformImageData? loadImage(String name); } diff --git a/packages/ios_platform_images/pubspec.yaml b/packages/ios_platform_images/pubspec.yaml index c4a0eee2c690..ac6d7bdb6497 100644 --- a/packages/ios_platform_images/pubspec.yaml +++ b/packages/ios_platform_images/pubspec.yaml @@ -2,7 +2,7 @@ name: ios_platform_images description: A plugin to share images between Flutter and iOS in add-to-app setups. repository: https://github.com/flutter/packages/tree/main/packages/ios_platform_images issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+ios_platform_images%22 -version: 0.2.2+3 +version: 0.2.3 environment: sdk: ">=2.19.0 <4.0.0"