Skip to content

[camera_avfoundation] Implementation swift migration - part 8 #9635

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

Conversation

RobertOdrowaz
Copy link
Contributor

Migrates camera implementation as part of flutter/flutter#119109

This PR migrates the 5th chunk of FLTCam class to Swift:

  • setVideoFormat
  • stopVideoRecording
  • stopImageStream
  • stopping accelerometer updates (deinit)
  • setDescriptionWhileRecording
  • createConnection (adds Swift implementation, FLTCam still depends on private non-static implementation)

NOTE: setDescriptionWhileRecording is migrated close to verbatim, the issue affecting it remains.

Some properties of the FLTCam have to be temporarily made public so that they are accessible in DefaultCamera.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

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

@RobertOdrowaz RobertOdrowaz marked this pull request as ready for review July 16, 2025 17:23
@RobertOdrowaz RobertOdrowaz marked this pull request as draft July 16, 2025 17:35
@RobertOdrowaz RobertOdrowaz force-pushed the feature/camera-implementation-swift-migration-part8 branch from a49cb5f to 2881a7a Compare July 16, 2025 17:39
@RobertOdrowaz RobertOdrowaz marked this pull request as ready for review July 16, 2025 17:39
@stuartmorgan-g
Copy link
Contributor

We're trialing Gemini Code Assist for GitHub in this repo, and I'm going to run it here since this is an interesting category of PR that we don't have many examples of. We may well choose to ignore some of its feedback since the goal is not to change behavior, but I'm curious to see how it handles a Swift migration PR.

@stuartmorgan-g
Copy link
Contributor

/gemini review

Copy link

Hello stuartmorgan-g,

Thank you for initiating this review and for providing the context of this being part of a larger Swift migration effort. I've thoroughly reviewed the changes in this pull request, focusing on correctness, maintainability, and adherence to the migration goals.

Overall, the changes look solid and are a clear step forward in the Swift migration. The logic has been successfully translated from Objective-C to Swift, maintaining the existing functionality and introducing a more Swifty approach where appropriate.

Here's a summary of my findings:

  • CHANGELOG.md and pubspec.yaml: The version bump and changelog entries accurately reflect the changes in this PR.
  • DefaultCamera.swift: The migration of setVideoFormat, stopVideoRecording, stopImageStream, setDescriptionWhileRecording, and the addition of createConnection are well-executed. The didSet for videoFormat and the deinit for motionManager demonstrate good Swift practices for property observation and resource management. The new createConnection static helper function improves modularity and reusability within the Swift implementation.
  • FLTCam.m and FLTCam.h: The corresponding Objective-C code has been correctly refactored by removing the migrated methods and properties. The changes to property attributes (e.g., captureDevice from readonly to strong) in FLTCam.h are necessary to support the Swift subclass's management of these properties, aligning with the migration strategy.

Minor Suggestion:

  • Consistency in createConnection's videoFormat usage: In DefaultCamera.swift, within the createConnection static function (lines 74-75 in the RIGHT side of DIFF 2), the videoFormat is cast as Any when setting captureVideoOutput.videoSettings. For consistency with how videoFormat is handled in its didSet (lines 15-17 in DIFF 1 of the same file), and for clearer type representation in Objective-C interop, consider using NSNumber(value: videoFormat) instead of videoFormat as Any.

    // packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift
    // Line 74
    captureVideoOutput.videoSettings = [
      kCVPixelBufferPixelFormatTypeKey as String: NSNumber(value: videoFormat)
    ]

    Severity: low - This is a minor stylistic and consistency improvement, not impacting correctness.

Overall, this is a well-structured and correct migration step. Great work, RobertOdrowaz!

Let me know if you have any questions or would like me to elaborate on any points.

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 migrates several methods from Objective-C to Swift, including setVideoFormat, stopVideoRecording, stopImageStream, stopping accelerometer updates, setDescriptionWhileRecording, and createConnection. The changes involve updating the DefaultCamera class and modifying the FLTCam class. The migration appears to be well-structured, with the use of temporary public properties to facilitate access during the transition. The code includes appropriate error handling and checks for various conditions, such as recording status and device capabilities. The changes also include updates to the CHANGELOG.md file to reflect the migrated methods.

@stuartmorgan-g
Copy link
Contributor

Hm, that was much worse than the first Java change we tried it on. It'll be interesting to see if poor-quality suggestions for Swift is a pattern.

@RobertOdrowaz RobertOdrowaz added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 18, 2025
@auto-submit auto-submit bot merged commit ec0ff4d into flutter:main Jul 18, 2025
78 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants