Skip to content

Commit ed876de

Browse files
Amber-Nan杨楠
and
杨楠
authored
feat(Timeline):优化自定义图标 & 文档更新 (#329)
* fix(Divider):优化 gutter属性不生效问题 * feat(Divider): 增加分割线标题的位置调整功能 & 更新文档 * feat(Rating):增加自定义每项的提示信息 & 更新文档 * feat(Rating):增加只读功能 & 文档更新 * feat(Timeline): 增加改变时间轴内容相对位置功能 & 文档更新 * style(Timeline):Update Readme.md img * feat(Timeline):增加自定义图标 & 文档更新 * feat(Timeline):优化自定义图标 & 文档更新 Co-authored-by: 杨楠 <[email protected]>
1 parent 7e3755b commit ed876de

File tree

4 files changed

+50
-42
lines changed

4 files changed

+50
-42
lines changed

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ export default (props: StepsViewProps) => {
2020
{
2121
title: '组件化',
2222
desc: '构建管理自身状态的封装组件,然后对其组合以构成复杂的 UI。',
23-
icon: {
24-
name: 'warning',
25-
size: 20,
26-
color: 'blue',
27-
},
2823
},
2924
{
3025
title: '一次学习,随处编写',
@@ -39,27 +34,27 @@ export default (props: StepsViewProps) => {
3934
title: '声明式声明式',
4035
tips: '2021-08-07 12:00:00',
4136
desc: 'React 使创建交互式',
42-
icon: {
43-
color: 'red',
44-
},
37+
icon: <Icon name="smile" fill="red" size={18} />,
4538
},
4639
{
4740
title: '组件化',
4841
tips: '2021-08-08 12:00:00',
4942
desc: '构建管理自身状态。',
50-
icon: {
51-
color: 'green',
52-
},
43+
size: 20,
44+
color: 'blue',
45+
icon: 'qq',
5346
},
5447
{
5548
title: '随处编写',
5649
tips: '2021-08-09 12:00:00',
5750
desc: '服务器渲染。',
51+
color: 'green',
5852
},
5953
{
6054
title: '一次学习,随处编写',
6155
tips: '2021-08-10 12:00:00',
6256
desc: '开发新功能。',
57+
size: 30,
6358
},
6459
];
6560

@@ -70,7 +65,7 @@ export default (props: StepsViewProps) => {
7065
description={route.params.description}
7166
/>
7267
<Body>
73-
<Card title={`基础用法 & 自定义图标`}>
68+
<Card title="基础用法">
7469
<WingBlank>
7570
<Timeline style={{backgroundColor: '#fff'}} items={item} />
7671
</WingBlank>
@@ -84,7 +79,7 @@ export default (props: StepsViewProps) => {
8479
/>
8580
</WingBlank>
8681
</Card>
87-
<Card title="交替展现">
82+
<Card title={`交替展现 & 自定义图标`}>
8883
<WingBlank>
8984
<Timeline
9085
style={{backgroundColor: '#fff'}}

packages/core/src/Timeline/README.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ import { Timeline } from '@uiw/react-native';
1010

1111
function Demo() {
1212
const item = [
13-
{
14-
title: '声明式声明式声明式声',
13+
{
14+
title: '声明式声明式',
1515
tips: '2021-08-07 12:00:00',
16-
desc: 'React 使创建交互式 UI 变得轻而易举。为你应用的每一个状态设计简洁的视图,当数据变动时 React 能高效更新并渲染合适的组件。',
17-
icon: {
18-
color: 'red'
19-
},
16+
desc: 'React 使创建交互式',
17+
icon: <Icon name="smile" fill="red" size={18} />
2018
},
2119
{
2220
title: '组件化',
23-
desc: '构建管理自身状态的封装组件,然后对其组合以构成复杂的 UI。',
24-
icon: {
25-
name: "warning",
26-
size: 20,
27-
color: 'blue'
28-
},
21+
tips: '2021-08-08 12:00:00',
22+
desc: '构建管理自身状态。',
23+
size: 20,
24+
color: 'blue',
25+
icon: 'qq'
26+
},
27+
{
28+
title: '随处编写',
29+
tips: '2021-08-09 12:00:00',
30+
desc: '服务器渲染。',
2931
},
3032
{
3133
title: '一次学习,随处编写',
32-
desc: [
33-
'无论你现在使用什么技术栈,在无需重写现有代码的前提下,通过引入 React 来开发新功能。',
34-
'React 还可以使用 Node 进行服务器渲染,或使用 React Native 开发原生移动应用。',
35-
],
34+
tips: '2021-08-10 12:00:00',
35+
desc: '开发新功能。',
3636
},
3737
];
3838
return (
@@ -59,7 +59,7 @@ function Demo() {
5959
<WingBlank>
6060
<Timeline
6161
style={{ backgroundColor: '#fff' }}
62-
items={item1}
62+
items={item}
6363
mode="alternate"
6464
/>
6565
</WingBlank>
@@ -98,8 +98,12 @@ export interface TimelineItemsProps {
9898
tips?: string;
9999
/** 子项内容 */
100100
desc?: string | string[];
101-
/** 自定义图标 */
102-
icon?: IconsProps;
101+
/** 自定义图标 */
102+
icon?: IconsName | React.ReactElement | React.ReactNode;
103+
/** 自定义图标颜色 */
104+
color?: string;
105+
/** 自定义图标尺寸 */
106+
size?: number;
103107
}
104108

105109
export interface TimelineProps extends ViewProps {

packages/core/src/Timeline/index.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { useState, useEffect } from 'react';
22
import { View, Text, StyleSheet, ViewProps } from 'react-native';
33
import { TabsItemIconTypes } from '../Tabs/TabsItem';
4-
import Icon, { IconsProps } from '../Icon';
4+
import Icon, { IconsName } from '../Icon';
5+
import { number } from 'prop-types';
56

67
export interface TimelineItemsProps {
78
/** 标题 */
@@ -11,7 +12,11 @@ export interface TimelineItemsProps {
1112
/** 子项内容 */
1213
desc?: string | string[];
1314
/** 自定义图标 */
14-
icon?: IconsProps;
15+
icon?: IconsName | React.ReactElement | React.ReactNode;
16+
/** 自定义图标颜色 */
17+
color?: string;
18+
/** 自定义图标尺寸 */
19+
size?: number;
1520
}
1621

1722
export interface TimelineProps extends ViewProps {
@@ -41,17 +46,19 @@ const Desc = (desc?: string | string[]) => {
4146
}
4247
};
4348

44-
const IconCustom = (icon?: IconsProps) => {
49+
const IconCustom = (icon?: IconsName | React.ReactElement | React.ReactNode, size?: number, color?: string) => {
4550
if (icon) {
4651
return (
47-
<Icon
48-
name={icon?.name ? icon.name : 'circle-o'}
49-
size={icon?.size ? icon.size : 15}
50-
color={icon?.color ? icon.color : '#e4e7ed'}
51-
/>
52+
<>
53+
{typeof icon === 'string' ? (
54+
<Icon name={icon as IconsName} size={size ? size : 15} color={color ? color : 'red'} />
55+
) : (
56+
icon
57+
)}
58+
</>
5259
);
5360
} else {
54-
return <Icon name="circle-o" size={15} color="#e4e7ed" />;
61+
return <Icon name="circle-o" size={size ? size : 15} color={color ? color : '#e4e7ed'} />;
5562
}
5663
};
5764

@@ -76,6 +83,8 @@ export default (props: TimelineProps) => {
7683
} else {
7784
setModeType('90%');
7885
}
86+
} else {
87+
setModeType('0%');
7988
}
8089
}, [isReverse, items]);
8190

@@ -107,7 +116,7 @@ export default (props: TimelineProps) => {
107116

108117
<View style={{ width: mode && mode === 'left' ? '10%' : 0, flexDirection: 'column', alignItems: 'center' }}>
109118
{index < items.length - 1 && <View style={styles.line}></View>}
110-
{IconCustom(item.icon)}
119+
{IconCustom(item.icon, item.size, item.color)}
111120
</View>
112121

113122
<View style={{ width: mode && mode === 'alternate' ? 0 : '90%', flexDirection: 'column' }}>
Loading

0 commit comments

Comments
 (0)