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

62 lines
1.5 KiB
TypeScript
Raw Normal View History

2020-10-29 14:52:28 +01:00
import React, { useState } from 'react'
import { Text } from 'react-native'
import Collapsible from 'react-native-collapsible'
import ParseContent from 'src/components/ParseContent'
2020-11-23 00:07:32 +01:00
import constants from 'src/utils/styles/constants'
import { useTheme } from 'src/utils/styles/ThemeManager'
2020-10-31 21:04:46 +01:00
export interface Props {
content: string
emojis: Mastodon.Emoji[]
mentions: Mastodon.Mention[]
2020-10-31 21:04:46 +01:00
spoiler_text?: string
}
const Content: React.FC<Props> = ({
content,
emojis,
mentions,
spoiler_text
}) => {
2020-11-23 00:07:32 +01:00
const { theme } = useTheme()
2020-10-29 14:52:28 +01:00
const [spoilerCollapsed, setSpoilerCollapsed] = useState(true)
return (
<>
{content &&
(spoiler_text ? (
<>
<Text>
{spoiler_text}{' '}
2020-11-23 00:07:32 +01:00
<Text
onPress={() => setSpoilerCollapsed(!spoilerCollapsed)}
style={{ color: theme.link }}
>
{spoilerCollapsed ? '点击展开' : '点击收起'}
2020-10-29 14:52:28 +01:00
</Text>
</Text>
<Collapsible collapsed={spoilerCollapsed}>
<ParseContent
content={content}
2020-11-23 00:07:32 +01:00
size={constants.FONT_SIZE_M}
2020-10-29 14:52:28 +01:00
emojis={emojis}
mentions={mentions}
/>
</Collapsible>
</>
) : (
<ParseContent
content={content}
2020-11-23 00:07:32 +01:00
size={constants.FONT_SIZE_M}
2020-10-29 14:52:28 +01:00
emojis={emojis}
mentions={mentions}
/>
))}
</>
)
}
2020-10-31 21:04:46 +01:00
export default Content