diff --git a/customappbar/interfaces/custom_app_bar_forpc.js b/customappbar/interfaces/custom_app_bar_forpc.js index c5610c79457a516f7eda904d071eb92d4fad370f..235e53c167e8e0d5e9a94a5e6f02952f6b988e13 100644 --- a/customappbar/interfaces/custom_app_bar_forpc.js +++ b/customappbar/interfaces/custom_app_bar_forpc.js @@ -45,6 +45,7 @@ const EVENT_NAME_CUSTOM_APP_BAR_DID_BUILD = 'arkui_custom_app_bar_did_build'; const EVENT_NAME_MIN_CLICK = 'arkui_custom_min_click'; const EVENT_NAME_CLOSE_CLICK = 'arkui_custom_close_click'; const EVENT_NAME_CUSTOM_MAX_CLICK = 'arkui_custom_max_click'; +const ARKUI_APP_BAR_MENU_SAFE_AREA = 'arkui_app_bar_menu_safe_area'; class ColorGroup { constructor(light, dark) { @@ -90,6 +91,7 @@ export class CustomAppBarForPC extends ViewPU { this.__contentMarginBottom = new ObservedPropertySimplePU('0vp', this, 'contentMarginBottom'); this.__isAdaptPC = new ObservedPropertySimplePU(false, this, 'isAdaptPC'); this.__maximizeResource = new ObservedPropertyObjectPU(this.getIconResource(maximizeButtonResourceId), this, 'maximizeResource'); + this.__statusBarHeight = new ObservedPropertySimplePU(0, this, 'statusBarHeight'); this.isDark = true; this.windowClass = undefined; this.setInitiallyProvidedValue(params); @@ -135,6 +137,9 @@ export class CustomAppBarForPC extends ViewPU { if (params.maximizeResource !== undefined) { this.maximizeResource = params.maximizeResource; } + if (params.statusBarHeight !== undefined) { + this.statusBarHeight = params.statusBarHeight; + } if (params.isDark !== undefined) { this.isDark = params.isDark; } @@ -158,6 +163,7 @@ export class CustomAppBarForPC extends ViewPU { this.__contentMarginBottom.purgeDependencyOnElmtId(rmElmtId); this.__isAdaptPC.purgeDependencyOnElmtId(rmElmtId); this.__maximizeResource.purgeDependencyOnElmtId(rmElmtId); + this.__statusBarHeight.purgeDependencyOnElmtId(rmElmtId); } aboutToBeDeleted() { this.__menuResource.aboutToBeDeleted(); @@ -173,6 +179,7 @@ export class CustomAppBarForPC extends ViewPU { this.__contentMarginBottom.aboutToBeDeleted(); this.__isAdaptPC.aboutToBeDeleted(); this.__maximizeResource.aboutToBeDeleted(); + this.__statusBarHeight.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id__()); this.aboutToBeDeletedInternal(); } @@ -254,6 +261,12 @@ export class CustomAppBarForPC extends ViewPU { set maximizeResource(newValue) { this.__maximizeResource.set(newValue); } + get statusBarHeight() { + return this.__statusBarHeight.get(); + } + set statusBarHeight(newValue) { + this.__statusBarHeight.set(newValue); + } async aboutToAppear() { let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE; try { @@ -339,6 +352,12 @@ export class CustomAppBarForPC extends ViewPU { else if (eventName === ARKUI_APP_BG_COLOR) { this.contentBgColor = param; } + else if (eventName === ARKUI_APP_BAR_MENU_SAFE_AREA) { + if (this.statusBarHeight === px2vp(Number(param))) { + return; + } + this.statusBarHeight = Number(param); + } } /** * menu按钮点击 @@ -413,7 +432,7 @@ export class CustomAppBarForPC extends ViewPU { Row.create(); Row.id('AtomicServiceMenubarRowId'); Row.justifyContent(FlexAlign.End); - Row.margin({ top: LengthMetrics.vp(VIEW_MARGIN_TOP), end: LengthMetrics.vp(VIEW_MARGIN_RIGHT) }); + Row.margin({ top: LengthMetrics.vp(this.statusBarHeight + VIEW_MARGIN_TOP), end: LengthMetrics.vp(VIEW_MARGIN_RIGHT) }); Row.height(VIEW_HEIGHT); Row.hitTestBehavior(HitTestMode.Transparent); }, Row); diff --git a/customappbar/source/custom_app_bar_forpc.ets b/customappbar/source/custom_app_bar_forpc.ets index ee914abd404b3ad947d4a2478028b4c283eb3a22..bab47c49108ce28edce1bf341455695de20af963 100644 --- a/customappbar/source/custom_app_bar_forpc.ets +++ b/customappbar/source/custom_app_bar_forpc.ets @@ -44,6 +44,7 @@ const EVENT_NAME_CUSTOM_APP_BAR_DID_BUILD = 'arkui_custom_app_bar_did_build'; const EVENT_NAME_MIN_CLICK: string = 'arkui_custom_min_click'; const EVENT_NAME_CLOSE_CLICK: string = 'arkui_custom_close_click'; const EVENT_NAME_CUSTOM_MAX_CLICK: string = 'arkui_custom_max_click'; +const ARKUI_APP_BAR_MENU_SAFE_AREA: string = 'arkui_app_bar_menu_safe_area'; class ColorGroup { public light: string = '#000000'; @@ -88,6 +89,8 @@ export struct CustomAppBarForPC { @State contentMarginBottom: string = '0vp'; @State isAdaptPC: boolean = false; @State maximizeResource: Resource = this.getIconResource(maximizeButtonResourceId); + @State statusBarHeight: number = 0; + private isDark: boolean = true; private windowClass: window.Window | undefined = undefined; @@ -181,6 +184,11 @@ export struct CustomAppBarForPC { this.contentMarginBottom = splitArray[3]; } else if (eventName === ARKUI_APP_BG_COLOR) { this.contentBgColor = param; + } else if (eventName === ARKUI_APP_BAR_MENU_SAFE_AREA) { + if (this.statusBarHeight === px2vp(Number(param))) { + return; + } + this.statusBarHeight = Number(param); } } @@ -331,7 +339,7 @@ export struct CustomAppBarForPC { } .id('AtomicServiceMenubarRowId') .justifyContent(FlexAlign.End) - .margin({ top: LengthMetrics.vp(VIEW_MARGIN_TOP), end: LengthMetrics.vp(VIEW_MARGIN_RIGHT) }) + .margin({ top: LengthMetrics.vp(this.statusBarHeight + VIEW_MARGIN_TOP), end: LengthMetrics.vp(VIEW_MARGIN_RIGHT) }) .height(VIEW_HEIGHT) .hitTestBehavior(HitTestMode.Transparent) }