Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.10.1+1

* Fixes Swift 6 Sendability warning in `CaptureDevice` protocol by annotating
the `setExposureTargetBias` completion handler as `@Sendable`.

## 0.10.1

* Fixes fatal crash on iPhone 17 when using `ResolutionPreset.max`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ final class CameraExposureTests: XCTestCase {
XCTAssertTrue(setExposureTargetBiasCalled)
}

func testSetExposureTargetBias_completionHandlerIsInvoked() {
// Regression test: the completion handler must be @Sendable to match
// AVCaptureDevice's signature (Swift 6 requirement).
// MockCaptureDevice conforms to CaptureDevice, so a compilation failure
// here means the protocol and mock have diverged.
let (_, mockDevice, _) = createCamera()

let expectation = expectation(description: "completion handler invoked")

mockDevice.setExposureTargetBiasStub = { _, handler in
handler?(CMTime(value: 1, timescale: 1))
}

mockDevice.setExposureTargetBias(1.0) { _ in
expectation.fulfill()
}

waitForExpectations(timeout: 1.0)
}

func testMaximumExposureOffset_returnsDeviceMaxExposureTargetBias() {
let (camera, mockDevice, _) = createCamera()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MockCaptureDevice: NSObject, CaptureDevice {
var setFocusPointOfInterestStub: ((CGPoint) -> Void)?
var setExposureModeStub: ((AVCaptureDevice.ExposureMode) -> Void)?
var setExposurePointOfInterestStub: ((CGPoint) -> Void)?
var setExposureTargetBiasStub: ((Float, ((CMTime) -> Void)?) -> Void)?
var setExposureTargetBiasStub: ((Float, (@Sendable (CMTime) -> Void)?) -> Void)?
var isExposureModeSupportedStub: ((AVCaptureDevice.ExposureMode) -> Bool)?
var setVideoZoomFactorStub: ((CGFloat) -> Void)?
var lockForConfigurationStub: (() throws -> Void)?
Expand Down Expand Up @@ -99,7 +99,7 @@ class MockCaptureDevice: NSObject, CaptureDevice {
set { setExposurePointOfInterestStub?(newValue) }
}

func setExposureTargetBias(_ bias: Float, completionHandler handler: ((CMTime) -> Void)? = nil) {
func setExposureTargetBias(_ bias: Float, completionHandler handler: (@Sendable (CMTime) -> Void)? = nil) {
setExposureTargetBiasStub?(bias, handler)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protocol CaptureDevice: NSObjectProtocol {
var minExposureTargetBias: Float { get }
var maxExposureTargetBias: Float { get }
func setExposureTargetBias(
_ bias: Float, completionHandler handler: ((CMTime) -> Void)?)
_ bias: Float, completionHandler handler: (@Sendable (CMTime) -> Void)?)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

This change to the protocol requirement will cause a compilation error in MockCaptureDevice.swift (and any other implementations of this protocol) because the method signature must match the protocol requirement exactly, including the @Sendable attribute. The PR description's claim that mocks are not affected is incorrect; they must be updated to include @Sendable in both the method signature and the setExposureTargetBiasStub property type to maintain protocol conformance.

func isExposureModeSupported(_ mode: AVCaptureDevice.ExposureMode) -> Bool

// Zoom
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_avfoundation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_avfoundation
description: iOS implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.10.1
version: 0.10.1+1

environment:
sdk: ^3.9.0
Expand Down