tooot/src/components/Timelines/Timeline/Shared/Content.tsx

87 lines
2.5 KiB
TypeScript
Raw Normal View History

2020-10-29 14:52:28 +01:00
import React, { useState } from 'react'
2020-12-12 18:44:27 +01:00
import { Pressable, Text } from 'react-native'
2020-10-29 14:52:28 +01:00
import Collapsible from 'react-native-collapsible'
2020-12-13 14:04:25 +01:00
import ParseContent from '@components/ParseContent'
2020-10-29 14:52:28 +01:00
2020-12-13 14:04:25 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
import { StyleConstants } from '@utils/styles/constants'
2020-12-12 18:44:27 +01:00
import { LinearGradient } from 'expo-linear-gradient'
2020-11-23 00:07:32 +01:00
2020-10-31 21:04:46 +01:00
export interface Props {
2020-12-03 01:28:56 +01:00
status: Mastodon.Status
2020-12-02 00:16:27 +01:00
numberOfLines?: number
2020-12-12 22:19:18 +01:00
highlighted?: boolean
2020-10-31 21:04:46 +01:00
}
2020-12-12 22:19:18 +01:00
const TimelineContent: React.FC<Props> = ({
status,
numberOfLines,
highlighted = false
}) => {
2020-11-23 00:07:32 +01:00
const { theme } = useTheme()
2020-10-29 14:52:28 +01:00
const [spoilerCollapsed, setSpoilerCollapsed] = useState(true)
2020-12-12 18:44:27 +01:00
const lineHeight = 28
2020-10-29 14:52:28 +01:00
return (
<>
2020-12-03 01:28:56 +01:00
{status.spoiler_text ? (
<>
2020-12-12 18:44:27 +01:00
<ParseContent
content={status.spoiler_text}
2020-12-12 22:19:18 +01:00
size={highlighted ? 'L' : 'M'}
2020-12-12 18:44:27 +01:00
emojis={status.emojis}
/>
<Collapsible collapsed={spoilerCollapsed} collapsedHeight={20}>
2020-12-03 01:28:56 +01:00
<ParseContent
content={status.content}
2020-12-12 22:19:18 +01:00
size={highlighted ? 'L' : 'M'}
2020-12-03 01:28:56 +01:00
emojis={status.emojis}
mentions={status.mentions}
{...(numberOfLines && { numberOfLines: numberOfLines })}
/>
</Collapsible>
2020-12-12 18:44:27 +01:00
<Pressable
onPress={() => setSpoilerCollapsed(!spoilerCollapsed)}
style={{
marginTop: spoilerCollapsed ? -lineHeight : 0
}}
>
<LinearGradient
colors={[
theme.backgroundGradientStart,
theme.backgroundGradientEnd
]}
locations={[0, lineHeight / (StyleConstants.Font.Size.S * 5)]}
style={{
paddingTop: StyleConstants.Font.Size.S * 2,
paddingBottom: StyleConstants.Font.Size.S
}}
>
<Text
style={{
textAlign: 'center',
fontSize: StyleConstants.Font.Size.S,
color: theme.primary
}}
>
{spoilerCollapsed ? '展开' : '收起'}
</Text>
</LinearGradient>
</Pressable>
2020-12-03 01:28:56 +01:00
</>
) : (
<ParseContent
content={status.content}
2020-12-12 22:19:18 +01:00
size={highlighted ? 'L' : 'M'}
2020-12-03 01:28:56 +01:00
emojis={status.emojis}
mentions={status.mentions}
{...(numberOfLines && { numberOfLines: numberOfLines })}
/>
)}
2020-10-29 14:52:28 +01:00
</>
)
}
2020-12-03 01:28:56 +01:00
export default React.memo(TimelineContent, () => true)