[camera_avfoundation] Pigeon swift migration - part 2#10980
Conversation
There was a problem hiding this comment.
Code Review
This pull request completes the migration of the camera_avfoundation package to a Swift-based Pigeon interface, removing the last Objective-C-based Pigeon interfaces. The changes are extensive and primarily involve:
- Replacing Objective-C generated Pigeon files with new Swift-generated ones (
Messages.swift). - Updating the
CameraApiimplementation inCameraPlugin.swiftandDefaultCamera.swiftto use the new Swift types andResult-based completion handlers. - Removing the Objective-C Pigeon target and related source files.
- Updating all unit and integration tests to align with the new Swift API, including changes to mock objects and assertions to handle
ResultandPigeonErrortypes. - Adjusting the
podspecandPackage.swiftfiles to reflect the removal of the Objective-C target.
My feedback focuses on improving the maintainability of the updated test files by reducing code duplication.
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPermissionTests.swift
Show resolved
Hide resolved
...s/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginDelegatingMethodTests.swift
Show resolved
Hide resolved
|
@hellohuanlin pls take a look at this PR when you have some time |
|
@RobertOdrowaz Hello, this PR is 2000 LOC and all in a single commit. Could you give a tour of the change and how i can start reviewing it, if possible? |
|
I know it's over 2000 LOC, but the vast majority are trivial changes:
camera.setZoomLevel(CGFloat(1.0)) { error in
XCTAssertNotNil(error)
XCTAssertEqual(error?.code, "ZOOM_ERROR")
expectation.fulfill()
}to camera.setZoomLevel(CGFloat(1.0)) { result in
switch result {
case .failure(let error as PigeonError):
XCTAssertEqual(error.code, "ZOOM_ERROR")
default:
XCTFail("Expected failure")
}
expectation.fulfill()
}because methods now pass a
I can split 1, 2 and 3+4 into separate commits if it will help you but IMO going file by file is effectively the same. |
|
@RobertOdrowaz Thanks for the tour. Don't worry about splitting it. Taking a look now. |
hellohuanlin
left a comment
There was a problem hiding this comment.
LGTM with just a few questions
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraMethodChannelTests.swift
Outdated
Show resolved
Hide resolved
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraPermissionTests.swift
Show resolved
Hide resolved
| handler(false) | ||
| } | ||
| permissionManager.requestCameraPermission { error in | ||
| XCTAssertEqual(error, expectedError) |
There was a problem hiding this comment.
curious why are we changing this? I don't see any problem with this approach. Is it related to equatable?
There was a problem hiding this comment.
FlutterError was equatable PigeonError is not
Global function 'XCTAssertEqual(::_:file:line:)' requires that 'PigeonError' conform to 'Equatable'
There was a problem hiding this comment.
Gotcha. I think you can also write an extension of PigeonError to conform to Equatable.
I filed an issue here: flutter/flutter#182480
...s/camera/camera_avfoundation/example/ios/RunnerTests/CameraPluginDelegatingMethodTests.swift
Show resolved
Hide resolved
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.swift
Show resolved
Hide resolved
| /// @param messenger Nullable messenger for capturing each frame. | ||
| func startVideoRecording( | ||
| completion: @escaping (_ error: FlutterError?) -> Void, | ||
| completion: @escaping (Result<Void, any Error>) -> Void, |
There was a problem hiding this comment.
why is it changing from FlutterError to any Error?
There was a problem hiding this comment.
I matches the completion interface generated by pigeon. We can have Result<Void, PigeonError> in Camera but I think that due to generics invariance in Swift we would have to map the errors like this
completion: { completion($0.mapError { $0 }) } in CameraPlugin
4bd9a26 to
779860d
Compare
| completion(.success(isSupported)) | ||
| } else { | ||
| completion(nil, nil) | ||
| completion(.success(false)) |
There was a problem hiding this comment.
I'm keeping the existing behavior and not adding error handling here. I can open an issue for this
|
@hellohuanlin I've resolved the conflicts and your comments. I will wait for your approval on #10980 (comment) before merging |
|
@hellohuanlin That was the last PR for the camera migration. Thank you for the reviews throughout the whole process! |
flutter/packages@f83926f...59f905c 2026-02-18 52160996+FMorschel@users.noreply.github.com [camera][google_fonts] Fixes future warning for `await`ing `Future` returns in `async` bodies inside `try` blocks (flutter/packages#11009) 2026-02-18 robert.odrowaz@leancode.pl [camera_avfoundation] Pigeon swift migration - part 2 (flutter/packages#10980) 2026-02-17 8490712+ruicraveiro@users.noreply.github.com [camera_android_camerax] Adds support for video stabilization (flutter/packages#11020) 2026-02-17 nateshmbhat1@gmail.com [video_player] Adds audio track metadata fetching and audio track selection feature (flutter/packages#9925) 2026-02-17 stuartmorgan@google.com [video_player] Update Android to exoplayer 1.9.1 (flutter/packages#10904) 2026-02-17 joonas.kerttula@codemate.com [google_maps_flutter_android] Add advanced markers support (flutter/packages#10381) 2026-02-17 stuartmorgan@google.com [google_maps_flutter] Standardize iOS class and file names (flutter/packages#10964) 2026-02-17 stuartmorgan@google.com [google_sign_in] Simply Kotlin/Java interop utils (flutter/packages#11011) 2026-02-17 engine-flutter-autoroll@skia.org Roll Flutter from 9bda20a to 6e4a481 (103 revisions) (flutter/packages#11041) 2026-02-17 stuartmorgan@google.com [ci] Update repo for 3.41 (flutter/packages#11017) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Migrates camera package to the Swift-based pigeon interface as the last part of flutter/flutter#119109
This PR replaces the ObjC-based pigeon interfaces with Swift-based ones, thus removing the last remaining pieces of ObjC code in the package 🎉
I know there are a lot of changes in this PR, but there is no way to split it into smaller parts.
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot 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.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3