Skip to content

fix(ios): guard video orientation when cameraMode is enabled (fixes #367)#369

Merged
riderx merged 1 commit into
mainfrom
fix/ios-cameramode-video-orientation
Jun 20, 2026
Merged

fix(ios): guard video orientation when cameraMode is enabled (fixes #367)#369
riderx merged 1 commit into
mainfrom
fix/ios-cameramode-video-orientation

Conversation

@riderx

@riderx riderx commented Jun 19, 2026

Copy link
Copy Markdown
Member

Summary

  • Guard all AVCaptureConnection.videoOrientation assignments with isVideoOrientationSupported to prevent iOS crashes when attaching AVCaptureMovieFileOutput during preview startup
  • Accept enableVideoMode on iOS (with backward-compatible support for legacy cameraMode) so the public TypeScript API matches native behavior

Test plan

  • bun run verify:web
  • bun run lint
  • iOS: start preview with enableVideoMode: true and confirm no crash
  • iOS: start preview with legacy cameraMode: true and confirm no crash
  • iOS: verify video recording still works after preview start

Fixes #367

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Added enableVideoMode as an alternative option for configuring camera video mode settings.
  • Bug Fixes

    • Improved video orientation handling to ensure consistent orientation application across photo captures, video recordings, and preview display.
  • Documentation

    • Updated positioning option documentation to reflect platform support for both Android and iOS.

Prevent crashes when starting preview with video mode enabled by checking
isVideoOrientationSupported before setting orientation on AVCaptureConnection.
Also accept enableVideoMode on iOS to match the public TypeScript API.

Fixes #367

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown
Contributor

Beta npm build

Maintainers can publish this PR to npm for fast testing.

Comment /publish-beta after the PR checks are green.

The workflow will:

  • publish a prerelease package on the beta tag
  • add a pinned pr-369 dist-tag for this exact PR build
  • update this comment with the install command

Security note: beta publish is only enabled for branches inside this repository.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b0e51f67-9009-4db3-8a52-c9e4acf143e7

📥 Commits

Reviewing files that changed from the base of the PR and between fc01eed and d149b67.

📒 Files selected for processing (3)
  • ios/Sources/CapgoCameraPreviewPlugin/CameraController.swift
  • ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift
  • src/definitions.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

📝 Walkthrough

Walkthrough

Introduces private setVideoOrientation helper overloads in CameraController.swift that guard isVideoOrientationSupported before assignment, replacing all direct .videoOrientation assignments across prepareOutputs, prepare, updateVideoOrientation, captureImage, and captureVideo. Plugin.swift adds enableVideoMode as a fallback alias for cameraMode. The positioning JSDoc in definitions.ts gains ios in its @platform annotation.

Changes

iOS orientation crash fix, enableVideoMode alias, and positioning docs

Layer / File(s) Summary
setVideoOrientation helper and all call sites
ios/Sources/CapgoCameraPreviewPlugin/CameraController.swift
Adds two private setVideoOrientation overloads that check isVideoOrientationSupported before assigning orientation to an AVCaptureConnection. All prior direct .videoOrientation = assignments in prepareOutputs, prepare, updateVideoOrientation, captureImage, and captureVideo are replaced with calls to these helpers.
enableVideoMode alias and positioning platform docs
ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift, src/definitions.ts
start in Plugin.swift now evaluates enableVideoMode ?? cameraMode to set cameraMode and logs enableVideoMode. The @platform annotation on CameraPreviewOptions.positioning in definitions.ts is updated from android to android, ios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Cap-go/capacitor-camera-preview#368: Overlaps at the captureVideo/fileVideoOutput code path — that PR modifies captureVideo(maxDuration:maxFileSize:) and its recording-finished handler, while this PR applies the setVideoOrientation helper inside the same captureVideo method.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly identifies the main fix (guarding video orientation) and references the specific iOS issue being addressed.
Linked Issues check ✅ Passed The PR addresses both objectives from issue #367: it guards videoOrientation assignments with isVideoOrientationSupported checks and implements enableVideoMode parameter support while maintaining cameraMode compatibility.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the iOS crash and API consistency issues documented in issue #367, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@riderx riderx merged commit 2025d59 into main Jun 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: iOS crash when starting preview with cameraMode: true

1 participant