Skip to content

Commit 210a568

Browse files
RobertOdrowazandroidseb
authored andcommitted
[camera_avfoundation] Implementation swift migration (flutter#8988)
Migrates camera implementation as part of flutter/flutter#119109 ~This PR includes the `CameraPlugin` class migration. Some additional changes regarding imports were necessary to keep Swift Package Manager compatibility. SPM does not support mixed languages in a single target. I assume there might be a better solution so I'm open to suggestions~ After splitting only a new target for SPM is created in this PR and the objc implementation is moved to a dedicated directory. During the plugin's migration from ObjC to Swift, there will be a transitional period during which the implementation will be mixed, with some parts already migrated to Swift and some still in ObjC. This is somewhat problematic with SwiftPM. SwiftPM does support packages with mixed language implementation but different languages have to be in separate targets. Every target defines a separate module which means that in some cases both have to be imported. However, this only applies to SwiftPM with Cocoapods we can mix Swift and ObjC code in the same pod and have a single module. Simmingly the best solution is to use conditional imports for the additional module when SwiftPM during the migration. ```swift @testable import camera_avfoundation #if canImport(camera_avfoundation_objc) @testable import camera_avfoundation_objc #endif ``` ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 50bd4bd commit 210a568

File tree

102 files changed

+301
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+301
-60
lines changed

packages/camera/camera_avfoundation/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.9.18+14
2+
3+
* Creates Swift Package Manager target for Swift implementation.
4+
15
## 0.9.18+13
26

37
* Migrates test utils and mocks to Swift.

packages/camera/camera_avfoundation/example/ios/RunnerTests/AvailableCamerasTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import XCTest
77

88
@testable import camera_avfoundation
99

10+
// Import Objectice-C part of the implementation when SwiftPM is used.
11+
#if canImport(camera_avfoundation_objc)
12+
@testable import camera_avfoundation_objc
13+
#endif
14+
1015
final class AvailableCamerasTest: XCTestCase {
1116
private func createCameraPlugin(with deviceDiscoverer: MockCameraDeviceDiscoverer) -> CameraPlugin
1217
{

packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraCaptureSessionQueueRaceConditionTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import XCTest
66

77
@testable import camera_avfoundation
88

9+
// Import Objectice-C part of the implementation when SwiftPM is used.
10+
#if canImport(camera_avfoundation_objc)
11+
@testable import camera_avfoundation_objc
12+
#endif
13+
914
final class CameraCaptureSessionQueueRaceConditionTests: XCTestCase {
1015
private func createCameraPlugin() -> CameraPlugin {
1116
return CameraPlugin(

packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraMethodChannelTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import XCTest
77

88
@testable import camera_avfoundation
99

10+
// Import Objectice-C part of the implementation when SwiftPM is used.
11+
#if canImport(camera_avfoundation_objc)
12+
@testable import camera_avfoundation_objc
13+
#endif
14+
1015
final class CameraMethodChannelTests: XCTestCase {
1116
private func createCameraPlugin(with session: MockCaptureSession) -> CameraPlugin {
1217
return CameraPlugin(

packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraOrientationTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import XCTest
88

99
@testable import camera_avfoundation
1010

11+
// Import Objectice-C part of the implementation when SwiftPM is used.
12+
#if canImport(camera_avfoundation_objc)
13+
@testable import camera_avfoundation_objc
14+
#endif
15+
1116
private final class MockUIDevice: UIDevice {
1217
var mockOrientation: UIDeviceOrientation = .unknown
1318

packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPermissionTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import XCTest
77

88
@testable import camera_avfoundation
99

10+
// Import Objectice-C part of the implementation when SwiftPM is used.
11+
#if canImport(camera_avfoundation_objc)
12+
@testable import camera_avfoundation_objc
13+
#endif
14+
1015
private final class MockPermissionService: NSObject, FLTPermissionServicing {
1116
var authorizationStatusStub: ((AVMediaType) -> AVAuthorizationStatus)?
1217
var requestAccessStub: ((AVMediaType, @escaping (Bool) -> Void) -> Void)?

packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginCreateCameraTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import XCTest
66

77
@testable import camera_avfoundation
88

9+
// Import Objectice-C part of the implementation when SwiftPM is used.
10+
#if canImport(camera_avfoundation_objc)
11+
@testable import camera_avfoundation_objc
12+
#endif
13+
914
final class CameraPluginCreateCameraTests: XCTestCase {
1015
private func createCameraPlugin() -> (
1116
CameraPlugin, MockFLTCameraPermissionManager, MockCaptureSession

packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginDelegatingMethodTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import XCTest
66

77
@testable import camera_avfoundation
88

9+
// Import Objectice-C part of the implementation when SwiftPM is used.
10+
#if canImport(camera_avfoundation_objc)
11+
@testable import camera_avfoundation_objc
12+
#endif
13+
914
/// Tests of `CameraPlugin` methods delegating to `FLTCam` instance
1015
final class CameraPluginDelegatingMethodTests: XCTestCase {
1116
private func createCameraPlugin() -> (CameraPlugin, MockFLTCam) {

packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginInitializeCameraTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import XCTest
66

77
@testable import camera_avfoundation
88

9+
// Import Objectice-C part of the implementation when SwiftPM is used.
10+
#if canImport(camera_avfoundation_objc)
11+
@testable import camera_avfoundation_objc
12+
#endif
13+
914
final class CameraPluginInitializeCameraTests: XCTestCase {
1015
private func createCameraPlugin() -> (
1116
CameraPlugin, MockFLTCam, MockGlobalEventApi

packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPreviewPauseTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import XCTest
77

88
@testable import camera_avfoundation
99

10+
// Import Objectice-C part of the implementation when SwiftPM is used.
11+
#if canImport(camera_avfoundation_objc)
12+
@testable import camera_avfoundation_objc
13+
#endif
14+
1015
final class CameraPreviewPauseTests: XCTestCase {
1116
func testPausePreviewWithResult_shouldPausePreview() {
1217
let camera = FLTCam()

0 commit comments

Comments
 (0)