Skip to content

Commit 6e553d8

Browse files
committed
fix: harmony 高度适配
1 parent 0d98098 commit 6e553d8

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/packages/navbar/navbar.harmony.css

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
position: relative;
44
display: flex;
55
flex-direction: row;
6+
justify-content: center;
67
align-items: center;
78
height: 44px;
89
box-sizing: border-box;
910
background: #f5f6fa;
10-
background-color: #FFFFFF;
1111
box-shadow: 0 0 transparent;
1212
font-size: 14px;
1313
color: #1a1a1a;
@@ -33,9 +33,8 @@
3333
padding-left: 14px;
3434
}
3535
.nut-navbar-title {
36-
min-width: 53%;
36+
width: 50%;
3737
height: 100%;
38-
margin: 0 auto;
3938
text-align: center;
4039
display: flex;
4140
flex-direction: row;
@@ -47,7 +46,6 @@
4746
}
4847
.nut-navbar-title-align-left {
4948
min-width: 0;
50-
margin: 0;
5149
flex: 1;
5250
justify-content: flex-start;
5351
padding: 0 8px;
@@ -63,6 +61,7 @@
6361
display: flex;
6462
align-items: center;
6563
flex-direction: row;
64+
height: 100%;
6665
cursor: pointer;
6766
padding: 0 14px;
6867
/* #ifndef rn harmony jd h5 weapp*/

src/packages/navbar/navbar.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
position: relative;
44
display: flex;
55
flex-direction: row;
6+
justify-content: center;
67
align-items: center;
78
height: $navbar-height;
89
box-sizing: border-box;
910
background: $navbar-background;
10-
background-color: #ffffff;
1111
box-shadow: $navbar-box-shadow;
1212
font-size: $navbar-font-size;
1313
color: $navbar-color;
@@ -37,9 +37,8 @@
3737
}
3838

3939
&-title {
40-
min-width: 53%;
40+
width: 50%;
4141
height: 100%;
42-
margin: 0 auto;
4342
text-align: center;
4443
display: flex;
4544
flex-direction: row;
@@ -50,7 +49,6 @@
5049
color: $navbar-title-font-color;
5150
&-align-left {
5251
min-width: 0;
53-
margin: 0;
5452
flex: 1;
5553
justify-content: flex-start;
5654
padding: 0 8px;
@@ -70,6 +68,7 @@
7068
display: flex;
7169
align-items: center;
7270
flex-direction: row;
71+
height: 100%;
7372
cursor: pointer;
7473
padding: 0 14px;
7574
/* #ifndef rn harmony jd h5 weapp*/

src/packages/navbar/navbar.taro.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { ITouchEvent, View } from '@tarojs/components'
44
import { useRtl } from '@/packages/configprovider/index.taro'
55
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
66
import { getRectByTaro } from '@/utils/get-rect-by-taro'
7+
import { harmonyAndRn } from '@/utils/platform-taro'
8+
import pxTransform from '@/utils/px-transform'
79

810
export interface NavBarProps extends BasicComponent {
911
left: React.ReactNode
@@ -100,7 +102,9 @@ export const NavBar: FunctionComponent<Partial<NavBarProps>> = (props) => {
100102
}
101103
setContentWidth(centerWidth.toFixed(2))
102104
}
103-
init()
105+
setTimeout(() => {
106+
init()
107+
}, 0)
104108
}, [left, right, back])
105109

106110
const renderLeft = () => {
@@ -134,11 +138,11 @@ export const NavBar: FunctionComponent<Partial<NavBarProps>> = (props) => {
134138
const renderContent = () => {
135139
let titleStyle = {}
136140
if (titleAlign === 'center') {
137-
const contentRealWidth = `${contentWidth}${
138-
/%$/i.test(contentWidth) ? '' : 'px'
139-
}`
141+
const width = harmonyAndRn()
142+
? pxTransform(Number(contentWidth))
143+
: `${contentWidth}px`
144+
const contentRealWidth = /%$/i.test(contentWidth) ? contentWidth : width
140145
titleStyle = {
141-
minWidth: contentRealWidth,
142146
width: contentRealWidth,
143147
}
144148
}

0 commit comments

Comments
 (0)