From f59cef72d88ebebd38a2718ceb2c8177136cbaff Mon Sep 17 00:00:00 2001 From: Elemt Date: Tue, 3 Nov 2026 15:28:20 +0800 Subject: [PATCH] =?UTF-8?q?dev:=201=E3=80=81=E9=A6=96=E9=A1=B5banner?= =?UTF-8?q?=E5=A4=A7=E4=BA=8E1=E6=97=B6=E6=89=8D=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E6=8C=87=E7=A4=BA=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 4 +-- common/src/main/ets/utils/WindowSafeArea.ets | 29 +++++++++++++++++-- .../src/main/ets/utils/WindowSafeArea.ets | 29 +++++++++++++++++-- products/app/build-profile.json5 | 2 +- products/app/src/main/ets/view/HomeBanner.ets | 24 ++++++++------- .../app/src/main/ets/view/SafeAreaPage.ets | 8 ++--- 6 files changed, 71 insertions(+), 25 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index 3ac23ba..50d41db 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -43,12 +43,12 @@ "arkOptions": { "buildProfileFields": { "CHANNEL": "harmony", - "BUILD_TIME": "2611031154" + "BUILD_TIME": "2611031526" } } }, "output": { - "artifactName": "rabbit_harmony_debug_v1.0.1_2611031154" + "artifactName": "rabbit_harmony_debug_v1.0.1_2611031526" } } ], diff --git a/common/src/main/ets/utils/WindowSafeArea.ets b/common/src/main/ets/utils/WindowSafeArea.ets index 9424512..15d5760 100644 --- a/common/src/main/ets/utils/WindowSafeArea.ets +++ b/common/src/main/ets/utils/WindowSafeArea.ets @@ -28,6 +28,21 @@ interface FloatingNavigationInfo { region: number[]; } +// 对齐 weiquan-har SafeAreaManager.getTabBarBottom:只有明确为隐藏/悬浮球才收紧手势区。 +// 缺少 region、设置不可用或未知 showType 时,不应把三键导航误当成手势导航。 +export function getTabBarBottomInset(bottom: number, systemBottom: number, navigationValue: string): number { + if (systemBottom > 0) { + return Math.max(systemBottom, bottom); + } + try { + const navigation = JSON.parse(navigationValue) as FloatingNavigationInfo; + if (navigation && (navigation.showType === -1 || navigation.showType === 1)) { + return Math.min(bottom, 12); + } + } catch (_) {} + return bottom; +} + // 悬浮三键在部分系统版本不计入 TYPE_SYSTEM;region 是屏幕坐标,单位 px。 export function getFloatingNavigationInsets(value: string, bounds: window.Rect): NavigationInsets { const result: NavigationInsets = { left: 0, right: 0, bottom: 0 }; @@ -87,6 +102,11 @@ export class WindowSafeArea { this.observingNavigation = settings.registerKeyObserver(context, FLOAT_NAVIGATION_KEY, settings.domainName.USER_PROPERTY, this.onFloatingNavigationChange); } catch (_) {} + try { + // 首帧前确定导航方式;后续变化继续异步读取,避免重复阻塞布局。 + this.floatingNavigationValue = settings.getValueSync(context, FLOAT_NAVIGATION_KEY, + '', settings.domainName.USER_PROPERTY); + } catch (_) {} this.refresh(); } @@ -128,10 +148,13 @@ export class WindowSafeArea { AppStorage.setOrCreate('statusBarHeight', uiContext.px2vp(systemArea.topRect.height)); AppStorage.setOrCreate('navigationBarLeft', uiContext.px2vp(insets.left)); AppStorage.setOrCreate('navigationBarRight', uiContext.px2vp(insets.right)); - AppStorage.setOrCreate('navigationBarBottom', uiContext.px2vp(insets.bottom)); + const bottom = uiContext.px2vp(insets.bottom); + const systemBottom = uiContext.px2vp(Math.max(0, systemArea.bottomRect.height, floating.bottom)); + AppStorage.setOrCreate('navigationBarBottom', bottom); // 三键导航是不可遮挡的系统区域;首页可单独收紧手势指示条上方的留白。 - AppStorage.setOrCreate('systemNavigationBarBottom', - uiContext.px2vp(Math.max(0, systemArea.bottomRect.height, floating.bottom))); + AppStorage.setOrCreate('systemNavigationBarBottom', systemBottom); + AppStorage.setOrCreate('tabBarBottom', + getTabBarBottomInset(bottom, systemBottom, this.floatingNavigationValue)); } catch (error) { Logger.error('WindowSafeArea', '更新系统栏避让区域失败: ' + JSON.stringify(error)); } diff --git a/features/mainLayout/oh_modules/@ohos/common/src/main/ets/utils/WindowSafeArea.ets b/features/mainLayout/oh_modules/@ohos/common/src/main/ets/utils/WindowSafeArea.ets index 9424512..15d5760 100644 --- a/features/mainLayout/oh_modules/@ohos/common/src/main/ets/utils/WindowSafeArea.ets +++ b/features/mainLayout/oh_modules/@ohos/common/src/main/ets/utils/WindowSafeArea.ets @@ -28,6 +28,21 @@ interface FloatingNavigationInfo { region: number[]; } +// 对齐 weiquan-har SafeAreaManager.getTabBarBottom:只有明确为隐藏/悬浮球才收紧手势区。 +// 缺少 region、设置不可用或未知 showType 时,不应把三键导航误当成手势导航。 +export function getTabBarBottomInset(bottom: number, systemBottom: number, navigationValue: string): number { + if (systemBottom > 0) { + return Math.max(systemBottom, bottom); + } + try { + const navigation = JSON.parse(navigationValue) as FloatingNavigationInfo; + if (navigation && (navigation.showType === -1 || navigation.showType === 1)) { + return Math.min(bottom, 12); + } + } catch (_) {} + return bottom; +} + // 悬浮三键在部分系统版本不计入 TYPE_SYSTEM;region 是屏幕坐标,单位 px。 export function getFloatingNavigationInsets(value: string, bounds: window.Rect): NavigationInsets { const result: NavigationInsets = { left: 0, right: 0, bottom: 0 }; @@ -87,6 +102,11 @@ export class WindowSafeArea { this.observingNavigation = settings.registerKeyObserver(context, FLOAT_NAVIGATION_KEY, settings.domainName.USER_PROPERTY, this.onFloatingNavigationChange); } catch (_) {} + try { + // 首帧前确定导航方式;后续变化继续异步读取,避免重复阻塞布局。 + this.floatingNavigationValue = settings.getValueSync(context, FLOAT_NAVIGATION_KEY, + '', settings.domainName.USER_PROPERTY); + } catch (_) {} this.refresh(); } @@ -128,10 +148,13 @@ export class WindowSafeArea { AppStorage.setOrCreate('statusBarHeight', uiContext.px2vp(systemArea.topRect.height)); AppStorage.setOrCreate('navigationBarLeft', uiContext.px2vp(insets.left)); AppStorage.setOrCreate('navigationBarRight', uiContext.px2vp(insets.right)); - AppStorage.setOrCreate('navigationBarBottom', uiContext.px2vp(insets.bottom)); + const bottom = uiContext.px2vp(insets.bottom); + const systemBottom = uiContext.px2vp(Math.max(0, systemArea.bottomRect.height, floating.bottom)); + AppStorage.setOrCreate('navigationBarBottom', bottom); // 三键导航是不可遮挡的系统区域;首页可单独收紧手势指示条上方的留白。 - AppStorage.setOrCreate('systemNavigationBarBottom', - uiContext.px2vp(Math.max(0, systemArea.bottomRect.height, floating.bottom))); + AppStorage.setOrCreate('systemNavigationBarBottom', systemBottom); + AppStorage.setOrCreate('tabBarBottom', + getTabBarBottomInset(bottom, systemBottom, this.floatingNavigationValue)); } catch (error) { Logger.error('WindowSafeArea', '更新系统栏避让区域失败: ' + JSON.stringify(error)); } diff --git a/products/app/build-profile.json5 b/products/app/build-profile.json5 index 6221bf7..c49b51b 100644 --- a/products/app/build-profile.json5 +++ b/products/app/build-profile.json5 @@ -26,7 +26,7 @@ { "name": "default", "output": { - "artifactName": "rabbit_harmony_v1.0.1_261131154" + "artifactName": "rabbit_harmony_v1.0.1_261131526" } }, { diff --git a/products/app/src/main/ets/view/HomeBanner.ets b/products/app/src/main/ets/view/HomeBanner.ets index 00715c9..0bcf2d5 100644 --- a/products/app/src/main/ets/view/HomeBanner.ets +++ b/products/app/src/main/ets/view/HomeBanner.ets @@ -77,18 +77,20 @@ export struct HomeBanner { if (event.type === TouchType.Up || event.type === TouchType.Cancel) { this.pressed = false; } }) - Row({ space: 6 }) { - ForEach(this.banners, (_banner: HomeBannerEntity, index: number) => { - Circle().width(6).height(6) - .fill(this.currentIndex === index ? Color.White : '#73FFFFFF') - }, (_banner: HomeBannerEntity, index: number) => index.toString()) + if (this.banners.length > 1) { + Row({ space: 6 }) { + ForEach(this.banners, (_banner: HomeBannerEntity, index: number) => { + Circle().width(6).height(6) + .fill(this.currentIndex === index ? Color.White : '#73FFFFFF') + }, (_banner: HomeBannerEntity, index: number) => index.toString()) + } + .id('home_banner_indicator') + .accessibilityText('第' + (this.currentIndex + 1) + '张,共' + this.banners.length + '张') + .padding({ left: 8, right: 8, top: 6, bottom: 6 }) + .backgroundColor('#26000000').borderRadius(20) + .margin({ bottom: 30 }) + .hitTestBehavior(HitTestMode.None) } - .id('home_banner_indicator') - .accessibilityText('第' + (this.currentIndex + 1) + '张,共' + this.banners.length + '张') - .padding({ left: 8, right: 8, top: 6, bottom: 6 }) - .backgroundColor('#26000000').borderRadius(20) - .margin({ bottom: 30 }) - .hitTestBehavior(HitTestMode.None) } } .id('home_banner') diff --git a/products/app/src/main/ets/view/SafeAreaPage.ets b/products/app/src/main/ets/view/SafeAreaPage.ets index 06e5160..7b1ad4f 100644 --- a/products/app/src/main/ets/view/SafeAreaPage.ets +++ b/products/app/src/main/ets/view/SafeAreaPage.ets @@ -8,8 +8,8 @@ export struct SafeAreaPage { @StorageProp('navigationBarLeft') private navigationBarLeft: number = 0; @StorageProp('navigationBarRight') private navigationBarRight: number = 0; @StorageProp('navigationBarBottom') private navigationBarBottom: number = 0; - @StorageProp('systemNavigationBarBottom') private systemNavigationBarBottom: number = 0; - // TabBar:手势区最多 12vp,三键导航完整避让后再留 8vp;详情页使用完整安全区。 + @StorageProp('tabBarBottom') private tabBarBottom: number = 0; + // 对齐 weiquan-har:三键/未知模式完整避让,明确为手势模式时最多 12vp。 @Prop compactGestureBottom: boolean = false; @BuilderParam content: () => void; @@ -24,9 +24,7 @@ export struct SafeAreaPage { left: this.navigationBarLeft, right: this.navigationBarRight, bottom: this.compactGestureBottom - ? (this.systemNavigationBarBottom > 0 - ? Math.max(this.systemNavigationBarBottom, this.navigationBarBottom) - : Math.min(this.navigationBarBottom, 12)) + ? this.tabBarBottom : this.navigationBarBottom }) }