-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[camera_avfoundation] Add lensType to CameraDescription #9959
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
base: main
Are you sure you want to change the base?
[camera_avfoundation] Add lensType to CameraDescription #9959
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.
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 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.
@@ -121,6 +127,7 @@ final class AvailableCamerasTest: XCTestCase { | |||
let unspecifiedCamera = MockCaptureDevice() | |||
unspecifiedCamera.uniqueID = "0" | |||
unspecifiedCamera.position = .unspecified | |||
unspecifiedCamera.deviceType = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -32,6 +32,7 @@ class MockCaptureDevice: NSObject, FLTCaptureDevice { | |||
|
|||
var uniqueID = "" | |||
var position = AVCaptureDevice.Position.unspecified | |||
var deviceType: AVCaptureDevice.DeviceType? = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -157,10 +157,24 @@ extension CameraPlugin: FCPCameraApi { | |||
@unknown default: | |||
lensFacing = .external | |||
} | |||
print(device.deviceType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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.yaml
with 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.md
to 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-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
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