Skip to content

feat!: migrate to Capacitor v8#407

Merged
ryaa merged 8 commits into
capacitor-community:masterfrom
fabiomartino:cap8
Mar 25, 2026
Merged

feat!: migrate to Capacitor v8#407
ryaa merged 8 commits into
capacitor-community:masterfrom
fabiomartino:cap8

Conversation

@fabiomartino

Copy link
Copy Markdown
Contributor

This PR updates the plugin to support Capacitor v8. The migration follows the official Capacitor v8 plugin upgrade guide.

This update addresses build issues on Android and specifically fixes compilation errors on iOS introduced by the stricter Swift Package Manager (SPM) integration in Capacitor v8.

Key Changes

📱 iOS (Swift & SPM)

The transition to Capacitor v8 and its default usage of Swift Package Manager required several adjustments in CameraPreviewPlugin.swift and CameraController.swift:

  1. SPM Compatibility (reject vs resolve):
  • In the Capacitor v8 SPM toolchain, call.reject() is not reliably exposed or callable in the same way as CocoaPods.
  • Fix: Replaced calls to call.reject("message") with a state-based resolution pattern: call.resolve(["success": false, "error": "message"]). This ensures the plugin compiles and behaves consistently across toolchains.
  1. Strict Type Safety & Optionals:
  • Updated how optional values (e.g., getInt, getString) are retrieved. Capacitor v8 accessors now enforce strict non-optional returns in certain contexts.
  • Fix: Implemented safer unwrapping using call.options["key"] or provided explicit default values where appropriate to prevent runtime crashes and build errors.
  1. API Deprecations:
  • Fix: Replaced the deprecated UIApplication.shared.statusBarOrientation (iOS 13+) with modern UIWindowScene logic to correctly determine interface orientation.

📦 Dependencies (NPM)

  • Bumped @capacitor/core, @capacitor/android, and @capacitor/ios to ^8.0.0.
  • Note on installation: I noticed the package.json contains specific overrides for ESLint versions. To respect your current configuration and avoid altering the repository's architecture or linting rules, I utilized npm install --force to resolve the peer dependency graph. You may want to review the overrides section in a future maintenance update to align it with the newer TypeScript/ESLint ecosystem, but for now, I have left it as is to minimize friction.

⚠️ Important testing note

This PR has been tested locally on both Android and iOS.
However, since this plugin interacts with system-level settings and behavior can vary
between devices and OS versions, it is strongly recommended that the original maintainer
also tests these changes in their own environment before approving and releasing.
No breaking changes are introduced beyond the already required Capacitor 8 migration.

- Replace deprecated `UIApplication.shared.statusBarOrientation` with `UIWindowScene` logic.
- Replace deprecated `jpegPhotoDataRepresentation` with `fileDataRepresentation`.
- Fix logic bug in `UIImage.fixedOrientation` where transform results were unused.
- Fix various linter issues.
@fabiomartino

Copy link
Copy Markdown
Contributor Author

reopen

@fabiomartino fabiomartino reopened this Jan 15, 2026
@fabiomartino

Copy link
Copy Markdown
Contributor Author

I close it for now... until this will be solved ionic-team/capacitor-swift-pm#33

@fabiomartino

Copy link
Copy Markdown
Contributor Author

Reopen.

latest changes made:

  • Call Lifecycle Security: Guaranteed that every CAPPluginCall invokes resolve or reject exactly once across all logic branches to prevent "dangling" promises.
  • Main-Thread UI Safety: Explicitly dispatched all WebView and AVFoundation view manipulations to the main thread to ensure stability in the Xcode 26 environment.
  • Robust Error Propagation: Replaced silent print logs with explicit call.reject() using localized error descriptions for consistent JS-layer feedback.
  • SPM Alignment: Cleaned up manual method registrations, relying on Capacitor v8's native macro system for streamlined Swift Package Manager integration.

@fabiomartino fabiomartino reopened this Feb 9, 2026
@fseve

fseve commented Mar 19, 2026

Copy link
Copy Markdown

Hi, @fabiomartino @ryaa is it possible to merge this update to Capacitor v8?

@ryaa

ryaa commented Mar 20, 2026

Copy link
Copy Markdown
Member

Hi, @fabiomartino @ryaa is it possible to merge this update to Capacitor v8?

I will try to get to this the next week.

Comment thread ios/Sources/CameraPreviewPlugin/CameraPreviewPlugin.swift
Comment thread ios/Sources/CameraPreviewPlugin/CameraController.swift Outdated
Comment thread android/build.gradle

@ryaa ryaa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Blocker: example-app not upgraded

The example-app still depends on Capacitor 7 across package.json, Podfile (platform :ios, '14.0'), and variables.gradle (compileSdkVersion = 35). Since the plugin's peerDependencies now require @capacitor/core >=8.0.2 and the podspec requires iOS 15, the example-app can't install or build against the plugin. I believe that we need to upgrade the example-app deps, bump the Podfile platform to 15.0, bump variables.gradle SDK versions to 36, and run cap sync.

Minor suggestions (non-blocking):

  • The #available(iOS 13.0, *) checks in getInterfaceOrientation() and updateVideoOrientation() are always true now that the deployment target is iOS 15 — the statusBarOrientation fallback is dead code. Consider removing.
  • lintOptions in android/build.gradle is deprecated in AGP 8.x — could be renamed to lint since you already touched that block.

ryaa added 3 commits March 24, 2026 13:25
Changes:
- update the example-app @capacitor/* dependencies to Capacitor 8-compatible versions
- align the example-app iOS configuration with the plugin’s new minimum iOS requirement
- align the example-app Android configuration with the Capacitor 8 migration requirements
- refresh generated/native example-app project state as needed after the upgrade
- fix the Android example-app build issue encountered during validation by updating the Android variables/config
- ensure the repository example-app can be used for end-to-end validation of the Capacitor 8 plugin migration
Changes:
- remove unnecessary `#available(iOS 13.0, *)` checks introduced during the Capacitor 8 migration
- remove obsolete `UIApplication.shared.statusBarOrientation` fallback branches
- use `connectedScenes` / `UIWindowScene` orientation lookup unconditionally for the iOS 15+ target
- keep behavior unchanged while simplifying the iOS orientation helpers
Changes:
- replace deprecated `lintOptions {}` with `lint {}` in the plugin Android Gradle file
@ryaa

ryaa commented Mar 24, 2026

Copy link
Copy Markdown
Member

@fabiomartino I went ahead and resolved all of my review findings on this PR.

This included:

  • upgrading the example-app so it is aligned with the Capacitor 8 plugin migration
  • cleaning up the dead iOS #available(iOS 13.0, *) fallback branches now that the minimum iOS version is 15
  • updating the Android Gradle lint block from deprecated lintOptions {} to lint {}

From my side, the review items I raised have now been addressed.

Can you please review and confirm that this PR can be merged? (we can also plan to release a new build with the capacitor 8 support after that).

@fabiomartino

Copy link
Copy Markdown
Contributor Author

Hi @ryaa, sounds good!

Just a quick note: we could further update some dependencies (like Capacitor to the current v8.2.0), but it’s not strictly necessary for this PR and can be handled later.

Currently, I don’t have the time to make further changes myself, so feel free to proceed with the merge if the current state looks good to you. If any minor tweaks are needed, you’re welcome to push them or I can look into them after the second week of April.

@ryaa ryaa merged commit c877df5 into capacitor-community:master Mar 25, 2026
2 checks passed
@ryaa

ryaa commented Mar 25, 2026

Copy link
Copy Markdown
Member

@fabiomartino I have merged the changes into master. The next step will be to publish a new build with Capacitor 8 support. I’ll try to do that as soon as possible, unless there are any objections.

@fseve

fseve commented Mar 26, 2026

Copy link
Copy Markdown

Thank you @ryaa @fabiomartino

Your support is appreciated.

@ryaa

ryaa commented Mar 27, 2026

Copy link
Copy Markdown
Member

v8.0.0 has now been released with Capacitor 8 support.

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.

3 participants