Skip to content

Commit 1e35bca

Browse files
[image_picker_ios] PR 3/5 Split SPM packaging and migrate the plugin class to Swift (flutter#13235)
Splits the Swift package into a Swift target and an `image_picker_ios_objc` target. The Swift target depends on the Objective-C target, which still holds the view provider, image utilities, PHPicker save operation, and Pigeon messages. Migrates `FLTImagePickerPlugin` to `ImagePickerPlugin` and moves the camera, photo library, and PHPicker seams into that Swift target. `pluginClass` is now `ImagePickerPlugin`. Plugin behavior is unchanged. Bumps `image_picker_ios` to **0.8.13+13**. PR 3/5 of the Obj-C → Swift migration. Part of flutter#119107 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^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 0e3b726 commit 1e35bca

38 files changed

Lines changed: 1056 additions & 1252 deletions

‎packages/image_picker/image_picker_ios/CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.8.13+13
2+
3+
* Splits the iOS implementation into mixed-language Swift Package Manager targets.
4+
* Migrates the plugin class from Objective-C to Swift.
5+
* Calls the single-item image and video completions once when more than one path is returned.
6+
17
## 0.8.13+12
28

39
* Updates minimum supported SDK version to Flutter 3.47/Dart 3.13.

‎packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerPluginTests.swift‎

Lines changed: 103 additions & 153 deletions
Large diffs are not rendered by default.

‎packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImageUtilTests.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import UniformTypeIdentifiers
1010

1111
@testable import image_picker_ios
1212

13+
#if canImport(image_picker_ios_objc)
14+
@testable import image_picker_ios_objc
15+
#endif
16+
1317
private let kColorRepresentation3x2BottomLeftYellow = "1 0.776471 0 1"
1418
private let kColorRepresentation3x2TopLeftRed = "1 0.0666667 0 1"
1519
private let kColorRepresentation3x2BottomRightCyan = "0 0.772549 1 1"

‎packages/image_picker/image_picker_ios/example/ios/RunnerTests/MetaDataUtilTests.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import UIKit
88

99
@testable import image_picker_ios
1010

11+
#if canImport(image_picker_ios_objc)
12+
@testable import image_picker_ios_objc
13+
#endif
14+
1115
@Suite
1216
struct MetaDataUtilTests {
1317
@Test func getImageMIMETypeFromImageData() {

‎packages/image_picker/image_picker_ios/example/ios/RunnerTests/PhotoAssetUtilTests.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import UIKit
99

1010
@testable import image_picker_ios
1111

12+
#if canImport(image_picker_ios_objc)
13+
@testable import image_picker_ios_objc
14+
#endif
15+
1216
@Suite
1317
struct PhotoAssetUtilTests {
1418
@Test func getAssetFromImagePickerInfoShouldReturnNilIfNotAvailable() {

‎packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import UIKit
88

99
@testable import image_picker_ios
1010

11+
#if canImport(image_picker_ios_objc)
12+
@testable import image_picker_ios_objc
13+
#endif
14+
1115
@Suite
1216
struct PickerSaveImageToPathOperationTests {
1317
private var testBundle: Bundle {

‎packages/image_picker/image_picker_ios/example/ios/RunnerTests/TestDoubles.swift‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import UniformTypeIdentifiers
1212

1313
@testable import image_picker_ios
1414

15+
#if canImport(image_picker_ios_objc)
16+
@testable import image_picker_ios_objc
17+
#endif
18+
1519
final class StubViewProvider: NSObject, FIPViewProvider {
1620
var viewController: UIViewController?
1721

@@ -104,12 +108,12 @@ final class FakeCameraPermissionChecker: NSObject, CameraPermissionChecking {
104108
/// not-determined → granted/denied can be tested separately.
105109
var requestAccessGranted = false
106110

107-
func authorizationStatus(forMediaType mediaType: AVMediaType) -> AVAuthorizationStatus {
111+
func authorizationStatus(for mediaType: AVMediaType) -> AVAuthorizationStatus {
108112
status
109113
}
110114

111115
func requestAccess(
112-
forMediaType mediaType: AVMediaType,
116+
for mediaType: AVMediaType,
113117
completionHandler handler: @escaping @Sendable (Bool) -> Void
114118
) {
115119
requestAccessCallCount += 1
@@ -148,10 +152,10 @@ final class FakePickerItem: NSObject, PickerItem {
148152
}
149153

150154
final class RecordingPHPickerCreator: NSObject, PHPickerCreating {
151-
private(set) var lastConfiguration: __PHPickerConfiguration?
155+
private(set) var lastConfiguration: PHPickerConfiguration?
152156
var picker = PHPickerViewController(configuration: PHPickerConfiguration())
153157

154-
func makePicker(configuration: __PHPickerConfiguration) -> PHPickerViewController {
158+
func makePicker(configuration: PHPickerConfiguration) -> PHPickerViewController {
155159
lastConfiguration = configuration
156160
return picker
157161
}

‎packages/image_picker/image_picker_ios/ios/image_picker_ios.podspec‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ Downloaded by pub (not CocoaPods).
1414
s.author = { 'Flutter Dev Team' => '[email protected]' }
1515
s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/image_picker_ios' }
1616
s.documentation_url = 'https://pub.dev/packages/image_picker_ios'
17-
s.source_files = 'image_picker_ios/Sources/image_picker_ios/**/*.{h,m}'
18-
s.public_header_files = 'image_picker_ios/Sources/image_picker_ios/**/*.h'
19-
s.module_map = 'image_picker_ios/Sources/image_picker_ios/include/ImagePickerPlugin.modulemap'
17+
s.source_files = 'image_picker_ios/Sources/image_picker_ios*/**/*.{h,m,swift}'
18+
s.public_header_files = 'image_picker_ios/Sources/image_picker_ios_objc/include/**/*.h'
19+
s.module_map = 'image_picker_ios/Sources/image_picker_ios_objc/include/ImagePickerPlugin.modulemap'
2020
s.dependency 'Flutter'
2121
s.platform = :ios, '15.0'
2222
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
23+
s.swift_version = '5.0'
24+
s.xcconfig = {
25+
'LIBRARY_SEARCH_PATHS' => '$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)/ $(SDKROOT)/usr/lib/swift',
26+
'LD_RUNPATH_SEARCH_PATHS' => '/usr/lib/swift',
27+
}
2328
s.resource_bundles = {'image_picker_ios_privacy' => ['image_picker_ios/Sources/image_picker_ios/Resources/PrivacyInfo.xcprivacy']}
2429
end

‎packages/image_picker/image_picker_ios/ios/image_picker_ios/Package.swift‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@ let package = Package(
1818
targets: [
1919
.target(
2020
name: "image_picker_ios",
21-
dependencies: [],
22-
exclude: ["include/image_picker_ios-umbrella.h", "include/ImagePickerPlugin.modulemap"],
21+
dependencies: [
22+
"image_picker_ios_objc"
23+
],
2324
resources: [
2425
.process("Resources")
25-
],
26+
]
27+
),
28+
.target(
29+
name: "image_picker_ios_objc",
30+
dependencies: [],
31+
exclude: ["include/image_picker_ios.h", "include/ImagePickerPlugin.modulemap"],
2632
cSettings: [
2733
.headerSearchPath("include/image_picker_ios")
2834
]
29-
)
35+
),
3036
]
3137
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import UIKit
6+
7+
/// Camera source and device availability checks.
8+
///
9+
/// This protocol exists to allow injecting an alternate implementation for testing.
10+
protocol CameraAvailabilityChecking {
11+
func isSourceTypeAvailable(_ sourceType: UIImagePickerController.SourceType) -> Bool
12+
func isCameraDeviceAvailable(_ cameraDevice: UIImagePickerController.CameraDevice) -> Bool
13+
}
14+
15+
/// Production implementation that forwards to UIImagePickerController.
16+
struct DefaultCameraAvailabilityChecker: CameraAvailabilityChecking {
17+
func isSourceTypeAvailable(_ sourceType: UIImagePickerController.SourceType) -> Bool {
18+
UIImagePickerController.isSourceTypeAvailable(sourceType)
19+
}
20+
21+
func isCameraDeviceAvailable(_ cameraDevice: UIImagePickerController.CameraDevice) -> Bool {
22+
UIImagePickerController.isCameraDeviceAvailable(cameraDevice)
23+
}
24+
}

0 commit comments

Comments
 (0)