Capacitor Native Decorator banner
aparajita aparajita

Capacitor Native Decorator

Development community

Description

@native decorator for Capacitor that revolutionizes the way we write and call plugins

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

capacitor-native-decorator  [![npm version](https://badge.fury.io/js/@aparajita%2Fcapacitor-native-decorator.svg)](https://badge.fury.io/js/@aparajita%2Fcapacitor-native-decorator)

❗️This package is now deprecated. Please read below if you are using Capacitor 4.

After spending many hours tracing through and reading through the Capacitor 4 source code and doing some experimentation with different coding conventions, I have come to the conclusion that this package is no longer needed.

Issues this package was originally designed to solve

This package was originally created to solve several issues:

  1. The need to manually maintain the Plugin.m file for iOS.
  2. The inability to use non-native methods in a class on native platforms.
  3. The necessity to unwrap single return values from an object.

#1 was a convenient side-effect of solving #2 and #3. In reality, it isn’t that important, as the API for a plugin doesn’t change that much.

#2 is no longer a problem with Capacitor 4. You can call any method on a plugin object, even if it’s not native.

#3 is easily solved by using object deconstruction.

Issues created by this package

There are three issues this package created:

  1. It was relying on private API within Capacitor that could change in the future, thus preventing users of this package from upgrading to the latest version of Capacitor.
  2. It was circumventing the Capacitor plugin method calling mechanism entirely, which eventually could lead to unexpected behavior in future versions of Capacitor.
  3. It did not support lazy loading of plugins, which is now the recommended way.

Using standard Capacitor mechanisms instead of this package solves all of these issues.

**Note:** When plugins are lazy loaded, **all** of the methods in the plugin class must be async and return a Promise.

The remaining Capacitor issue

There is one problem with Capacitor 4 that needs to be solved if you want to get the mo