diff options
author | Samuel Newman <mozzius@protonmail.com> | 2025-06-14 00:43:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-13 16:43:17 -0500 |
commit | 00469314ca2f76bf13d0526afdd6c9253c0953d1 (patch) | |
tree | b21d41d3eac86d3c135c9d701f65a1be47d09ee4 /src/components/Post/ShowMoreTextButton.tsx | |
parent | ed9691511beb26bdb799bbcb9a973a8b8df3433c (diff) | |
download | voidsky-00469314ca2f76bf13d0526afdd6c9253c0953d1.tar.zst |
Use Button instead of TextLink for show more button (#8480)
* use button instead of TextLink for show more * Match post text size, provide interaction feedback * Move to new Post components dir * Prettier --------- Co-authored-by: Eric Bailey <git@esb.lol>
Diffstat (limited to 'src/components/Post/ShowMoreTextButton.tsx')
-rw-r--r-- | src/components/Post/ShowMoreTextButton.tsx | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/components/Post/ShowMoreTextButton.tsx b/src/components/Post/ShowMoreTextButton.tsx new file mode 100644 index 000000000..bc6db55b9 --- /dev/null +++ b/src/components/Post/ShowMoreTextButton.tsx @@ -0,0 +1,56 @@ +import {useCallback, useMemo} from 'react' +import {LayoutAnimation, type TextStyle} from 'react-native' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' + +import {HITSLOP_10} from '#/lib/constants' +import {atoms as a, flatten, type TextStyleProp, useTheme} from '#/alf' +import {Button} from '#/components/Button' +import {Text} from '#/components/Typography' + +export function ShowMoreTextButton({ + onPress: onPressProp, + style, +}: TextStyleProp & {onPress: () => void}) { + const t = useTheme() + const {_} = useLingui() + + const onPress = useCallback(() => { + LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) + onPressProp() + }, [onPressProp]) + + const textStyle = useMemo(() => { + return flatten([a.leading_snug, a.text_sm, style]) as TextStyle & { + fontSize: number + lineHeight: number + } + }, [style]) + + return ( + <Button + label={_(msg`Expand post text`)} + onPress={onPress} + style={[ + a.self_start, + { + paddingBottom: textStyle.fontSize / 3, + }, + ]} + hitSlop={HITSLOP_10}> + {({pressed, hovered}) => ( + <Text + style={[ + textStyle, + { + color: t.palette.primary_500, + opacity: pressed ? 0.6 : 1, + textDecorationLine: hovered ? 'underline' : undefined, + }, + ]}> + <Trans>Show More</Trans> + </Text> + )} + </Button> + ) +} |