-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[ios_platform_images] migrate objC to swift #4847
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
Merged
auto-submit
merged 39 commits into
flutter:main
from
Mairramer:ios_platform_images_swift_migration
Oct 21, 2023
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
ad9ed35
[ios_platform_images] migrate objC to swift
Mairramer e5545bc
pump version
Mairramer cf21182
added some tests
Mairramer 008d5d3
update tests
Mairramer e422e78
Merge branch 'main' into ios_platform_images_swift_migration
Mairramer b0122cf
fix format
Mairramer 54b9b92
Merge branch 'main' into ios_platform_images_swift_migration
Mairramer 6c29139
Merge branch 'main' into ios_platform_images_swift_migration
Mairramer f3ce031
improve code
Mairramer 100202a
rollback comment
Mairramer 97dc083
pump version
Mairramer 1a28d20
Merge branch 'main' into ios_platform_images_swift_migration
Mairramer 8da12bd
rollback implementation
Mairramer 50ce448
rollback original logic
Mairramer 59d7b6d
fix logic
Mairramer 17a369e
rollback logic
Mairramer cfbf55f
Merge branch 'main' into ios_platform_images_swift_migration
Mairramer 101c190
fix test
Mairramer 1d2969b
fix test
Mairramer 372ce11
fix scaled image and migrate tests
Mairramer 523a277
Merge remote-tracking branch 'origin/main' into ios_platform_images_s…
Mairramer aef7985
migrate pigeon to swift
Mairramer 78cbc82
format code
Mairramer 45d185d
fix build script
Mairramer a9a4879
improves
Mairramer 364be83
update readme
Mairramer aae7a29
rollback objC test
Mairramer cbbc208
fix test import
Mairramer ac54592
improves
Mairramer 3e66718
improve test
Mairramer 71f2589
fix test
Mairramer e2d9a9a
Merge branch 'main' into ios_platform_images_swift_migration
Mairramer 3324ccd
rollback
Mairramer e370d61
update readme
Mairramer b25d574
Revert whitespace change in podfile
stuartmorgan-g 5d03976
TODO style fix
stuartmorgan-g eaf7c90
Re-add DEFINES_MODULE
stuartmorgan-g 139e125
Merge branch 'main' into ios_platform_images_swift_migration
stuartmorgan-g 6ea1fc0
Merge branch 'main' into ios_platform_images_swift_migration
Mairramer 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,4 @@ Aleksandr Yurkovskiy <[email protected]> | |
Anton Borries <[email protected]> | ||
Alex Li <[email protected]> | ||
Rahul Raj <[email protected]> | ||
Mairramer <[email protected]> |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.2.3 | ||
|
||
* Migrates to a Swift implementation. | ||
|
||
## 0.2.2+3 | ||
|
||
* Converts platform communication to Pigeon. | ||
|
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
113 changes: 70 additions & 43 deletions
113
packages/ios_platform_images/example/ios/Runner.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...es/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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
18 changes: 0 additions & 18 deletions
18
packages/ios_platform_images/example/ios/RunnerTests/IosPlatformImagesTests.m
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
packages/ios_platform_images/example/ios/RunnerTests/IosPlatformImagesTests.swift
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,48 @@ | ||
// 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 XCTest | ||
|
||
@testable import ios_platform_images | ||
|
||
class IosPlatformImagesTests: XCTestCase { | ||
let plugin = IosPlatformImagesPlugin() | ||
|
||
func testLoadImage() { | ||
let assetName = "flutter" | ||
let imageData = plugin.loadImage(name: assetName) | ||
|
||
XCTAssertNotNil(imageData) | ||
XCTAssertNotNil(imageData?.data) | ||
} | ||
|
||
func testLoadImageNotFound() { | ||
let assetName = "notFound" | ||
let imageData = plugin.loadImage(name: assetName) | ||
|
||
Mairramer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
XCTAssertNil(imageData) | ||
} | ||
|
||
func testResolveURL() { | ||
let resourceName = "textfile" | ||
do { | ||
let url = try plugin.resolveUrl(resourceName: resourceName, extension: nil) | ||
XCTAssertNotNil(url) | ||
XCTAssertTrue(url?.contains(resourceName) ?? false) | ||
} catch { | ||
XCTFail("Error while resolving URL: \(error)") | ||
} | ||
} | ||
|
||
func testResolveURLNotFound() { | ||
do { | ||
let url = try plugin.resolveUrl(resourceName: "notFound", extension: nil) | ||
XCTAssertNil(url) | ||
} catch { | ||
XCTFail("Error while resolving URL: \(error)") | ||
} | ||
} | ||
|
||
} |
12 changes: 0 additions & 12 deletions
12
packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.h
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.m
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
packages/ios_platform_images/ios/Classes/IosPlatformImagesPlugin.swift
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,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 | ||
} | ||
|
||
} |
27 changes: 0 additions & 27 deletions
27
packages/ios_platform_images/ios/Classes/UIImage+ios_platform_images.h
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
packages/ios_platform_images/ios/Classes/UIImage+ios_platform_images.m
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
packages/ios_platform_images/ios/Classes/UIImageIosPlatformImages.swift
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,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 | ||
Mairramer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) | ||
} | ||
Mairramer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.