diff --git a/customappbar/interfaces/custom_app_bar.js b/customappbar/interfaces/custom_app_bar.js index 8715e2d1abf2455ea491f3c3562698ede17db68d..aa55468094ad8c2ed5b60217ef6b32b3dcf05d6a 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 b426bf86e79a7e8330e56007028aeea6018b7605..fad46326155fe8b0d5bd9e2cbb5e9413c61d3ced 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(); }))