未验证 提交 6a8f1535 编写于 作者: O openharmony_ci 提交者: Gitee

!14171 ArkUi Plugin相关接口整改changelog

Merge pull request !14171 from wangchensu/0130
......@@ -157,6 +157,7 @@
- [@ohos.curves (插值计算)](js-apis-curve.md)
- [@ohos.matrix4 (矩阵变换)](js-apis-matrix4.md)
- [@ohos.mediaquery (媒体查询)](js-apis-mediaquery.md)
- [@ohos.pluginComponent(PluginComponentManager)](js-apis-plugincomponent.md)
- [@ohos.promptAction (弹窗)](js-apis-promptAction.md)
- [@ohos.router (页面路由)](js-apis-router.md)
......
# @ohos.pluginComponent (PluginComponentManager)
用于给插件组件的使用者请求组件与数据,使用者发送组件模板和数据。如需实现插件模板的显示,请参考[PluginComponent](../arkui-ts/ts-basic-components-plugincomponent.md)
> **说明:**
>
> - 本模块首批接口从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 导入模块
```js
import pluginComponentManager from '@ohos.pluginComponent'
```
## PluginComponentTemplate
Plugin组件模板参数。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
| 参数 | 类型 | 必填 | 描述 |
| ---------- | ------ | ---- | --------------------------- |
| source | string | 是 | 组件模板名。 |
| bundleName | string | 是 | 提供者Ability的bundleName。 |
## PluginComponentManager
### KVObject
以键值对形式存储信息,符合json格式。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
| 取值范围 | 说明 |
| --------------------- | ---------------------------------------- |
| [key: string] | 关键字,数据类型为字符串,可取空字符串。 |
| number | 键值,表示值类型为数字。 |
| string | 键值,表示值类型为字符串,可取空字符串。 |
| boolean | 键值,表示值类型为布尔值。 |
| [] | 键值,可取值为[]。 |
| [KVObject](#kvobject) | 键值,表示值类型为KVObject。 |
### PushParameters
用于设置FA模型下使用PluginManager.Push方法时候的需要传递的参数。
**模型约束:** 此接口仅适用于FA模型。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------------------- | ---- | -------------------------------------------------------------- |
| want | [Want](js-apis-application-want.md) | 是 | 组件使用者Ability信息。 |
| name | string | 是 | 组件名称。 |
| data | [KVObject](#kvobject) | 否 | 组件数据值。 |
| extraData | [KVObject](#kvobject) | 否 | 附加数据值。 |
| jsonPath | string | 否 | 存放模板路径的[external.json](#externaljson文件说明)件的路径。 |
### PushParameterForStage
用于设置Stage模型下使用PluginManager.Push方法时候的需要传递的参数。
**模型约束:** 此接口仅适用于Stage模型。
**系统接口:** 此接口为系统接口。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------------------- | ---- | ---------------------------------------------------------------- |
| owner | [Want](js-apis-application-want.md) | 是 | 组件提供方Ability信息。 |
| target | [Want](js-apis-application-want.md) | 是 | 组件使用者Ability信息。 |
| name | string | 是 | 组件名称。 |
| data | [KVObject](#kvobject) | 否 | 组件数据值。 |
| extraData | [KVObject](#kvobject) | 否 | 附加数据值。 |
| jsonPath | string | 否 | 存放模板路径的[external.json](#externaljson文件说明)文件的路径。 |
### RequestParameters
用于设置FA模型下使用PluginManager.Request方法时候的需要传递的参数。
**模型约束:** 此接口仅适用于FA模型。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------- | ---- | --------------------------------------------------------------------------------------------------------------------- |
| want | [Want](js-apis-application-want.md) | 是 | 组件提供者Ability信息。 |
| name | string | 是 | 请求组件名称。 |
| data | [KVObject](#kvobject) | 是 | 附加数据。 |
| jsonPath | string | 否 | 存放模板路径的[external.json](#externaljson文件说明)文件的路径。jsonPath字段不为空或者未设置的时候不触发Request通信。 |
### RequestParameterForStage
用于设置Stage模型下使用PluginManager.Request方法时候的需要传递的参数。
**系统接口:** 此接口为系统接口。
**模型约束:** 此接口仅适用于Stage模型。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------- | ---- | --------------------------------------------------------------------------------------------------------------------- |
| owner | [Want](js-apis-application-want.md) | 是 | 组件使用者Ability信息。 |
| target | [Want](js-apis-application-want.md) | 是 | 组件提供者Ability信息。 |
| name | string | 是 | 请求组件名称。 |
| data | [KVObject](#kvobject) | 是 | 附加数据。 |
| jsonPath | string | 否 | 存放模板路径的[external.json](#externaljson文件说明)文件的路径。jsonPath字段不为空或者未设置的时候不触发Request通信。 |
### RequestCallbackParameters
PluginManager.Request方法时候接收到的回调结果。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
| 名称 | 类型 | 必填 | 说明 |
| ----------------- | ---------------------------------------------------- | ---- | ---------- |
| componentTemplate | [PluginComponentTemplate](#plugincomponenttemplate)] | 是 | 组件模板。 |
| data | [KVObject](#kvobject) | 是 | 组件数据。 |
| extraData | [KVObject](#kvobject) | 是 | 附加数据。 |
### RequestEventResult
注册Request监听方法后,接受到的请求事件时候回应请求的数据类型。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
| 名称 | 类型 | 必填 | 说明 |
| --------- | --------------------- | ---- | ---------- |
| template | string | 否 | 组件模板。 |
| data | [KVObject](#kvobject) | 否 | 组件数据。 |
| extraData | [KVObject](#kvobject) | 否 | 附加数据。 |
### OnPushEventCallback
OnPushEventCallback = (source: Want, template: PluginComponentTemplate, data: KVObject,
extraData: KVObject) => void
对应Push事件的监听回调函数。
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| --------- | --------------------------------------------------- | ---- | ---------------------------------------- |
| source | [Want](js-apis-application-want.md) | 是 | Push请求发送方相关信息。 |
| template | [PluginComponentTemplate](#plugincomponenttemplate) | 是 | Push请求发送方相关信息请求组件模板名称。 |
| data | [KVObject](#kvobject) | 是 | 数据。 |
| extraData | [KVObject](#kvobject) | 是 | 附加数据。 |
**示例:**
```js
function onPushListener(source, template, data, extraData) {
console.log("onPushListener template.source=" + template.source)
console.log("onPushListener source=" + JSON.stringify(source))
console.log("onPushListener template=" + JSON.stringify(template))
console.log("onPushListener data=" + JSON.stringify(data))
console.log("onPushListener extraData=" + JSON.stringify(extraData))
}
```
### OnRequestEventCallback
OnRequestEventCallback = (source: Want, name: string, data: KVObject) => RequestEventResult
对应request事件的监听回调函数。
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| --------- | ----------------------------------- | ---- | --------------------------- |
| source | [Want](js-apis-application-want.md) | 是 | request请求发送方相关信息。 |
| data | [KVObject](#kvobject) | 是 | 数据。 |
| extraData | [KVObject](#kvobject) | 是 | 附加数据。 |
**示例:**
```js
function onRequestListener(source, name, data)
{
console.error("onRequestListener");
console.log("onRequestListener source=" + JSON.stringify(source));
console.log("onRequestListener name=" + name);
console.log("onRequestListener data=" + JSON.stringify(data));
return {template:"ets/pages/plugin.js", data:data};
}
```
### push
push(param: PushParameters , callback: AsyncCallback<void>): void
组件提供者向组件使用者主动发送组件与数据。
**模型约束:** 此接口仅适用于FA模型。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------- | ---- | ------------------------ |
| param | [PushParameters](#pushparameters) | 是 | 组件使用者的详细信息。 |
| callback | AsyncCallback<void> | 是 | 此次接口调用的异步回调。 |
**示例:**
```js
pluginComponentManager.push(
{
want: {
bundleName: "com.example.provider",
abilityName: "com.example.provider.MainAbility",
},
name: "plugintemplate",
data: {
"key_1": "plugin component test",
"key_2": 34234
},
extraData: {
"extra_str": "this is push event"
},
jsonPath: "",
},
(err, data) => {
console.log("push_callback: push ok!");
}
)
```
### push
push(param: PushParameterForStage, callback: AsyncCallback<void>): void
组件提供者向组件使用者主动发送组件与数据。
**系统接口:** 此接口为系统接口。
**模型约束:** 此接口仅适用于Stage模型。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ------------------------ |
| param | [PushParameterForStage](#pushparameterforstage) | 是 | 组件使用者的详细信息。 |
| callback | AsyncCallback<void> | 是 | 此次接口调用的异步回调。 |
**示例:**
```js
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: RequestParameters, callback: AsyncCallback<RequestCallbackParameters>): void
组件使用者向组件提供者主动请求组件。
**模型约束:** 此接口仅适用于FA模型。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------------------------------------------------- | ---- | ---------------------------------------------------------------- |
| param | [RequestParameters](#requestparameters) | 是 | 组件模板的详细请求信息。 |
| callback | AsyncCallback<[RequestCallbackParameters](#requestcallbackparameters) \| void> | 是 | 此次请求的异步回调, 通过回调接口的参数返回接受请求的数据。 |
**示例:**
```js
pluginComponentManager.request(
{
want: {
bundleName: "com.example.provider",
abilityName: "com.example.provider.MainAbility",
},
name: "plugintemplate",
data: {
"key_1": "plugin component test",
"key_2": 1111111
},
jsonPath: "",
},
(err, data) => {
console.log("request_callback: componentTemplate.ability=" + data.componentTemplate.ability)
console.log("request_callback: componentTemplate.source=" + data.componentTemplate.source)
console.log("request_callback: data=" + JSON.stringify(data.data))
console.log("request_callback: extraData=" + JSON.stringify(data.extraData))
}
)
```
### request
request(param: RequestParameterForStage, callback: AsyncCallback<RequestCallbackParameters>): void
组件使用者向组件提供者主动请求组件。
**系统接口:** 此接口为系统接口。
**模型约束:** 此接口仅适用于Stage模型。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------------------------------------------------------- | ---- | ---------------------------------------------------------------- |
| param | [RequestParameterForStage](#requestparameterforstage) | 是 | 组件模板的详细请求信息。 |
| callback | AsyncCallback<[RequestCallbackParameters](#requestcallbackparameters) \| void> | 是 | 此次请求的异步回调, 通过回调接口的参数返回接受请求的数据。 |
**示例:**
```js
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)
}
)
```
### on
on(eventType: string, callback: OnPushEventCallback | OnRequestEventCallback ): void
提供者监听"request"类型的事件,给使用者返回通过request接口主动请求的数据;使用者监听"push"类型的事件,接收提供者通过push接口主动推送的数据。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------------------------------------------------------------------------- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| eventType | string | 是 | 监听的事件类型,&nbsp;可选值为:"push"&nbsp;、"request"。<br/>"push”:指组件提供者向使用者主动推送数据。<br/>"request”:指组件使用者向提供者主动请求数据。 |
| callback | [OnPushEventCallback](#onpusheventcallback)&nbsp;\|&nbsp;[OnRequestEventCallback](#onrequesteventcallback) | 是 | 对应监听回调,push事件对应回调类型为[OnPushEventCallback](#onpusheventcallback),request事件对应回调类型为[OnRequestEventCallback](#onrequesteventcallback) 。 |
**示例:**
```js
pluginComponentManager.on("push", onPushListener)
pluginComponentManager.on("request", onRequestListener)
```
## external.json文件说明
external.json文件由开发者创建。external.json中以键值对形式存放组件名称以及对应模板路径。以组件名称name作为关键字,对应模板路径作为值。
**示例**
```json
{
"PluginProviderExample": "ets/pages/PluginProviderExample.js",
"plugintemplate2": "ets/pages/plugintemplate2.js"
}
# PluginComponent
提供外部应用组件嵌入式显示功能,即外部应用提供的UI可在本应用内显示。
提供外部应用组件嵌入式显示功能,即外部应用提供的UI可在本应用内显示。如需通过跨进程通信实现更新,请参考[@ohos.pluginComponent](../apis/js-apis-plugincomponent.md)
> **说明:**
>
> - 该组件从API Version 9开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
>
> - 本组件为系统接口。
## 子组件
......@@ -23,155 +20,30 @@ PluginComponent(value: { template: PluginComponentTemplate, data: KVObject})
**参数:**
| 参数名 | 参数类型 | 必填 | 参数描述 |
| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| value | {<br/>template:&nbsp;PluginComponentTemplate,<br/>data:&nbsp;KVObject<br/>} | 是 | template:&nbsp;&nbsp;组件模板,用于跟提供者定义的组件绑定。<br/>data:&nbsp;传给插件组件提供者使用的数据。 |
| 参数名 | 参数类型 | 必填 | 参数描述 |
| ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------------- |
| value | {<br/>template:&nbsp; [PluginComponentTemplate](#plugincomponenttemplate类型说明),<br/>data:&nbsp;[KVObject](../apis/js-apis-plugincomponent.md#kvobject)<br/>} | 是 | template:&nbsp;&nbsp;组件模板,用于跟提供者定义的组件绑定。<br/>data:&nbsp;传给插件组件提供者使用的数据。 |
## PluginComponentTemplate类型说明
| 参数 | 类型 | 描述 |
| ------- | ------ | ----------------------- |
| source | string | 组件模板名。 |
| ability | string | 提供者Ability的abilityname。 |
| 参数 | 类型 | 描述 |
| ---------- | ------ | --------------------------- |
| source | string | 组件模板名。 |
| bundleName | string | 提供者Ability的bundleName。 |
## 事件
| 名称 | 功能描述 |
| ---------------------------------------- | ---------------------------------------- |
| onComplete(callback:&nbsp;()&nbsp;=&gt;&nbsp;void) | 组件加载完成回调。 |
| 名称 | 功能描述 |
| ------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| onComplete(callback:&nbsp;()&nbsp;=&gt;&nbsp;void) | 组件加载完成回调。 |
| onError(callback:&nbsp;(info:&nbsp;{&nbsp;errcode:&nbsp;number,&nbsp;msg:&nbsp;string&nbsp;})&nbsp;=&gt;&nbsp;void) | 组件加载错误回调。<br/>errcode:&nbsp;错误码。<br/>msg:&nbsp;错误信息。 |
## PluginComponentManager
提供配套插件组件使用的相关接口,用于给插件组件的使用者请求组件与数据,使用者发送组件模板和数据。
## 导入模块
```
import pluginComponentManager from '@ohos.plugincomponent'
```
## push
push(param: PushParameters, callback: AsyncCallback&lt;void&gt;): void
组件提供者向组件使用者主动发送组件与数据。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | -------------------------------- |
| param | PushParameters | 是 | 组件使用者的详细信息,详见PushParameters参数说明。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 此次接口调用的异步回调。 |
**PushParameters参数说明**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | -------- | ---- | --------------- |
| want | Want | 是 | 组件使用者Ability信息。 |
| name | string | 是 | 组件名称。 |
| data | KVObject | 否 | 组件数据值。 |
| extraData | KVObject | 否 | 附加数据值。 |
| jsonPath | string | 否 | 存放模板路径的external.json文件的路径。 |
**示例**
[Plugin组件提供方](#组件提供方)示例。
## request
request(param: RequestParameters, callback: AsyncCallback&lt;RequestCallbackParameters&gt;): void
组件使用者向组件提供者主动请求组件。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| param | RequestParameters | 是 | 组件模板的详细请求信息,详见RequestParameters参数说明。 |
| callback | AsyncCallback<RequestCallbackParameters&nbsp;\|&nbsp;void&gt; | 是 | 此次请求的异步回调,&nbsp;通过回调接口的参数返回接受请求的数据。 |
**RequestParameters参数说明**
| 参数名 | 类型 | 必填 | 说明 |
| ---- | -------- | ---- | --------------- |
| want | Want | 是 | 组件提供者Ability信息。 |
| name | string | 是 | 请求组件名称。 |
| data | KVObject | 是 | 附加数据。 |
| jsonPath | string | 否 | 存放模板路径的external.json文件的路径。jsonPath字段不为空或者未设置的时候不触发Request通信。 |
**RequestCallbackParameters说明**
| 名称 | 类型 | 说明 |
| ----------------- | ----------------------- | ----- |
| componentTemplate | PluginComponentTemplate | 组件模板。 |
| data | KVObject | 组件数据。 |
| extraData | KVObject | 附加数据。 |
**示例**
[Plugin组件使用方](#组件使用方)示例。
## on
on(eventType: string, callback: OnPushEventCallback | OnRequestEventCallback): void
提供者监听"request"类型的事件,给使用者返回通过request接口主动请求的数据;使用者监听"push"类型的事件,接收提供者通过push接口主动推送的数据。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | ---------------------------------------- |
| eventType | string | 是 | 监听的事件类型,&nbsp;可选值为:"push"&nbsp;、"request"。<br/>"push”:指组件提供者向使用者主动推送数据。<br/>"request”:指组件使用者向提供者主动请求数据。 |
| callback | OnPushEventCallback&nbsp;\|&nbsp;OnRequestEventCallback | 是 | 见callback事件说明。 |
**callback事件说明**
| 参数名 | 类型 | 说明 |
| ---------------------- | ---------------------------------------- | ---------------------------------------- |
| OnRequestEventCallback | (source:&nbsp;Want,<br/>name:&nbsp;string,<br/>data:&nbsp;KVObject&nbsp;)&nbsp;=>RequestEventResult | 数据请求事件的回调。<br/>source:&nbsp;组件请求方Ability信息。<br/>name:&nbsp;请求组件名称。<br/>data:&nbsp;附加数据。<br/>返回值:&nbsp;请求数据结果。 |
| OnPushEventCallback | (source:&nbsp;Want,<br/>template:&nbsp;PluginComponentTemplate,<br/>data:&nbsp;KVObject,<br/>extraData:&nbsp;KVObject<br/>)&nbsp;=&gt;&nbsp;void | 接收提供者主动推送的数据。<br/>source:&nbsp;组件提供者Ability信息。<br/>template:&nbsp;组件模板。<br/>data:&nbsp;组件更新数据。<br/>extraData:&nbsp;附加数据。 |
**RequestEventResult类型说明**
| 参数 | 类型 | 说明 |
| --------- | -------- | ---------- |
| template | string | 组件名称。 |
| data | KVObject | 组件数据。 |
| extraData | KVObject | 附加数据。 |
**示例**
[Plugin组件工具](#plugin组件工具)示例。
**KVObject类型说明**
| 参数 | 类型 | 说明 |
| ---- | ---------------------------------------- | ---------------------------------------- |
| key | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;boolean&nbsp;\|&nbsp;Array&nbsp;\|&nbsp;KVObject | KVObject用[key,value]来存储数据,key是string类型的,value可以是number,string,boolean,数组或者另外的一个KVObject。 |
**external.json文件说明**
external.json文件由开发者创建。external.json中以键值对形式存放组件名称以及对应模板路径。以组件名称name作为关键字,对应模板路径作为值。
**示例**
[external.json](#externaljson)示例。
## 示例
### 组件使用方
```ts
//PluginUserExample.ets
import plugin from "plugin_component.js"
......@@ -180,9 +52,9 @@ import plugin from "plugin_component.js"
@Component
struct PluginUserExample {
@StorageLink("plugincount") plugincount: Object[] = [
{ source: 'plugincomponent1', ability: 'com.example.plugin' },
{ source: 'plugintemplate', ability: 'com.example.myapplication' },
{ source: 'plugintemplate', ability: 'com.example.myapplication' }]
{ source: 'plugincomponent1', bundleName: 'com.example.plugin' },
{ source: 'plugintemplate', bundleName: 'com.example.myapplication' },
{ source: 'plugintemplate', bundleName: 'com.example.myapplication' }]
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
......@@ -209,7 +81,7 @@ struct PluginUserExample {
})
ForEach(this.plugincount, item => {
PluginComponent({
template: { source: 'plugincomponent1', ability: 'com.example.plugin' },
template: { source: 'PluginProviderExample', bundleName: 'com.example.plugin' },
data: { 'countDownStartValue': 'new countDownStartValue' }
}).size({ width: 500, height: 100 })
.onComplete(() => {
......@@ -270,7 +142,7 @@ struct PluginProviderExample {
### Plugin组件工具
#### FA模型
```js
//plugin_component.js
import pluginComponentManager from '@ohos.pluginComponent'
......@@ -308,10 +180,10 @@ export default {
pluginComponentManager.push(
{
want: {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
bundleName: "com.example.plugin",
abilityName: "com.example.myapplication.PluginProviderExample",
},
name: "plugintemplate",
name: "PluginProviderExample",
data: {
"key_1": "plugin component test",
"key_2": 34234
......@@ -330,10 +202,10 @@ export default {
// 组件使用方主动发送事件
pluginComponentManager.request({
want: {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
bundleName: "com.example.plugin",
abilityName: "com.example.myapplication.PluginProviderExample",
},
name: "plugintemplate",
name: "PluginProviderExample",
data: {
"key_1": "plugin component test",
"key_2": 34234
......@@ -358,10 +230,98 @@ export default {
}
```
#### Stage模型
```js
//plugin_component.js
import pluginComponentManager from '@ohos.pluginComponent'
function onPushListener(source, template, data, extraData) {
console.log("onPushListener template.source=" + template.source)
var jsonObject = JSON.parse(data.componentTemplate.source)
console.log("request_callback1:source json object" + jsonObject)
var jsonArry = jsonObject.ExternalComponent
for (var i in jsonArry) {
console.log(jsonArry[i])
}
console.log("onPushListener:source json object" + jsonObject)
console.log("onPushListener:source json string" + JSON.stringify(jsonObject))
console.log("onPushListener template.ability=" + template.ability)
console.log("onPushListener data=" + JSON.stringify(data))
console.log("onPushListener extraData=" + JSON.stringify(extraData))
}
### external.json
```json
function onRequestListener(source, name, data)
{
"plugintemplate": "ets/pages/plugintemplate.js",
"plugintemplate2": "ets/pages/plugintemplate2.js"
console.log("onRequestListener name=" + name);
console.log("onRequestListener data=" + JSON.stringify(data));
return {template:"plugintemplate", data:data};
}
export default {
//register listener
onListener() {
pluginComponentManager.on("push", onPushListener)
pluginComponentManager.on("request", onRequestListener)
},
Push() {
// 组件提供方主动发送事件
pluginComponentManager.push(
{
owner: {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
},
target: {
bundleName: "com.example.plugin",
abilityName: "com.example.myapplication.PluginProviderExample",
},
name: "PluginProviderExample",
data: {
"key_1": "plugin component test",
"key_2": 34234
},
extraData: {
"extra_str": "this is push event"
},
jsonPath: "",
},
(err, data) => {
console.log("push_callback: push ok!");
}
)
},
Request() {
// 组件使用方主动发送事件
pluginComponentManager.request({
owner: {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
},
target: {
bundleName: "com.example.plugin",
abilityName: "com.example.myapplication.PluginProviderExample",
},
name: "PluginProviderExample",
data: {
"key_1": "plugin component test",
"key_2": 34234
},
jsonPath: "",
},
(err, data) => {
console.log("request_callback: componentTemplate.ability=" + data.componentTemplate.ability)
console.log("request_callback: componentTemplate.source=" + data.componentTemplate.source)
var jsonObject = JSON.parse(data.componentTemplate.source)
console.log("request_callback:source json object" + jsonObject)
var jsonArry = jsonObject.ExternalComponent
for (var i in jsonArry) {
console.log(jsonArry[i])
}
console.log("request_callback:source json string" + JSON.stringify(jsonObject))
console.log("request_callback: data=" + JSON.stringify(data.data))
console.log("request_callback: extraData=" + JSON.stringify(data.extraData))
}
)
}
}
```
# arkui子系统ChangeLog
## cl.arkui.1 getInspectorTree接口返回值从string修改为Object。
**变更影响**
3.2.10.7之前使用getInspectorTree接口的代码需要适配
**关键的接口/组件变更**
getInspectorTree接口返回值从string修改为Object
**适配指导**
将getInspectorTree返回值作为string使用的代码需要修改,比如以下示例代码:
```typescript
console.info(getInspectorTree())
```
需要修改成
```typescript
console.info(JSON.stringify(getInspectorTree()))
```
## cl.arkui.2 废弃GridItem的forceRebuild属性
**变更影响**
无,该属性无作用
**关键的接口/组件变更**
GridItem的forceRebuild属性废弃
**适配指导**
如有使用可以直接删除,不影响GridItem功能
# arkui子系统ChangeLog
## cl.arkui.1 getInspectorTree接口返回值从string修改为Object。
**变更影响**
3.2.10.7之前使用getInspectorTree接口的代码需要适配
**关键的接口/组件变更**
getInspectorTree接口返回值从string修改为Object
**适配指导**
将getInspectorTree返回值作为string使用的代码需要修改,比如以下示例代码:
```typescript
console.info(getInspectorTree())
```
需要修改成
```typescript
console.info(JSON.stringify(getInspectorTree()))
```
## cl.arkui.2 废弃GridItem的forceRebuild属性
**变更影响**
无,该属性无作用
**关键的接口/组件变更**
GridItem的forceRebuild属性废弃
**适配指导**
如有使用可以直接删除,不影响GridItem功能
## cl.arkui.3 Plugin模块接口变更
### 1. arkui子系统Plugin模块 `PluginComponentTemplate` 接口存在变更:
ability命名无法准确表达对应参数的语义,修改为bundleName。
开发者需要根据以下说明对应用进行适配。
**变更影响**
基于此前版本开发的应用,需适配变更接口,变更前的接口已经不能正常使用,会在编译过程中报错。
**关键的接口/组件变更**
- 涉及接口
interface PluginComponentTemplate {
source: string;
bundleName: string;
}
interface PluginComponentInterface {
(value: { template: PluginComponentTemplate; data: any }): PluginComponentAttribute;
}
- 变更前:
```js
interface PluginComponentTemplate { source: string; ability: string; }
interface PluginComponentInterface {
(value: { template: PluginComponentTemplate; data: any }): PluginComponentAttribute;
}
```
- 变更后:
```js
interface PluginComponentTemplate { source: string; bundleName: string; }
interface PluginComponentInterface {
(value: { template: PluginComponentTemplate; data: any }): PluginComponentAttribute;
}
```
**适配指导**
使用变更后的接口,示例代码如下:
- 变更前:
```js
PluginComponent({
template: { source: 'plugincomponent1', ability: 'com.example.plugin' },
data: { 'countDownStartValue': 'new countDownStartValue' }
}).size({ width: 500, height: 100 })
```
- 变更后:
```js
PluginComponent({
template: { source: 'plugincomponent1', bundleName: 'com.example.plugin' },
data: { 'countDownStartValue': 'new countDownStartValue' }
}).size({ width: 500, height: 100 })
```
### 2. arkui子系统Plugin模块 `pluginComponentManager` 接口存在变更:
want命名无法准确表达对应参数的语义,修改为target。
开发者需要根据以下说明对应用进行适配。
**变更影响**
基于此前版本开发的应用,需适配变更接口。变更前的接口会出现告警,虽然可以通过编译,但是已经不能正常使用其功能。
**关键的接口/组件变更**
- 涉及接口
interface PushParameterForStage {
owner: Want;
target: Want;
name: string;
data: KVObject;
extraData: KVObject;
jsonPath?: string;
}
function push(param: PushParameterForStage, callback: AsyncCallback<void>): void;
interface RequestParameterForStage {
owner: Want;
target: Want;
name: string;
data: KVObject;
jsonPath?: string;
}
function request(param: RequestParameterForStage, callback: AsyncCallback<RequestCallbackParameters>): void;
- 变更前:
```js
interface PushParameterForStage {
owner: Want;
want: Want;
name: string;
data: KVObject;
extraData: KVObject;
jsonPath?: string;
}
function push(param: PushParameterForStage, callback: AsyncCallback<void>): void;
interface RequestParameterForStage {
owner: Want;
want: Want;
name: string;
data: KVObject;
jsonPath?: string;
}
function request(param: RequestParameterForStage, callback: AsyncCallback<RequestCallbackParameters>): void;
```
- 变更后:
```js
interface PushParameterForStage {
owner: Want;
target: Want;
name: string;
data: KVObject;
extraData: KVObject;
jsonPath?: string;
}
function push(param: PushParameterForStage, callback: AsyncCallback<void>): void;
interface RequestParameterForStage {
owner: Want;
target: Want;
name: string;
data: KVObject;
jsonPath?: string;
}
function request(param: RequestParameterForStage, callback: AsyncCallback<RequestCallbackParameters>): void;
```
**适配指导**
使用变更后的接口,示例代码如下:
- 变更前:
```js
import pluginComponentManager from '@ohos.pluginComponent'
pluginComponentManager.push({
owner:{
bundleName:"com.example.provider",
abilityName:"com.example.provider.MainAbility"
},
want: {
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!");
}
)
pluginComponentManager.request({
owner:{
bundleName:"com.example.provider",
abilityName:"com.example.provider.MainAbility"
},
want: {
bundleName: "com.example.provider",
abilityName: "ets/pages/plugin2.js",
},
name: "plugintemplate",
data: {
"key_1": " myapplication plugin component test",
"key_2": 123456
},
jsonPath: "",
},
(err, data) => {
console.log("request_callback: componentTemplate.ability=" + data.componentTemplate.ability)
console.log("request_callback: componentTemplate.source=" + data.componentTemplate.source)
}
)
```
- 变更后:
```js
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!");
}
)
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",
"key_2": 123456
},
jsonPath: "",
},
(err, data) => {
console.log("request_callback: componentTemplate.ability=" + data.componentTemplate.ability)
console.log("request_callback: componentTemplate.source=" + data.componentTemplate.source)
}
)
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册