[camera_avfoundation] Add lensType to CameraDescription#9959
[camera_avfoundation] Add lensType to CameraDescription#9959Limatationz wants to merge 3 commits intoflutter:mainfrom Limatationz:better-ca-era-description-ios
Conversation
upgrade version
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request adds the lensType to CameraDescription to allow for better camera identification on iOS. The changes span across the native Swift/Objective-C code, the Pigeon message definitions, the Dart platform implementation, and the example app. The core logic correctly maps AVCaptureDevice.DeviceType to the new lensType enum. The tests have also been updated to cover this new property.
My review has identified a few issues that need to be addressed: a build-breaking error in the Pigeon definition, a syntax error in a test file, an incorrect mock implementation, and a leftover debug print statement. After these are fixed, the PR should be in good shape.
| let unspecifiedCamera = MockCaptureDevice() | ||
| unspecifiedCamera.uniqueID = "0" | ||
| unspecifiedCamera.position = .unspecified | ||
| unspecifiedCamera.deviceType = |
There was a problem hiding this comment.
This line contains a syntax error and will cause a compilation failure. It seems like an incomplete assignment. To test the .unknown lens type mapping, you could assign a device type that is not explicitly handled in the CameraPlugin's switch statement, for example .builtInDualCamera.
| unspecifiedCamera.deviceType = | |
| unspecifiedCamera.deviceType = .builtInDualCamera |
| /// The type of the camera lense | ||
| final PlatformCameraLensType lensType; |
There was a problem hiding this comment.
The PlatformCameraDescription class is missing the new lensType field in its constructor. Since lensType is a final field, it must be initialized. Please update the constructor to PlatformCameraDescription({required this.name, required this.lensDirection, required this.lensType}); and then re-run the pigeon generator.
|
|
||
| var uniqueID = "" | ||
| var position = AVCaptureDevice.Position.unspecified | ||
| var deviceType: AVCaptureDevice.DeviceType? = nil |
There was a problem hiding this comment.
The deviceType property is declared as optional (AVCaptureDevice.DeviceType?), but the FLTCaptureDevice protocol it conforms to defines it as a non-optional property. This mismatch can lead to runtime errors. Please make it non-optional and provide a default value to align with the protocol.
| var deviceType: AVCaptureDevice.DeviceType? = nil | |
| var deviceType: AVCaptureDevice.DeviceType = .builtInWideAngleCamera |
| @unknown default: | ||
| lensFacing = .external | ||
| } | ||
| print(device.deviceType) |
|
Thanks for the contribution! You’ve checked boxes in the PR checklist above that are not reflected in this PR, so I’m assuming this is a work in progress and am marking it as a Draft. Please review the checklist, updating the PR as appropriate, and when the state of the PR as posted reflects the checklist please feel free to mark it as ready for review. |
|
Obsoleted by #7653. |
Hey,
I noticed that the existing lensType property in CameraDescription is currently not set in camera_avfoundation. But for identifying the cameras (in particular the back ones) this is essential. The name of the camera cannot to this correctly.
fixes #174982
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