From b88326688117a977476ddae882b630e1a49a468c Mon Sep 17 00:00:00 2001 From: betavs Date: Tue, 5 Mar 2024 17:10:15 +0800 Subject: [PATCH 1/2] fix(navbar): px to rpx conversion error --- src/navbar/navbar.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/navbar/navbar.ts b/src/navbar/navbar.ts index dfe5484e6..3a5256046 100644 --- a/src/navbar/navbar.ts +++ b/src/navbar/navbar.ts @@ -73,15 +73,16 @@ export default class Navbar extends SuperComponent { wx.getSystemInfo({ success: (res) => { const boxStyleList = []; - const { statusBarHeight } = wx.getSystemInfoSync(); + const { windowWidth, statusBarHeight } = wx.getSystemInfoSync(); + const px2rpx = (v: number) => Math.round((v * 750) / (windowWidth >= 750 ? 750 / 2 : windowWidth)); - boxStyleList.push(`--td-navbar-padding-top:${statusBarHeight * 2}rpx`); + boxStyleList.push(`--td-navbar-padding-top: ${px2rpx(statusBarHeight)}rpx`); if (rect && res?.windowWidth) { - boxStyleList.push(`--td-navbar-right:${(res.windowWidth - rect.left) * 2}rpx`); // 导航栏右侧小程序胶囊按钮宽度 + boxStyleList.push(`--td-navbar-right: ${px2rpx(res.windowWidth - rect.left)}rpx`); // 导航栏右侧小程序胶囊按钮宽度 } - boxStyleList.push(`--td-navbar-capsule-height: ${rect.height * 2}rpx`); // 胶囊高度 - boxStyleList.push(`--td-navbar-capsule-width: ${rect.width * 2}rpx`); // 胶囊宽度 - boxStyleList.push(`--td-navbar-height: ${((rect.top - statusBarHeight) * 2 + rect.height) * 2}rpx`); + boxStyleList.push(`--td-navbar-capsule-height: ${px2rpx(rect.height)}rpx`); // 胶囊高度 + boxStyleList.push(`--td-navbar-capsule-width: ${px2rpx(rect.width)}rpx`); // 胶囊宽度 + boxStyleList.push(`--td-navbar-height: ${px2rpx((rect.top - statusBarHeight) * 2 + rect.height)}rpx`); this.setData({ boxStyle: `${boxStyleList.join('; ')}`, }); From f378fbb57a3a329eea0072316b1fadf411694b3d Mon Sep 17 00:00:00 2001 From: betavs Date: Tue, 5 Mar 2024 17:15:10 +0800 Subject: [PATCH 2/2] test(navbar): px to rpx conversion error --- src/navbar/__test__/__snapshots__/index.test.js.snap | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/navbar/__test__/__snapshots__/index.test.js.snap b/src/navbar/__test__/__snapshots__/index.test.js.snap index 4b32693bb..2df0a3975 100644 --- a/src/navbar/__test__/__snapshots__/index.test.js.snap +++ b/src/navbar/__test__/__snapshots__/index.test.js.snap @@ -40,7 +40,7 @@ exports[`navbar :base 2`] = `