From 4b17116ac91701c2eaf2c8ed3d9c07ace2209719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9E=E6=BC=AA?= Date: Mon, 10 Mar 2025 17:34:26 +0800 Subject: [PATCH] =?UTF-8?q?menubar=E9=80=82=E9=85=8D=E6=97=A0=E9=9A=9C?= =?UTF-8?q?=E7=A2=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 连漪 --- customappbar/interfaces/custom_app_bar.js | 42 +++++++++++++++++++++++ customappbar/source/custom_app_bar.ets | 22 +++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/customappbar/interfaces/custom_app_bar.js b/customappbar/interfaces/custom_app_bar.js index 8715e2d..aa55468 100644 --- a/customappbar/interfaces/custom_app_bar.js +++ b/customappbar/interfaces/custom_app_bar.js @@ -67,6 +67,8 @@ const EVENT_NAME_CUSTOM_APP_BAR_MENU_CLICK = 'arkui_custom_app_bar_menu_click'; const EVENT_NAME_CUSTOM_APP_BAR_CLOSE_CLICK = 'arkui_custom_app_bar_close_click'; const EVENT_NAME_CUSTOM_APP_BAR_DID_BUILD = 'arkui_custom_app_bar_did_build'; const EVENT_NAME_CUSTOM_APP_BAR_CREATE_SERVICE_PANEL = 'arkui_custom_app_bar_create_service_panel'; +const ARKUI_APP_BAR_SERVICE_PANEL = 'arkui_app_bar_service_panel'; +const ARKUI_APP_BAR_CLOSE = 'arkui_app_bar_close'; /** * 适配不同颜色模式集合 @@ -132,6 +134,8 @@ export class CustomAppBar extends ViewPU { this.__statusBarHeight = new ObservedPropertySimplePU(0, this, 'statusBarHeight'); this.__ratio = new ObservedPropertyObjectPU(undefined, this, 'ratio'); this.__breakPoint = new ObservedPropertySimplePU(BreakPointsType.NONE, this, 'breakPoint'); + this.__serviceMenuRead = new ObservedPropertySimplePU(this.getStringByResourceToken(ARKUI_APP_BAR_SERVICE_PANEL), this, 'serviceMenuRead'); + this.__closeRead = new ObservedPropertySimplePU(this.getStringByResourceToken(ARKUI_APP_BAR_CLOSE), this, 'closeRead'); this.isHalfToFullScreen = false; this.isDark = true; this.bundleName = ''; @@ -232,6 +236,12 @@ export class CustomAppBar extends ViewPU { if (params.breakPoint !== undefined) { this.breakPoint = params.breakPoint; } + if (params.serviceMenuRead !== undefined) { + this.serviceMenuRead = params.serviceMenuRead; + } + if (params.closeRead !== undefined) { + this.closeRead = params.closeRead; + } if (params.isHalfToFullScreen !== undefined) { this.isHalfToFullScreen = params.isHalfToFullScreen; } @@ -297,6 +307,8 @@ export class CustomAppBar extends ViewPU { this.__statusBarHeight.purgeDependencyOnElmtId(rmElmtId); this.__ratio.purgeDependencyOnElmtId(rmElmtId); this.__breakPoint.purgeDependencyOnElmtId(rmElmtId); + this.__serviceMenuRead.purgeDependencyOnElmtId(rmElmtId); + this.__closeRead.purgeDependencyOnElmtId(rmElmtId); } aboutToBeDeleted() { this.__menuResource.aboutToBeDeleted(); @@ -327,6 +339,8 @@ export class CustomAppBar extends ViewPU { this.__statusBarHeight.aboutToBeDeleted(); this.__ratio.aboutToBeDeleted(); this.__breakPoint.aboutToBeDeleted(); + this.__serviceMenuRead.aboutToBeDeleted(); + this.__closeRead.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id__()); this.aboutToBeDeletedInternal(); } @@ -498,6 +512,18 @@ export class CustomAppBar extends ViewPU { set breakPoint(newValue) { this.__breakPoint.set(newValue); } + get serviceMenuRead() { + return this.__serviceMenuRead.get(); + } + set serviceMenuRead(newValue) { + this.__serviceMenuRead.set(newValue); + } + get closeRead() { + return this.__closeRead.get(); + } + set closeRead(newValue) { + this.__closeRead.set(newValue); + } aboutToAppear() { if (this.isHalfScreen) { this.contentBgColor = Color.Transparent; @@ -568,6 +594,14 @@ export class CustomAppBar extends ViewPU { } return defaultColor; } + getStringByResourceToken(resName) { + try { + return getContext(this).resourceManager.getStringByNameSync(resName); + } catch (err) { + console.error(LOG_TAG, `getAccessibilityDescription, error: ${err.toString()}`); + } + return ''; + } /** * atomicservice侧的事件变化回调 * @param eventName 事件名称 @@ -806,6 +840,10 @@ export class CustomAppBar extends ViewPU { Button.backgroundColor(Color.Transparent); Button.width(BUTTON_SIZE); Button.height(VIEW_HEIGHT); + Button.accessibilityText(this.serviceMenuRead); + Button.onAccessibilityHover(() => { + this.serviceMenuRead = this.getStringByResourceToken(ARKUI_APP_BAR_SERVICE_PANEL); + }); Gesture.create(GesturePriority.Low); TapGesture.create(); TapGesture.onAction(() => { @@ -841,6 +879,10 @@ export class CustomAppBar extends ViewPU { Button.borderRadius({ topRight: MENU_RADIUS, bottomRight: MENU_RADIUS }); Button.width(BUTTON_SIZE); Button.height(VIEW_HEIGHT); + Button.accessibilityText(this.closeRead); + Button.onAccessibilityHover(() => { + this.closeRead = this.getStringByResourceToken(ARKUI_APP_BAR_CLOSE); + }); Gesture.create(GesturePriority.Low); TapGesture.create(); TapGesture.onAction(() => { diff --git a/customappbar/source/custom_app_bar.ets b/customappbar/source/custom_app_bar.ets index b426bf8..fad4632 100644 --- a/customappbar/source/custom_app_bar.ets +++ b/customappbar/source/custom_app_bar.ets @@ -59,7 +59,8 @@ const ARKUI_APP_BAR_CONTENT_SAFE_AREA: string = 'arkui_app_bar_content_safe_area const ARKUI_APP_BAR_BAR_INFO: string = 'arkui_app_bar_info'; const ARKUI_APP_BAR_SCREEN: string = 'arkui_app_bar_screen'; const ARKUI_APP_BG_COLOR: string = 'arkui_app_bg_color'; - +const ARKUI_APP_BAR_SERVICE_PANEL: string = 'arkui_app_bar_service_panel'; +const ARKUI_APP_BAR_CLOSE: string = 'arkui_app_bar_close'; const EVENT_NAME_CUSTOM_APP_BAR_MENU_CLICK = 'arkui_custom_app_bar_menu_click'; const EVENT_NAME_CUSTOM_APP_BAR_CLOSE_CLICK = 'arkui_custom_app_bar_close_click'; const EVENT_NAME_CUSTOM_APP_BAR_DID_BUILD = 'arkui_custom_app_bar_did_build'; @@ -144,6 +145,8 @@ export struct CustomAppBar { @State statusBarHeight: number = 0; @State ratio: number | undefined = undefined; @State @Watch('onBreakPointChange') breakPoint: BreakPointsType = BreakPointsType.NONE; + @State serviceMenuRead: string = this.getStringByResourceToken(ARKUI_APP_BAR_SERVICE_PANEL); + @State closeRead: string = this.getStringByResourceToken(ARKUI_APP_BAR_CLOSE); private isHalfToFullScreen: boolean = false; private isDark: boolean = true; private bundleName: string = ''; @@ -229,6 +232,15 @@ export struct CustomAppBar { return defaultColor; } + getStringByResourceToken(resName: string): string { + try { + return getContext(this).resourceManager.getStringByNameSync(resName); + } catch (err) { + console.error(LOG_TAG, `getAccessibilityDescription, error: ${err.toString()}`); + } + return ''; + } + /** * atomicservice侧的事件变化回调 * @param eventName 事件名称 @@ -446,6 +458,10 @@ export struct CustomAppBar { .backgroundColor(Color.Transparent) .width(BUTTON_SIZE) .height(VIEW_HEIGHT) + .accessibilityText(this.serviceMenuRead) + .onAccessibilityHover(() => { + this.serviceMenuRead = this.getStringByResourceToken(ARKUI_APP_BAR_SERVICE_PANEL); + }) .gesture(TapGesture().onAction(() => { this.onMenuButtonClick(); })) @@ -473,6 +489,10 @@ export struct CustomAppBar { .borderRadius({ topRight: MENU_RADIUS, bottomRight: MENU_RADIUS }) .width(BUTTON_SIZE) .height(VIEW_HEIGHT) + .accessibilityText(this.closeRead) + .onAccessibilityHover(() => { + this.closeRead = this.getStringByResourceToken(ARKUI_APP_BAR_CLOSE); + }) .gesture(TapGesture().onAction(() => { this.closeContainerAnimation(); })) -- Gitee