-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[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
Changes from 14 commits
ad9ed35
e5545bc
cf21182
008d5d3
e422e78
b0122cf
54b9b92
6c29139
f3ce031
100202a
97dc083
1a28d20
8da12bd
50ce448
59d7b6d
17a369e
cfbf55f
101c190
1d2969b
372ce11
523a277
aef7985
78cbc82
45d185d
a9a4879
364be83
aae7a29
cbbc208
ac54592
3e66718
71f2589
e2d9a9a
3324ccd
e370d61
b25d574
5d03976
eaf7c90
139e125
6ea1fc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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]> | ||
| 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+2 | ||
|
|
||
| * Adds pub topics to package metadata. | ||
|
|
||
Large diffs are not rendered by default.
| 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> | ||
Mairramer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <true/> | ||
| </dict> | ||
| </plist> | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| // 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 { | ||
|
|
||
| func testHandleMethodCall_loadImage() { | ||
| let assetName = "flutter" | ||
|
|
||
| let call = FlutterMethodCall(methodName: "loadImage", arguments: [assetName]) | ||
| let mockChannel = MockMethodChannel() | ||
| let plugin = IosPlatformImagesPlugin(channel: mockChannel) | ||
|
|
||
| let resultExpectation = expectation(description: "result block must be called.") | ||
|
|
||
| plugin.handle(call) { result in | ||
| let result = result as? [String: Any] | ||
| XCTAssertNotNil(result) | ||
|
|
||
| let scale = result?["scale"] as? CGFloat | ||
| let data = result?["data"] as? FlutterStandardTypedData | ||
|
|
||
| XCTAssertNotNil(scale) | ||
| XCTAssertNotNil(data) | ||
|
|
||
| resultExpectation.fulfill() | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 2, handler: nil) | ||
|
||
| } | ||
|
|
||
| func testHandleMethodCall_loadImage_notFound() { | ||
| let assetName = "flutterNotFound" | ||
|
|
||
| let call = FlutterMethodCall(methodName: "loadImage", arguments: [assetName]) | ||
| let mockChannel = MockMethodChannel() | ||
| let plugin = IosPlatformImagesPlugin(channel: mockChannel) | ||
|
|
||
| let resultExpectation = expectation(description: "result block must be called.") | ||
|
|
||
| plugin.handle(call) { result in | ||
| let result = result as? [String: Any] | ||
|
|
||
| XCTAssertNil(result) | ||
| resultExpectation.fulfill() | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 2, handler: nil) | ||
| } | ||
|
|
||
| func testHandleMethodCall_resolveURL() { | ||
| let assetName = "textfile" | ||
|
|
||
| let call = FlutterMethodCall(methodName: "resolveURL", arguments: [assetName]) | ||
| let mockChannel = MockMethodChannel() | ||
| let plugin = IosPlatformImagesPlugin(channel: mockChannel) | ||
|
|
||
| let resultExpectation = expectation(description: "result block must be called.") | ||
|
|
||
| plugin.handle(call) { result in | ||
| let result = result as? String | ||
| XCTAssertNotNil(result) | ||
| XCTAssertEqual(result?.components(separatedBy: "/").last, assetName) | ||
| resultExpectation.fulfill() | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 1, handler: nil) | ||
| } | ||
|
|
||
| func testHandleMethodCall_resolveURL_notFound() { | ||
| let assetName = "notFound" | ||
|
|
||
| let call = FlutterMethodCall(methodName: "resolveURL", arguments: [assetName]) | ||
| let mockChannel = MockMethodChannel() | ||
| let plugin = IosPlatformImagesPlugin(channel: mockChannel) | ||
|
|
||
| let resultExpectation = expectation(description: "result block must be called.") | ||
|
|
||
| plugin.handle(call) { result in | ||
| XCTAssertNil(result) | ||
| resultExpectation.fulfill() | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 1, handler: nil) | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // 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 Foundation | ||
|
|
||
| @testable import ios_platform_images | ||
|
|
||
| final class MockMethodChannel: MethodChannel { | ||
| var invokeMethodStub: ((_ methods: String, _ arguments: Any?) -> Void)? = nil | ||
| func invokeMethod(_ method: String, arguments: Any?) { | ||
| invokeMethodStub?(method, arguments) | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // 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 { | ||
|
|
||
| private let channel: MethodChannel | ||
Mairramer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| init(channel: MethodChannel) { | ||
| self.channel = channel | ||
| } | ||
|
|
||
| public static func register(with registrar: FlutterPluginRegistrar) { | ||
| let channel = FlutterMethodChannel( | ||
| name: "plugins.flutter.io/ios_platform_images", | ||
| binaryMessenger: registrar.messenger()) | ||
|
|
||
| let instance = IosPlatformImagesPlugin(channel: channel) | ||
| registrar.addMethodCallDelegate(instance, channel: channel) | ||
| } | ||
|
|
||
| public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { | ||
| switch call.method { | ||
| case "loadImage": | ||
| loadImage(call, result) | ||
| case "resolveURL": | ||
| resolveURL(call, result) | ||
| default: | ||
| result(FlutterMethodNotImplemented) | ||
| } | ||
| } | ||
|
|
||
| private func loadImage(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { | ||
| if let name = call.arguments as? [String], let firstItem = name.first { | ||
| guard let image = flutterImageWithName(withName: firstItem) else { | ||
Mairramer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| result(nil) | ||
| return | ||
| } | ||
|
|
||
| guard let data = image.pngData() else { | ||
| result(nil) | ||
| return | ||
| } | ||
|
|
||
| let imageResult: [String: Any] = [ | ||
| "scale": image.scale, | ||
| "data": FlutterStandardTypedData(bytes: data), | ||
| ] | ||
|
|
||
| result(imageResult) | ||
| } else { | ||
| result(nil) | ||
| } | ||
| } | ||
|
|
||
| private func resolveURL(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { | ||
| if let args = call.arguments as? [String?] { | ||
|
||
| let name = args[0] | ||
| let extensionName = args.count == 2 ? args[1] : nil | ||
|
||
|
|
||
| if let url = Bundle.main.url(forResource: name, withExtension: extensionName) { | ||
|
||
| result(url.absoluteString) | ||
| } else { | ||
| result(nil) | ||
| } | ||
| } else { | ||
| result(nil) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // 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 | ||
|
|
||
| /// A channel for platform code to communicate with the Dart code. | ||
| protocol MethodChannel { | ||
Mairramer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// Invokes a method in Dart code. | ||
| /// - Parameter method the method name. | ||
| /// - Parameter arguments the method arguments. | ||
| func invokeMethod(_ method: String, arguments: Any?) | ||
| } | ||
|
|
||
| /// A default implementation of the `MethodChannel` protocol. | ||
| extension FlutterMethodChannel: MethodChannel {} | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.