Skip to content

CameraView fix for iOS: orientation and video recording#3167

Merged
TheCodeTraveler merged 15 commits intoCommunityToolkit:mainfrom
zhitaop:fix/camera-update-ios
Apr 2, 2026
Merged

CameraView fix for iOS: orientation and video recording#3167
TheCodeTraveler merged 15 commits intoCommunityToolkit:mainfrom
zhitaop:fix/camera-update-ios

Conversation

@zhitaop
Copy link
Copy Markdown
Contributor

@zhitaop zhitaop commented Mar 20, 2026

Description of Change

  • This PR fixes a bug on iOS where camera preview is stopped after video recording, and attempting to capture an image would crash the app. This is done by fixing video recording clean up logic so only recording-specific resources (audioInput, videoOutput) are added and removed.

  • Simplifies video recording session management by removing the separate video input and reusing the existing capture input

  • Improves iOS camera orientation handling for both photo capture and video recording. Centralized orientation handling logic in ConfigureAVCaptureConnection():

    • Uses AVCaptureDeviceRotationCoordinator on iOS 17+
    • Falls back to CMMotionManager on iOS 16 and below

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

Copilot AI review requested due to automatic review settings March 20, 2026 09:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves iOS CameraView behavior by centralizing orientation configuration for photo/video capture and refining video recording resource management to prevent post-recording crashes.

Changes:

  • Centralizes photo/video orientation configuration via a new ConfigureAVCaptureConnection() helper (iOS 17+ rotation coordinator; iOS ≤16 accelerometer fallback).
  • Simplifies iOS video recording by reusing the existing camera input and only adding/removing recording-specific resources (audioInput, videoOutput).
  • Adds lifecycle cleanup for rotation coordinator and motion manager resources in Dispose().

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

@TheCodeTraveler
Copy link
Copy Markdown
Collaborator

Thanks @zhitaop! Could you take a second to review CoPilot's recommendations and implement the fix if you deem it appropriate?

@zhitaop
Copy link
Copy Markdown
Contributor Author

zhitaop commented Apr 2, 2026

Hi @TheCodeTraveler, I've reviewed Copilot's feedback and implement the fix accordingly.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

TheCodeTraveler
TheCodeTraveler previously approved these changes Apr 2, 2026
Copy link
Copy Markdown
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

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

Thanks @zhitaop!!

@TheCodeTraveler TheCodeTraveler merged commit 8a2ab3c into CommunityToolkit:main Apr 2, 2026
9 of 10 checks passed
matt-goldman pushed a commit to matt-goldman/Maui-1 that referenced this pull request Apr 2, 2026
…lkit#3167)

* CameraView update for iOS: orientation, video recording

* Address Copilot review

* Update mirroring handle

* Address Copilot review

* Reduce scope of `OnLoaded` and `IsInitialized`

* Use `ICommand` for `StopCameraPreviewCommand`

* Refactor `TryConfigureAVCaptureConnection`

* Update CameraManager.windows.cs

* Update CameraManager.macios.cs

* Update XML docs

* `dotnet format`

---------

Co-authored-by: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com>
@zhitaop zhitaop deleted the fix/camera-update-ios branch April 3, 2026 02:06
@github-actions github-actions bot locked and limited conversation to collaborators Apr 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

3 participants