@ohos.pluginComponent (PluginComponentManager) (System API)
The PluginComponentManager module provides APIs for the PluginComponent user to request components and data and send component templates and data. For details about how to display the PluginComponent template, see PluginComponent.
NOTE
The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
This topic describes only system APIs provided by the module. For details about its public APIs, see @ohos.pluginComponent (PluginComponentManager).
Modules to Import
import { pluginComponentManager } from '@kit.ArkUI';
PushParameterForStage9+
Sets the parameters to be passed in the PluginManager.Push API in the stage model.
Model restriction: This API can be used only in the stage model.
System API: This is a system API.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| owner | Want | No | No | Ability information of the component provider. |
| target | Want | No | No | Ability information of the component user. |
| name | string | No | No | Component name. |
| data | KVObject | No | No | Component data. |
| extraData | KVObject | No | No | Additional data. |
| jsonPath | string | No | Yes | Path to the external.json file that stores the template path. |
RequestParameterForStage9+
Sets the parameters to be passed in the PluginManager.Request API in the stage model.
System API: This is a system API.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| owner | Want | No | No | Ability information of the component user. |
| target | Want | No | No | Ability information of the component provider. |
| name | string | No | No | Name of the requested component. |
| data | KVObject | No | No | Additional data. |
| jsonPath | string | No | Yes | Path to the external.json file that stores the template path. If the jsonPath field is not empty, the Request communication is not triggered. |
push9+
push(param: PushParameterForStage, callback: AsyncCallback<void>): void
Pushes components and data to the component user.
System API: This is a system API.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| param | PushParameterForStage | Yes | Parameters to be sent by the component provider. |
| callback | AsyncCallback<void> | Yes | Asynchronous callback used to return the result. |
Example
import { pluginComponentManager } from '@kit.ArkUI';
pluginComponentManager.push(
{
owner: {
bundleName: "com.example.provider",
abilityName: "com.example.provider.MainAbility",
},
target: {
bundleName: "com.example.user",
abilityName: "com.example.user.MainAbility",
},
name: "ets/pages/plugin2.js",
data: {
"js": "ets/pages/plugin.js",
"key_1": 1111,
},
extraData: {
"extra_str": "this is push event"
},
jsonPath: "",
},
(err, data) => {
console.info("push_callback:err: ", JSON.stringify(err));
console.info("push_callback:data: ", JSON.stringify(data));
console.info("push_callback: push ok!");
}
)
request9+
request(param: RequestParameterForStage, callback: AsyncCallback<RequestCallbackParameters>): void
Requests the component from the component provider.
System API: This is a system API.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.ArkUI.ArkUI.Full
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| param | RequestParameterForStage | Yes | Information about the component request. |
| callback | AsyncCallback<RequestCallbackParameters | void> | Yes | Asynchronous callback used to return the requested data. |
Example
import { pluginComponentManager } from '@kit.ArkUI';
pluginComponentManager.request(
{
owner: {
bundleName: "com.example.user",
abilityName: "com.example.user.MainAbility",
},
target: {
bundleName: "com.example.provider",
abilityName: "com.example.provider.MainAbility",
},
name: "plugintemplate",
data: {
"key_1": " myapplication plugin component test",
},
jsonPath: "",
},
(err, data) => {
console.info("request_callback: componentTemplate.ability=" + data.componentTemplate.ability);
console.info("request_callback: componentTemplate.source=" + data.componentTemplate.source);
}
)
About the external.json File
The external.json file is created by developers. It stores component names and template paths in key-value pairs. The component name is used as the keyword, and the corresponding template path is used as the value.
Example
{
"PluginProviderExample": "ets/pages/PluginProviderExample.js",
"plugintemplate2": "ets/pages/plugintemplate2.js"
}