From 84d20e771247566fb152c3d702dff35b87dbec5a Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 22 Apr 2021 14:51:09 +0800 Subject: [PATCH] fix: navigationBar fontSize --- packages/shims-uni-app.d.ts | 1 + packages/uni-h5/dist/uni-h5.esm.js | 15 +++++++++++---- .../src/framework/components/page/pageHead.tsx | 4 +++- .../uni-h5/src/framework/setup/provide/page.ts | 6 ++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/shims-uni-app.d.ts b/packages/shims-uni-app.d.ts index 874579392..9297d1cbe 100644 --- a/packages/shims-uni-app.d.ts +++ b/packages/shims-uni-app.d.ts @@ -92,6 +92,7 @@ declare namespace UniApp { interface PageNavigationBar { type?: 'default' | 'transparent' | 'float' | 'none' + titleSize?: string titleText?: string titleImage?: string titleColor?: '#000' | '#fff' diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index 948b1c9fe..aad048f0f 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -1254,9 +1254,11 @@ function normalizePageMeta(pageMeta) { } if (__UNI_FEATURE_NAVIGATIONBAR__) { const {navigationBar} = pageMeta; + const {titleSize, titleColor, backgroundColor} = navigationBar; navigationBar.backButton = pageMeta.isQuit ? false : true; - navigationBar.titleColor = navigationBar.titleColor || "#fff"; - navigationBar.backgroundColor = navigationBar.backgroundColor || "#F7F7F7"; + navigationBar.titleSize = titleSize || "16px"; + navigationBar.titleColor = titleColor || "#fff"; + navigationBar.backgroundColor = backgroundColor || "#F7F7F7"; } if (__UNI_FEATURE_PAGES__ && history.state) { const type = history.state.__type__; @@ -13568,21 +13570,26 @@ function createPageHeadBdTsx(navigationBar, searchInput) { return createPageHeadSearchInputTsx(navigationBar, searchInput); } function createPageHeadTitleTextTsx({ + type, loading, + titleSize, titleText, titleImage }) { return createVNode("div", { class: "uni-page-head-bd" }, [createVNode("div", { - style: "{fontSize:titleSize,opacity:type==='transparent'?0:1}", + style: { + fontSize: titleSize, + opacity: type === "transparent" ? 0 : 1 + }, class: "uni-page-head__title" }, [loading ? createVNode("i", { class: "uni-loading" }, null) : titleImage ? createVNode("img", { src: titleImage, class: "uni-page-head__title_image" - }, null, 8, ["src"]) : titleText])]); + }, null, 8, ["src"]) : titleText], 4)]); } function createPageHeadSearchInputTsx(navigationBar, { text: text2, diff --git a/packages/uni-h5/src/framework/components/page/pageHead.tsx b/packages/uni-h5/src/framework/components/page/pageHead.tsx index bc6a343ef..3af8f3ad5 100644 --- a/packages/uni-h5/src/framework/components/page/pageHead.tsx +++ b/packages/uni-h5/src/framework/components/page/pageHead.tsx @@ -147,14 +147,16 @@ function createPageHeadBdTsx( } function createPageHeadTitleTextTsx({ + type, loading, + titleSize, titleText, titleImage, }: UniApp.PageNavigationBar) { return (
{loading ? ( diff --git a/packages/uni-h5/src/framework/setup/provide/page.ts b/packages/uni-h5/src/framework/setup/provide/page.ts index 6f78c810b..a2cccbc24 100644 --- a/packages/uni-h5/src/framework/setup/provide/page.ts +++ b/packages/uni-h5/src/framework/setup/provide/page.ts @@ -104,9 +104,11 @@ function normalizePageMeta(pageMeta: UniApp.PageRouteMeta) { } if (__UNI_FEATURE_NAVIGATIONBAR__) { const { navigationBar } = pageMeta + const { titleSize, titleColor, backgroundColor } = navigationBar navigationBar.backButton = pageMeta.isQuit ? false : true - navigationBar.titleColor = navigationBar.titleColor || '#fff' - navigationBar.backgroundColor = navigationBar.backgroundColor || '#F7F7F7' + navigationBar.titleSize = titleSize || '16px' + navigationBar.titleColor = titleColor || '#fff' + navigationBar.backgroundColor = backgroundColor || '#F7F7F7' } if (__UNI_FEATURE_PAGES__ && history.state) { // 首页执行了redirectTo -- GitLab