@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 '@ohos.pluginComponent'
PushParameterForStage
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 | Mandatory | Description |
---|---|---|---|
owner | Want | Yes | Ability information of the component provider. |
target | Want | Yes | Ability information of the component user. |
name | string | Yes | Component name. |
data | KVObject | Yes | Component data value. |
extraData | KVObject | Yes | Additional data value. |
jsonPath | string | No | Path to the external.json file that stores the template path. |
RequestParameterForStage
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 | Mandatory | Description |
---|---|---|---|
owner | Want | Yes | Ability information of the component user. |
target | Want | Yes | Ability information of the component provider. |
name | string | Yes | Name of the requested component. |
data | KVObject | Yes | Additional data. |
jsonPath | string | No | Path to the external.json file that stores the template path. Request communication is not triggered when jsonPath is not empty or not set. |
push
push(param: PushParameterForStage, callback: AsyncCallback<void>): void
Pushes the component 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.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
param | PushParameterForStage | Yes | Information about the component user. |
callback | AsyncCallback<void> | Yes | Asynchronous callback used to return the result. |
Example
import pluginComponentManager from '@ohos.pluginComponent'
pluginComponentManager.push(
{
owner: {
bundleName: "com.example.provider",
abilityName: "com.example.provider.MainAbility"
},
target: {
bundleName: "com.example.provider",
abilityName: "com.example.provider.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.log("push_callback:err: ", JSON.stringify(err));
console.log("push_callback:data: ", JSON.stringify(data));
console.log("push_callback: push ok!");
}
)
request
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.
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 '@ohos.pluginComponent'
pluginComponentManager.request(
{
owner: {
bundleName: "com.example.provider",
abilityName: "com.example.provider.MainAbility"
},
target: {
bundleName: "com.example.provider",
abilityName: "ets/pages/plugin2.js",
},
name: "plugintemplate",
data: {
"key_1": " myapplication plugin component test",
},
jsonPath: "",
},
(err, data) => {
console.log("request_callback: componentTemplate.ability=" + data.componentTemplate.ability)
console.log("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"
}