From d16c7259b4ec10052dc9a9c3bf9980346a0e896d Mon Sep 17 00:00:00 2001 From: lanterngamescn Date: Fri, 26 Jun 2026 21:19:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20H5=20=E7=BC=A9=E6=94=BE?= =?UTF-8?q?=E7=AD=89=E5=8A=A8=E7=94=BB=E4=B8=8D=E6=92=AD=E6=94=BE=EF=BC=9A?= =?UTF-8?q?=E5=A4=A7=E5=8E=85=20Web=20=E9=A6=96=E6=AC=A1=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E8=A1=A5=20onActive()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ArkWeb 文档:onInactive 态会暂停"可安全暂停的内容,例如动画"(CSS 动画/rAF),onActive 恢复。 本工程 controller.onActive() 原仅在从子游戏返回(activate)时调,**首次进大厅从未调用**, 大厅 Web 处于未激活态 → CSS transform/keyframes 动画与 requestAnimationFrame 被暂停, 表现为"画面在、但缩放等动画卡住不播放"。 修复:WebSlot 增 notifyShown()(调 controller.onActive(),幂等),在 setup() 激活槽建好即调, 并在 BridgeGameContainer 的 NavDestination.onShown 调用(首次进大厅 + 从通用网页返回均覆盖)。 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../src/main/ets/pages/BridgeGameContainer.ets | 2 ++ entry/src/main/ets/web/WebSlot.ets | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/entry/src/main/ets/pages/BridgeGameContainer.ets b/entry/src/main/ets/pages/BridgeGameContainer.ets index dacead5..f66616a 100644 --- a/entry/src/main/ets/pages/BridgeGameContainer.ets +++ b/entry/src/main/ets/pages/BridgeGameContainer.ets @@ -254,6 +254,8 @@ export struct BridgeGameContainer { .width('100%').height('100%') } .hideTitleBar(true) + // 页面(重新)可见时激活当前槽的 Web 引擎,恢复 CSS 动画/rAF(首次进大厅 + 从通用网页返回) + .onShown(() => this.activeSlot()?.notifyShown()) .onBackPressed(() => { // 分享面板打开时,返回键关闭面板并按取消回投(对齐 Android 点空白关闭) if (this.sharePanelVisible) { diff --git a/entry/src/main/ets/web/WebSlot.ets b/entry/src/main/ets/web/WebSlot.ets index 89aab8a..f9b527d 100644 --- a/entry/src/main/ets/web/WebSlot.ets +++ b/entry/src/main/ets/web/WebSlot.ets @@ -74,6 +74,23 @@ export class WebSlot { } catch (e) { WebSlot.log.e(`[${this.role}] capability registration failed (bridge usable): ${(e as Error).message}`); } + // 激活槽(大厅/子游戏)首次建好即通知 Web 引擎进入激活态——否则 ArkWeb 默认未激活态会 + // 暂停 CSS 动画/requestAnimationFrame(官方:onInactive 暂停动画),表现为"画面在但缩放等动画不播放"。 + if (this.active) { + this.notifyShown(); + } + } + + /** 页面可见时确保 Web 引擎处于激活态,恢复 CSS 动画/rAF(与 NavDestination onShown 配合,幂等)。 */ + notifyShown(): void { + if (this.disposed) { + return; + } + try { + this.controller.onActive(); + } catch (e) { + WebSlot.log.w(`[${this.role}] onActive(notifyShown) failed: ${(e as BusinessError).message}`); + } } onLoadIntercept(url: string): boolean {