diff --git a/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js b/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js index d1a79332689bd8707e8f75549b52ad141e5b0e42..31a5d0f3a5798be5e0342d27639b3c02ba416aee 100644 --- a/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js +++ b/halfscreenlaunchcomponent/interfaces/halfscreenlaunchcomponent.js @@ -20,6 +20,7 @@ const hilog = requireNapi('hilog'); const abilityManager = requireNapi('app.ability.abilityManager'); const commonEventManager = requireNapi('commonEventManager'); const EMBEDDED_HALF_MODE = 2; +const atomicServiceDataTag = 'ohos.atomicService.window'; export class HalfScreenLaunchComponent extends ViewPU { constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { super(parent, __localStorage, elmtId, extraInfo); @@ -34,6 +35,7 @@ export class HalfScreenLaunchComponent extends ViewPU { this.subscriber = null; this.onError = undefined; this.onTerminated = undefined; + this.onReceive = undefined; this.setInitiallyProvidedValue(params); this.finalizeConstruction(); } @@ -62,6 +64,9 @@ export class HalfScreenLaunchComponent extends ViewPU { if (params.onTerminated !== undefined) { this.onTerminated = params.onTerminated; } + if (params.onReceive !== undefined) { + this.onReceive = params.onReceive; + } } updateStateVars(params) { } @@ -165,6 +170,21 @@ export class HalfScreenLaunchComponent extends ViewPU { hilog.error(0x3900, 'HalfScreenLaunchComponent', '%{public}s open service error!', e.message); } } + handleOnReceiveEvent(data) { + if (data === undefined || data === null) { + return; + } + if (this.onReceive !== undefined) { + const sourceKeys = Object.keys(data); + let atomicServiceData = {}; + for (let i = 0; i < sourceKeys.length; i++) { + if (sourceKeys[i].includes(atomicServiceDataTag)) { + atomicServiceData[sourceKeys[i]] = data[sourceKeys[i]]; + } + } + this.onReceive(atomicServiceData); + } + } initialRender() { this.observeComponentCreation2((elmtId, isInitialRender) => { Row.create(); @@ -209,6 +229,9 @@ export class HalfScreenLaunchComponent extends ViewPU { this.onTerminated(info); } }); + UIExtensionComponent.onReceive(data => { + this.handleOnReceiveEvent(data); + }); }, UIExtensionComponent); } rerender() { diff --git a/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets b/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets index 4abb0472c0a7827c8b18db6ddf73646daa0ff7d9..dfd4a3bb5110c0f318016c8ae3c5b3cce55999cb 100644 --- a/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets +++ b/halfscreenlaunchcomponent/source/halfscreenlaunchcomponent.ets @@ -21,6 +21,7 @@ import commonEventManager from '@ohos.commonEventManager'; import Base from '@ohos.base'; const EMBEDDED_HALF_MODE = 2; +const atomicServiceDataTag: string = 'ohos.atomicService.window'; @Component export struct HalfScreenLaunchComponent { @BuilderParam content: Callback = this.doNothingBuilder; @@ -31,6 +32,7 @@ export struct HalfScreenLaunchComponent { private subscriber: commonEventManager.CommonEventSubscriber | null = null; onError?: ErrorCallback; onTerminated?: Callback; + onReceive?: Callback>; aboutToAppear(): void { let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { @@ -128,6 +130,22 @@ export struct HalfScreenLaunchComponent { } } + private handleOnReceiveEvent(data: Object): void { + if (data === undefined || data === null) { + return; + } + if (this.onReceive !== undefined) { + const sourceKeys = Object.keys(data); + let atomicServiceData: Record = {}; + for (let i = 0; i < sourceKeys.length; i++) { + if (sourceKeys[i].includes(atomicServiceDataTag)) { + atomicServiceData[sourceKeys[i]] = data[sourceKeys[i]]; + } + } + this.onReceive(atomicServiceData); + } + } + build() { Row() { this.content(); @@ -172,5 +190,8 @@ export struct HalfScreenLaunchComponent { this.onTerminated(info); } }) + .onReceive(data => { + this.handleOnReceiveEvent(data); + }) } } \ No newline at end of file diff --git a/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js b/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js index 00a9510b06e65e71d8febb86bdc82b40632d1386..6f74e03990778f0460256faa510955c1435f9ec7 100644 --- a/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js +++ b/innerfullscreenlaunchcomponent/interfaces/innerfullscreenlaunchcomponent.js @@ -19,6 +19,7 @@ if (!("finalizeConstruction" in ViewPU.prototype)) { const hilog = requireNapi('hilog'); const abilityManager = requireNapi('app.ability.abilityManager'); const commonEventManager = requireNapi('commonEventManager'); +const atomicServiceDataTag = 'ohos.atomicService.window'; export class LaunchController { constructor() { this.launchAtomicService = (n1, o1) => { }; @@ -39,6 +40,7 @@ export class InnerFullScreenLaunchComponent extends ViewPU { this.options = undefined; this.__isShow = new ObservedPropertySimplePU(false, this, "isShow"); this.subscriber = null; + this.onReceive = undefined; this.launchAtomicService = (k1, l1) => { hilog.info(0x3900, 'InnerFullScreenLaunchComponent', 'launchAtomicService, appId: %{public}s.', k1); this.appId = k1; @@ -73,6 +75,9 @@ export class InnerFullScreenLaunchComponent extends ViewPU { if (c1.launchAtomicService !== undefined) { this.launchAtomicService = c1.launchAtomicService; } + if (c1.onReceive !== undefined) { + this.onReceive = c1.onReceive; + } } updateStateVars(b1) { } @@ -177,6 +182,21 @@ export class InnerFullScreenLaunchComponent extends ViewPU { hilog.error(0x3900, 'InnerFullScreenLaunchComponent', '%{public}s open service error!', l.message); } } + handleOnReceiveEvent(data) { + if (data === undefined || data === null) { + return; + } + if (this.onReceive !== undefined) { + const sourceKeys = Object.keys(data); + let atomicServiceData = {}; + for (let i = 0; i < sourceKeys.length; i++) { + if (sourceKeys[i].includes(atomicServiceDataTag)) { + atomicServiceData[sourceKeys[i]] = data[sourceKeys[i]]; + } + } + this.onReceive(atomicServiceData); + } + } initialRender() { this.observeComponentCreation2((i, j) => { Row.create(); @@ -210,6 +230,9 @@ export class InnerFullScreenLaunchComponent extends ViewPU { message: g.message }); }); + UIExtensionComponent.onReceive(data => { + this.handleOnReceiveEvent(data); + }); }, UIExtensionComponent); } rerender() { diff --git a/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets b/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets index e5e6d00d943f5d0b7fac82b3e459853b57df4e8d..23e062359404e302d5909be48bb76dbcfba8d694 100644 --- a/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets +++ b/innerfullscreenlaunchcomponent/source/innerfullscreenlaunchcomponent.ets @@ -25,6 +25,7 @@ export class LaunchController { } const EMBEDDED_FULL_MODE: number = 1; +const atomicServiceDataTag: string = 'ohos.atomicService.window'; @Component export struct InnerFullScreenLaunchComponent { @@ -42,6 +43,7 @@ export struct InnerFullScreenLaunchComponent { this.options = options; this.checkAbility(); } + onReceive?: Callback>; aboutToAppear() { let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { @@ -141,6 +143,22 @@ export struct InnerFullScreenLaunchComponent { } } + private handleOnReceiveEvent(data: Object): void { + if (data === undefined || data === null) { + return; + } + if (this.onReceive !== undefined) { + const sourceKeys = Object.keys(data); + let atomicServiceData: Record = {}; + for (let i = 0; i < sourceKeys.length; i++) { + if (sourceKeys[i].includes(atomicServiceDataTag)) { + atomicServiceData[sourceKeys[i]] = data[sourceKeys[i]]; + } + } + this.onReceive(atomicServiceData); + } + } + build() { Row() { this.content(); @@ -165,14 +183,18 @@ export struct InnerFullScreenLaunchComponent { hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'onRelease'); this.isShow = false; } - ).onError( - err => { - this.isShow = false; - hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'call up UIExtension error! %{public}s', err.message); - this.getUIContext().showAlertDialog({ - message: err.message - }); - } - ) + ) + .onError( + err => { + this.isShow = false; + hilog.error(0x3900, 'InnerFullScreenLaunchComponent', 'call up UIExtension error! %{public}s', err.message); + this.getUIContext().showAlertDialog({ + message: err.message + }); + } + ) + .onReceive(data => { + this.handleOnReceiveEvent(data); + }) } } \ No newline at end of file