-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(TimeLine): 重构时间轴 & 新增自定义渲染 (#629)
- Loading branch information
1 parent
585f7f0
commit dce305b
Showing
11 changed files
with
908 additions
and
195 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { View, Text, StyleSheet } from 'react-native'; | ||
import { useTheme } from '@shopify/restyle'; | ||
import { Theme } from '../theme'; | ||
|
||
interface DescProps { | ||
desc?: string | string[]; | ||
theme: Theme; | ||
} | ||
|
||
export const Desc = ({ desc, theme }: DescProps) => { | ||
const styles = createStyles({ | ||
desc: theme.colors.text, | ||
}); | ||
|
||
if (Array.isArray(desc) && desc.length) { | ||
const descs: string[] = desc as string[]; | ||
return ( | ||
<View> | ||
{descs.map((item, index) => ( | ||
<Text style={styles.desc} key={index}> | ||
{item} | ||
</Text> | ||
))} | ||
</View> | ||
); | ||
} | ||
return <Text style={styles.desc}>{desc}</Text>; | ||
}; | ||
|
||
function createStyles({ desc = '#5e6d82' }) { | ||
return StyleSheet.create({ | ||
desc: { | ||
color: desc, | ||
fontSize: 14, | ||
marginTop: 10, | ||
lineHeight: 20, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Fragment } from 'react'; | ||
import Icon, { IconsName } from '../Icon'; | ||
import { Theme } from '../theme'; | ||
import type { TimelineItemsIcons } from './types'; | ||
|
||
interface IconCustomProps { | ||
icon?: TimelineItemsIcons; | ||
size?: number; | ||
color?: string; | ||
theme: Theme; | ||
} | ||
|
||
export const IconCustom = (props: IconCustomProps) => { | ||
const { icon, size, color, theme } = props; | ||
|
||
if (icon) { | ||
if (typeof icon === 'string') { | ||
return <Icon name={icon as IconsName} size={size ? size : 15} color={color ? color : 'red'} />; | ||
} | ||
return <Fragment>{icon}</Fragment>; | ||
} | ||
return ( | ||
<Icon | ||
name="circle-o" | ||
size={size ? size : 15} | ||
color={color ? color : theme.colors.primary_background || '#3578e5'} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import { Fragment } from 'react'; | ||
import { View, Text, StyleSheet, ViewProps } from 'react-native'; | ||
import { IconCustom } from './Icons'; | ||
import { Desc } from './Desc'; | ||
import { useTheme } from '@shopify/restyle'; | ||
import { Theme } from '../theme'; | ||
import type { TimelineItemsProps, TimelineItemsMode, TimelineProps } from './types'; | ||
|
||
interface LineItemProps { | ||
item: TimelineItemsProps; | ||
mode?: TimelineItemsMode; | ||
end?: boolean; | ||
index: number; | ||
renderItem?: TimelineProps['renderItem']; | ||
} | ||
|
||
export const Items = (props: LineItemProps) => { | ||
const theme = useTheme<Theme>(); | ||
const { item, end, mode, index, renderItem } = props; | ||
|
||
const styles = createStyles({ | ||
backgroundColor: theme.colors.mask, | ||
title: theme.colors.primary_text, | ||
line: theme.colors.primary_text, | ||
tips: theme.colors.primary_text, | ||
}); | ||
|
||
const render = () => { | ||
if (item.renderItem) { | ||
return item.renderItem(item, index); | ||
} else if (renderItem) { | ||
return renderItem(item, index); | ||
} | ||
return ( | ||
<Fragment> | ||
<View> | ||
<Text style={styles.title}>{item.title}</Text> | ||
</View> | ||
{item.tips && <Text style={styles.tips}>{item.tips}</Text>} | ||
{item.desc && <Desc theme={theme} desc={item.desc} />} | ||
</Fragment> | ||
); | ||
}; | ||
|
||
return ( | ||
<View | ||
style={[ | ||
styles.item, | ||
mode === 'left' && styles.itemLeft, | ||
mode === 'alternate' && index % 2 === 0 && styles.itemEnd, | ||
]} | ||
> | ||
<View style={[styles.left, mode === 'alternate' && styles.leftAlternate]}> | ||
{!end && <View style={styles.line} />} | ||
<View style={styles.icons}> | ||
<IconCustom theme={theme} icon={item.icon} size={item.size} color={item.color} /> | ||
</View> | ||
</View> | ||
|
||
<View | ||
style={[ | ||
!mode && styles.content, | ||
mode === 'left' && styles.contentLeft, | ||
mode === 'alternate' && styles.contentAlternate, | ||
mode === 'alternate' && index % 2 !== 0 && styles.contentAlternateLeft, | ||
mode === 'alternate' && index % 2 === 0 && styles.contentAlternateRight, | ||
]} | ||
> | ||
{render()} | ||
</View> | ||
</View> | ||
); | ||
}; | ||
|
||
function createStyles({ backgroundColor = '', title = '#666', tips = '#666', line = '#e4e7ed' }) { | ||
return StyleSheet.create({ | ||
item: { | ||
position: 'relative', | ||
paddingBottom: 20, | ||
display: 'flex', | ||
flexDirection: 'row', | ||
}, | ||
itemLeft: { | ||
flexDirection: 'row-reverse', | ||
}, | ||
itemEnd: { | ||
justifyContent: 'flex-end', | ||
}, | ||
|
||
left: { | ||
width: 24, | ||
position: 'relative', | ||
}, | ||
leftAlternate: { | ||
position: 'absolute', | ||
left: '50%', | ||
marginLeft: -12, | ||
top: 5, | ||
bottom: 10, | ||
}, | ||
content: { | ||
paddingLeft: 12, | ||
paddingRight: 12, | ||
flex: 1, | ||
}, | ||
contentLeft: { | ||
flex: 1, | ||
paddingLeft: 12, | ||
paddingRight: 12, | ||
alignItems: 'flex-end', | ||
}, | ||
contentAlternate: { | ||
paddingLeft: 12, | ||
paddingRight: 12, | ||
width: '47%', | ||
}, | ||
contentAlternateLeft: { | ||
alignItems: 'flex-end', | ||
textAlign: 'right', | ||
}, | ||
contentAlternateRight: {}, | ||
icons: { | ||
width: 24, | ||
display: 'flex', | ||
alignItems: 'center', | ||
}, | ||
|
||
line: { | ||
position: 'absolute', | ||
left: 12, | ||
top: 22, | ||
bottom: -17, | ||
width: 1, | ||
backgroundColor: line, | ||
}, | ||
wrapper: { | ||
paddingLeft: 20, | ||
}, | ||
top: {}, | ||
tips: { | ||
color: tips, | ||
marginTop: 8, | ||
}, | ||
title: { | ||
fontSize: 15, | ||
lineHeight: 20, | ||
color: title, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.