Plugin Development Workflow
With the new plugin created, you can begin implementing functionality across a variety of platforms.
Implementing a New Method
To implement new functionality in your plugin, begin by defining the method's signature in the exported TypeScript interface for your plugin in src/definitions.ts
.
In the example below, the openMap()
method is added which takes a latitude
and longitude
. It is good practice to define interfaces for method parameters that can be imported and used in apps.
export interface EchoPlugin {
echo(options: { value: string }): Promise<{ value: string }>;
+ openMap(options: OpenMapOptions): Promise<void>;
}
+export interface OpenMapOptions {
+ latitude: number;
+ longitude: number;
+}
Implement the web implementation in src/web.ts
:
import type {
EchoPlugin,
+ OpenMapOptions,
} from './definitions';
export class EchoWeb extends WebPlugin implements EchoPlugin {
// other methods
+ async openMap(location: OpenMapOptions): Promise<void> {
+ // logic here
+ }
}
To compile the plugin, navigate into the plugin directory then run:
npm run build
Implement Android functionality in android/src/main/[nested folders]/EchoPlugin.java
:
@PluginMethod()
public void openMap(PluginCall call) {
Double latitude = call.getDouble("latitude");
Double longitude = call.getDouble("longitude");
// more logic
call.resolve();
}