Skip to content

Commit 0d618c2

Browse files
committed
fix(Table):添加表格明暗主题适配
1 parent 67dad16 commit 0d618c2

File tree

2 files changed

+68
-70
lines changed

2 files changed

+68
-70
lines changed

example/examples/src/routes/Badge/index.tsx

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
2-
import {Text} from 'react-native';
3-
import {Badge, List} from '@uiw/react-native';
2+
import {Badge, List, Text} from '@uiw/react-native';
43
import {ComProps} from '../../routes';
54
import Layout, {Container} from '../../Layout';
65
const {Header, Body, Footer} = Layout;
@@ -18,41 +17,28 @@ export default class BadgeView extends React.Component<BadgeViewProps> {
1817
<Header title={title} description={description} />
1918
<Body>
2019
<List size="small" flat={false}>
21-
<List.Item onPress={() => navigation.goBack()}>
22-
这6种编码方法,你掌握了几个?
23-
</List.Item>
20+
<List.Item onPress={() => navigation.goBack()}>这6种编码方法,你掌握了几个?</List.Item>
2421
<List.Item extra={<Badge text="450k" color="green" />}>
2522
<Badge type="dot" text={<Text>450k</Text>} color="green" />
26-
<Text>Protobuf 生成 Go代码指南</Text>
27-
</List.Item>
28-
<List.Item extra={<Badge text="10" color="green" />}>
29-
Git 版本控制的核心概念
30-
</List.Item>
31-
<List.Item extra={<Badge text="450k" color="green" />}>
32-
HTTP Referer 和 Referrer Policy
33-
</List.Item>
34-
<List.Item extra={<Badge text="450k" color="yellow" />}>
35-
何解?浪费一年时间,我学了假人工智能
23+
<Text color="text">Protobuf 生成 Go代码指南</Text>
3624
</List.Item>
25+
<List.Item extra={<Badge text="10" color="green" />}>Git 版本控制的核心概念</List.Item>
26+
<List.Item extra={<Badge text="450k" color="green" />}>HTTP Referer 和 Referrer Policy</List.Item>
27+
<List.Item extra={<Badge text="450k" color="yellow" />}>何解?浪费一年时间,我学了假人工智能</List.Item>
3728
<List.Item extra={<Badge text="450k" color="green" />}>
38-
<Text>超燃!高效 MacBook 工作环境配置,超实用</Text>
29+
<Text color="text">超燃!高效 MacBook 工作环境配置,超实用</Text>
3930
</List.Item>
4031
<List.Item extra={<Badge text="标记" color="red" />}>
41-
<Text>一文带你搞懂 API 网关</Text>
32+
<Text color="text">一文带你搞懂 API 网关</Text>
4233
</List.Item>
4334
</List>
44-
<List
45-
size="small"
46-
flat={false}
47-
title="设置类型 type?: 'dot' | 'text'">
48-
<List.Item
49-
extra={<Badge type="dot" text="450k" color="red" />}
50-
onPress={() => navigation.goBack()}>
35+
<List size="small" flat={false} title="设置类型 type?: 'dot' | 'text'">
36+
<List.Item extra={<Badge type="dot" text="450k" color="red" />} onPress={() => navigation.goBack()}>
5137
这6种编码方法,你掌握了几个?
5238
</List.Item>
5339
<List.Item extra={<Badge text="450k" color="red" />}>
5440
<Badge type="dot" text="450k" color="green" />
55-
<Text>Protobuf 生成 Go代码指南</Text>
41+
<Text color="text">Protobuf 生成 Go代码指南</Text>
5642
</List.Item>
5743
</List>
5844
</Body>

packages/core/src/Table/index.tsx

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from 'react';
22
import { View, Text, StyleSheet, Dimensions, ScrollView } from 'react-native';
33
import BodyRow from './BodyRow';
44
import { colors } from '../utils';
5+
import { useTheme } from '@shopify/restyle';
6+
import { Theme } from '../theme';
57

68
interface TableProps {
79
data: Array<Object>;
@@ -20,6 +22,11 @@ interface columnsState {
2022
}
2123
// table组件
2224
const Table = ({ data, columns, rowKey, horizontal = true, style }: TableProps) => {
25+
const theme = useTheme<Theme>();
26+
const styles = createStyles({
27+
bgColor: theme.colors.background || '#F5F5F5',
28+
textColor: theme.colors.primary_text || '#ccc',
29+
});
2330
const getRowKey: (record: any) => string = (record) => {
2431
const key = typeof rowKey === 'function' ? rowKey(record) : record && record[rowKey];
2532
return key;
@@ -32,7 +39,11 @@ const Table = ({ data, columns, rowKey, horizontal = true, style }: TableProps)
3239
{columns.map((itm, idx) => (
3340
<View
3441
key={itm.dataIndex + idx}
35-
style={[styles.contRight, { borderRightWidth: idx === columns.length - 1 ? 0 : 1 }, itm.style ? itm.style : styles.titleFlex]}
42+
style={[
43+
styles.contRight,
44+
{ borderRightWidth: idx === columns.length - 1 ? 0 : 1 },
45+
itm.style ? itm.style : styles.titleFlex,
46+
]}
3647
>
3748
<Text style={styles.content}>{itm.title}</Text>
3849
</View>
@@ -41,13 +52,7 @@ const Table = ({ data, columns, rowKey, horizontal = true, style }: TableProps)
4152
<View testID="RNE__Table__body">
4253
{data.map((item, idx) => {
4354
const key = getRowKey(item);
44-
return (
45-
<BodyRow
46-
key={key}
47-
columns={columns}
48-
record={item}
49-
/>
50-
);
55+
return <BodyRow key={key} columns={columns} record={item} />;
5156
})}
5257
</View>
5358
{data.length === 0 && <Text style={styles.noDataText}>暂无数据...</Text>}
@@ -56,42 +61,49 @@ const Table = ({ data, columns, rowKey, horizontal = true, style }: TableProps)
5661
);
5762
};
5863

59-
const styles = StyleSheet.create({
60-
title: {
61-
backgroundColor: colors.white,
62-
height: 30,
63-
},
64-
conTitle: {
65-
flexDirection: 'row',
66-
borderWidth: 1,
67-
borderColor: colors.colorsPalette.dark70,
68-
},
69-
content: {
70-
color: colors.colorsPalette.dark30,
71-
},
72-
contRight: {
73-
borderRightWidth: 1,
74-
borderRightColor: colors.colorsPalette.dark70,
75-
borderBottomColor: colors.colorsPalette.dark70,
76-
color: '#888888',
77-
flexDirection: 'row',
78-
alignItems: 'center',
79-
justifyContent: 'center',
80-
paddingTop: 5,
81-
paddingBottom: 5,
82-
},
83-
conW: {
84-
backgroundColor: colors.white,
85-
},
86-
noDataText: {
87-
color: '#888888',
88-
textAlign: 'center',
89-
paddingTop: 4,
90-
paddingBottom: 4,
91-
},
92-
titleFlex: {
93-
flex: 1
94-
}
95-
});
64+
type CreStyle = {
65+
bgColor: string;
66+
textColor: string;
67+
};
68+
69+
function createStyles({ bgColor, textColor }: CreStyle) {
70+
return StyleSheet.create({
71+
title: {
72+
backgroundColor: colors.white,
73+
height: 30,
74+
},
75+
conTitle: {
76+
flexDirection: 'row',
77+
borderWidth: 1,
78+
borderColor: colors.colorsPalette.dark70,
79+
},
80+
content: {
81+
color: textColor,
82+
},
83+
contRight: {
84+
borderRightWidth: 1,
85+
borderRightColor: colors.colorsPalette.dark70,
86+
borderBottomColor: colors.colorsPalette.dark70,
87+
color: '#888888',
88+
flexDirection: 'row',
89+
alignItems: 'center',
90+
justifyContent: 'center',
91+
paddingTop: 5,
92+
paddingBottom: 5,
93+
},
94+
conW: {
95+
backgroundColor: bgColor,
96+
},
97+
noDataText: {
98+
color: '#888888',
99+
textAlign: 'center',
100+
paddingTop: 4,
101+
paddingBottom: 4,
102+
},
103+
titleFlex: {
104+
flex: 1,
105+
},
106+
});
107+
}
96108

97109
export default Table;

0 commit comments

Comments
 (0)