Skip to content

[camera_avfoundation] Pigeon swift migration - part 2#10980

Merged
auto-submit[bot] merged 4 commits intoflutter:mainfrom
leancodepl:feature/camera-pigeon-swift-migration-part2
Feb 18, 2026
Merged

[camera_avfoundation] Pigeon swift migration - part 2#10980
auto-submit[bot] merged 4 commits intoflutter:mainfrom
leancodepl:feature/camera-pigeon-swift-migration-part2

Conversation

@RobertOdrowaz
Copy link
Contributor

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

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-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.

Footnotes

  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. 2 3

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CameraApi implementation in CameraPlugin.swift and DefaultCamera.swift to use the new Swift types and Result-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 Result and PigeonError types.
  • Adjusting the podspec and Package.swift files 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.

@stuartmorgan-g stuartmorgan-g added the triage-ios Should be looked at in iOS triage label Feb 10, 2026
@RobertOdrowaz
Copy link
Contributor Author

@hellohuanlin pls take a look at this PR when you have some time

@hellohuanlin
Copy link
Contributor

@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?

@RobertOdrowaz
Copy link
Contributor Author

I know it's over 2000 LOC, but the vast majority are trivial changes:

  1. ~1300 LOC is in Messages.swift which is generated by pigeon
  2. ~600 LOC in tests which is mostly very repetitive change from something like
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 Result union type instead of nullable error to the completion.

  1. ~100 LOC in CameraPlugin.swift mostly changes from nullable error to a Result in completions
  2. ~140 LOC in DefaultCamera.swift mostly changes from nullable error to a Result and PigeonError instead of FlutterError.

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.

@hellohuanlin
Copy link
Contributor

@RobertOdrowaz Thanks for the tour. Don't worry about splitting it. Taking a look now.

Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with just a few questions

handler(false)
}
permissionManager.requestCameraPermission { error in
XCTAssertEqual(error, expectedError)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why are we changing this? I don't see any problem with this approach. Is it related to equatable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlutterError was equatable PigeonError is not

Global function 'XCTAssertEqual(::_:file:line:)' requires that 'PigeonError' conform to 'Equatable'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. I think you can also write an extension of PigeonError to conform to Equatable.

I filed an issue here: flutter/flutter#182480

/// @param messenger Nullable messenger for capturing each frame.
func startVideoRecording(
completion: @escaping (_ error: FlutterError?) -> Void,
completion: @escaping (Result<Void, any Error>) -> Void,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it changing from FlutterError to any Error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@RobertOdrowaz RobertOdrowaz force-pushed the feature/camera-pigeon-swift-migration-part2 branch from 4bd9a26 to 779860d Compare February 16, 2026 18:29
completion(.success(isSupported))
} else {
completion(nil, nil)
completion(.success(false))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm keeping the existing behavior and not adding error handling here. I can open an issue for this

@RobertOdrowaz
Copy link
Contributor Author

@hellohuanlin I've resolved the conflicts and your comments. I will wait for your approval on #10980 (comment) before merging

Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RobertOdrowaz RobertOdrowaz added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 18, 2026
@auto-submit auto-submit bot merged commit 66b0cce into flutter:main Feb 18, 2026
81 checks passed
@RobertOdrowaz
Copy link
Contributor Author

@hellohuanlin That was the last PR for the camera migration. Thank you for the reviews throughout the whole process!

github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Feb 18, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-ios platform-macos triage-ios Should be looked at in iOS triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments