From 0738c0699f7a26547885cdf86749ca643a6f7d5b Mon Sep 17 00:00:00 2001 From: chenshuai Date: Sun, 29 Sep 2024 20:03:32 +0800 Subject: [PATCH] UIExtension Adapts to Visible Area Change Events Feature or Bugfix: Bugfix Binary Source: NO Signed-off-by: amoscloud2013 --- frameworks/js/napi/adcomponent/adcomponent.js | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/frameworks/js/napi/adcomponent/adcomponent.js b/frameworks/js/napi/adcomponent/adcomponent.js index 08cd764..6c4ceca 100644 --- a/frameworks/js/napi/adcomponent/adcomponent.js +++ b/frameworks/js/napi/adcomponent/adcomponent.js @@ -48,6 +48,8 @@ class AdComponent extends ViewPU { this.eventUniqueId = ''; this.uniqueId = ''; this.uiExtProxy = null; + this.isVisibleBeforeRemoteReady = false; + this.currentRatioBeforeRemoteReady = 0; this.__showComponent = new ObservedPropertySimplePU(false, this, 'showComponent'); this.__Behavior = new ObservedPropertySimplePU(HitTestMode.Default, this, 'Behavior'); this.__uecHeight = new ObservedPropertySimplePU('100%', this, 'uecHeight'); @@ -71,6 +73,8 @@ class AdComponent extends ViewPU { 'eventUniqueId', 'uniqueId', 'uiExtProxy', + 'isVisibleBeforeRemoteReady', + 'currentRatioBeforeRemoteReady', 'showComponent', 'Behavior', 'uecHeight', @@ -291,6 +295,23 @@ class AdComponent extends ViewPU { }); UIExtensionComponent.onRemoteReady((v) => { this.uiExtProxy = v; + v.on('asyncReceiverRegister', (p) => { + p.send({ + 'isVisible': this.isVisibleBeforeRemoteReady, + 'currentRatio': this.currentRatioBeforeRemoteReady, + }); + }); + }); + UIExtensionComponent.onVisibleAreaChange(this.ratios, (v, r) => { + if (this.uiExtProxy) { + this.uiExtProxy.send({ + 'isVisible': v, + 'currentRatio': r, + }); + } else { + this.isVisibleBeforeRemoteReady = v; + this.currentRatioBeforeRemoteReady = r; + } }); UIExtensionComponent.width('100%'); UIExtensionComponent.height(this.uecHeight); @@ -318,11 +339,6 @@ class AdComponent extends ViewPU { const u = IMP; this.sendDataRequest(u, w); } - let p; - (p = this.uiExtProxy) === null || p === void 0 ? void 0 : p.send({ - 'isVisible': v, - 'currentRatio': w, - }); }); Column.onClick(() => this.onAreaClick()); }