启动后隐藏底部系统手势条,避免遮挡/拦截 H5 底部点击
横屏游戏外壳下底部导航条(手势指示条)会压在 H5 内容上并拦截点击。 在 onWindowStageCreate 调用 setWindowSystemBarEnable(['status']): 保留顶部状态栏、隐藏底部导航条,隐藏后避让区更新,H5 内容自动延伸到屏幕底部。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
5cfb68209c
commit
53fdd6d358
@@ -1,6 +1,7 @@
|
||||
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { window } from '@kit.ArkUI';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { EventBus } from 'common';
|
||||
import { WeChatApi } from 'feature_capabilities';
|
||||
import { AppEvents } from '../routes/AppRoutes';
|
||||
@@ -36,6 +37,10 @@ export default class EntryAbility extends UIAbility {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
|
||||
// 隐藏底部系统手势条(导航条):横屏游戏外壳下其会遮挡并拦截 H5 底部点击。
|
||||
// 保留顶部状态栏,避免给 H5 顶部内容引入新的避让遮挡。
|
||||
this.hideNavigationBar(windowStage);
|
||||
|
||||
windowStage.loadContent('pages/Index', (err) => {
|
||||
if (err.code) {
|
||||
hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
|
||||
@@ -45,6 +50,22 @@ export default class EntryAbility extends UIAbility {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏底部导航条(手势指示条),回收其占用空间给 H5 内容。
|
||||
* setWindowSystemBarEnable 的入参是"需要显示"的系统栏集合:仅传 'status'
|
||||
* → 顶部状态栏保留、底部导航条隐藏。隐藏后避让区更新,内容自动延伸到屏幕底部。
|
||||
*/
|
||||
private hideNavigationBar(windowStage: window.WindowStage): void {
|
||||
try {
|
||||
const mainWin: window.Window = windowStage.getMainWindowSync();
|
||||
mainWin.setWindowSystemBarEnable(['status']).catch((e: BusinessError) => {
|
||||
hilog.error(DOMAIN, 'testTag', 'setWindowSystemBarEnable failed: %{public}s', JSON.stringify(e));
|
||||
});
|
||||
} catch (e) {
|
||||
hilog.error(DOMAIN, 'testTag', 'hideNavigationBar threw: %{public}s', JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||
|
||||
Reference in New Issue
Block a user