Skip to content

Commit 0648882

Browse files
authored
feat(Tabbar): harmony 适配 (#2783)
1 parent beb7be2 commit 0648882

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

src/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@
353353
"author": "hx"
354354
},
355355
{
356-
"version": "2.0.0",
356+
"version": "3.0.0",
357357
"name": "Tabbar",
358358
"type": "component",
359359
"cName": "标签栏",

src/packages/tabbaritem/tabbaritem.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,20 @@
4242
color: $tabbar-active-color;
4343

4444
.nut-tabbar-item-icon-box {
45+
/* #ifdef harmony*/
46+
color: $tabbar-active-color;
47+
/* #endif*/
48+
/* #ifndef harmony*/
4549
color: inherit;
50+
/* #endif*/
4651

4752
.nut-icon {
53+
/* #ifdef harmony*/
54+
color: $tabbar-active-color;
55+
/* #endif*/
56+
/* #ifndef harmony*/
4857
color: inherit;
58+
/* #endif*/
4959
}
5060
}
5161
}

src/packages/tabbaritem/tabbaritem.taro.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { View } from '@tarojs/components'
44
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
55
import Badge from '@/packages/badge/index.taro'
66
import TabbarContext from '@/packages/tabbar/context'
7+
import addColorForHarmony from '@/utils/add-color-for-harmony'
78

89
export interface TabbarItemProps extends BasicComponent {
910
title: ReactNode
@@ -83,13 +84,32 @@ export const TabbarItem: FunctionComponent<Partial<TabbarItemProps>> = (
8384
{icon ? (
8485
<>
8586
<Badge {...badgeProps}>
86-
<View className={boxPrefix}>{icon}</View>
87+
<View className={boxPrefix}>
88+
{addColorForHarmony(
89+
icon,
90+
active ? ctx?.activeColor : ctx?.inactiveColor
91+
)}
92+
</View>
8793
</Badge>
88-
<View className={titleClass}>{title}</View>
94+
<View
95+
className={titleClass}
96+
style={{
97+
color: active ? ctx?.activeColor : ctx?.inactiveColor,
98+
}}
99+
>
100+
{title}
101+
</View>
89102
</>
90103
) : (
91104
<Badge {...badgeProps}>
92-
<View className={titleClass}>{title}</View>
105+
<View
106+
className={titleClass}
107+
style={{
108+
color: active ? ctx?.activeColor : ctx?.inactiveColor,
109+
}}
110+
>
111+
{title}
112+
</View>
93113
</Badge>
94114
)}
95115
</View>

src/utils/add-color-for-harmony.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface ColorProps {
1111
* @param color - 要添加的颜色值(如:'#ff0000')
1212
* @returns 处理后的 React 节点
1313
*/
14-
function addColorForHarmony(maybeElement: ReactNode, color: string) {
14+
function addColorForHarmony(maybeElement: ReactNode, color?: string) {
1515
if (React.isValidElement(maybeElement) && harmony()) {
1616
return React.cloneElement<ColorProps>(maybeElement as ReactElement, {
1717
color,

0 commit comments

Comments
 (0)