From 7efd1e5ccde7a87e8efc708b07fe6988a7ba47f1 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Mon, 8 Aug 2022 14:50:19 +0800 Subject: [PATCH] fix(h5): onNavigationBarChange layout navigationBarTitleText --- .../src/framework/components/layout/index.tsx | 17 +++++++++++++++-- packages/uni-h5/src/helpers/useDocumentTitle.ts | 3 ++- packages/uni-shared/dist/uni-shared.cjs.js | 2 ++ packages/uni-shared/dist/uni-shared.d.ts | 2 ++ packages/uni-shared/dist/uni-shared.es.js | 3 ++- packages/uni-shared/src/constants.ts | 1 + 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/uni-h5/src/framework/components/layout/index.tsx b/packages/uni-h5/src/framework/components/layout/index.tsx index 92795ca26..0f11187e3 100644 --- a/packages/uni-h5/src/framework/components/layout/index.tsx +++ b/packages/uni-h5/src/framework/components/layout/index.tsx @@ -24,7 +24,11 @@ import { defineSystemComponent } from '@dcloudio/uni-components' import { updateCssVar } from '@dcloudio/uni-core' import { useTabBar } from '../../setup/state' import { useKeepAliveRoute } from '../../setup/page' -import { resolveOwnerEl, RESPONSIVE_MIN_WIDTH } from '@dcloudio/uni-shared' +import { + resolveOwnerEl, + RESPONSIVE_MIN_WIDTH, + ON_NAVIGATION_BAR_CHANGE, +} from '@dcloudio/uni-shared' import { checkMinWidth } from '../../../helpers/dom' import { hasOwn } from '@vue/shared' @@ -111,6 +115,7 @@ interface LayoutState { marginWidth: number leftWindowWidth: number rightWindowWidth: number + navigationBarTitleText: string topWindowStyle: unknown leftWindowStyle: unknown rightWindowStyle: unknown @@ -235,6 +240,7 @@ function useState() { marginWidth: 0, leftWindowWidth: 0, rightWindowWidth: 0, + navigationBarTitleText: '', topWindowStyle: {}, leftWindowStyle: {}, rightWindowStyle: {}, @@ -276,6 +282,9 @@ function useState() { () => layoutState.rightWindowWidth + layoutState.marginWidth, (value) => updateCssVar({ '--window-right': value + 'px' }) ) + UniServiceJSBridge.on(ON_NAVIGATION_BAR_CHANGE, (navigationBar) => { + layoutState.navigationBarTitleText = navigationBar.titleText + }) const windowState = computed(() => ({ matchTopWindow: layoutState.topWindowMediaQuery, showTopWindow: layoutState.showTopWindow || layoutState.apiShowTopWindow, @@ -460,7 +469,11 @@ function createTopWindowTsx( v-show={layoutState.showTopWindow || layoutState.apiShowTopWindow} >
- +