This commit is contained in:
xmflsct 2022-08-10 00:46:43 +02:00
parent dba43e248b
commit a2721d21c0
5 changed files with 49 additions and 26 deletions

View File

@ -249,37 +249,23 @@ const ParseHTML = React.memo(
({ children }: any) => { ({ children }: any) => {
const { t } = useTranslation('componentParse') const { t } = useTranslation('componentParse')
const [expandAllow, setExpandAllow] = useState(false) const [totalLines, setTotalLines] = useState<number>()
const [expanded, setExpanded] = useState(highlighted) const [expanded, setExpanded] = useState(highlighted)
return ( return (
<View style={{ overflow: 'hidden' }}> <View style={{ overflow: 'hidden' }}>
<CustomText {typeof totalLines === 'number' ? (
children={children}
onTextLayout={({ nativeEvent }) => {
if (
numberOfLines === 1 ||
nativeEvent.lines.length >= numberOfLines + 5
) {
setExpandAllow(true)
}
}}
numberOfLines={
expandAllow ? (expanded ? 999 : numberOfLines) : undefined
}
selectable={selectable}
/>
{expandAllow ? (
<Pressable <Pressable
accessibilityLabel='' accessibilityLabel={t('HTML.accessibilityHint')}
onPress={() => { onPress={() => {
analytics('status_readmore', { allow: expandAllow, expanded }) analytics('status_readmore', { totalLines, expanded })
layoutAnimation() layoutAnimation()
setExpanded(!expanded) setExpanded(!expanded)
}} }}
style={{ style={{
flexDirection: 'row',
justifyContent: 'center', justifyContent: 'center',
marginTop: expanded ? 0 : -adaptedLineheight, alignItems: 'center',
minHeight: 44, minHeight: 44,
backgroundColor: colors.backgroundDefault backgroundColor: colors.backgroundDefault
}} }}
@ -288,14 +274,47 @@ const ParseHTML = React.memo(
style={{ style={{
textAlign: 'center', textAlign: 'center',
...StyleConstants.FontStyle.S, ...StyleConstants.FontStyle.S,
color: colors.primaryDefault color: colors.primaryDefault,
marginRight: StyleConstants.Spacing.S
}} }}
children={t(`HTML.expanded.${expanded.toString()}`, { children={t(`HTML.expanded.${expanded.toString()}`, {
hint: expandHint hint: expandHint,
totalLines:
numberOfLines > 1 && typeof totalLines === 'number'
? t('HTML.totalLines', { count: totalLines })
: ''
})} })}
/> />
<Icon
name={expanded ? 'Minimize2' : 'Maximize2'}
color={colors.primaryDefault}
strokeWidth={2}
size={StyleConstants.Font.Size[size]}
/>
</Pressable> </Pressable>
) : null} ) : null}
<CustomText
children={children}
onTextLayout={({ nativeEvent }) => {
if (
numberOfLines === 1 ||
nativeEvent.lines.length >= numberOfLines + 5
) {
setTotalLines(nativeEvent.lines.length)
}
}}
style={{
height: numberOfLines === 1 && !expanded ? 0 : undefined
}}
numberOfLines={
typeof totalLines === 'number'
? expanded
? 999
: numberOfLines
: undefined
}
selectable={selectable}
/>
</View> </View>
) )
}, },

View File

@ -5,6 +5,7 @@ import TimelineAttachment from '@components/Timeline/Shared/Attachment'
import TimelineAvatar from '@components/Timeline/Shared/Avatar' import TimelineAvatar from '@components/Timeline/Shared/Avatar'
import TimelineCard from '@components/Timeline/Shared/Card' import TimelineCard from '@components/Timeline/Shared/Card'
import TimelineContent from '@components/Timeline/Shared/Content' import TimelineContent from '@components/Timeline/Shared/Content'
// @ts-ignore
import TimelineHeaderDefault from '@components/Timeline/Shared/HeaderDefault' import TimelineHeaderDefault from '@components/Timeline/Shared/HeaderDefault'
import TimelinePoll from '@components/Timeline/Shared/Poll' import TimelinePoll from '@components/Timeline/Shared/Poll'
import { useNavigation } from '@react-navigation/native' import { useNavigation } from '@react-navigation/native'

View File

@ -5,6 +5,7 @@ import TimelineAttachment from '@components/Timeline/Shared/Attachment'
import TimelineAvatar from '@components/Timeline/Shared/Avatar' import TimelineAvatar from '@components/Timeline/Shared/Avatar'
import TimelineCard from '@components/Timeline/Shared/Card' import TimelineCard from '@components/Timeline/Shared/Card'
import TimelineContent from '@components/Timeline/Shared/Content' import TimelineContent from '@components/Timeline/Shared/Content'
// @ts-ignore
import TimelineHeaderNotification from '@components/Timeline/Shared/HeaderNotification' import TimelineHeaderNotification from '@components/Timeline/Shared/HeaderNotification'
import TimelinePoll from '@components/Timeline/Shared/Poll' import TimelinePoll from '@components/Timeline/Shared/Poll'
import { useNavigation } from '@react-navigation/native' import { useNavigation } from '@react-navigation/native'

View File

@ -1,9 +1,11 @@
{ {
"HTML": { "HTML": {
"accessibilityHint": "Tap to expand or collapse content",
"expanded": { "expanded": {
"true": "Fold {{hint}}", "true": "{{hint}}{{totalLines}}",
"false": "Expand {{hint}}" "false": "{{hint}}{{totalLines}}"
}, },
"defaultHint": "article" "totalLines": " ({{count}} lines)",
"defaultHint": "Long toot"
} }
} }

View File

@ -81,7 +81,7 @@
"accessibilityHint": "Tap to go to {{name}}'s page" "accessibilityHint": "Tap to go to {{name}}'s page"
}, },
"content": { "content": {
"expandHint": "hidden content" "expandHint": "Hidden content"
}, },
"filtered": "Filtered", "filtered": "Filtered",
"fullConversation": "Read conversations", "fullConversation": "Read conversations",