Match post text size, provide interaction feedback

This commit is contained in:
Eric Bailey
2025-06-13 16:13:44 -05:00
parent 7ec4d7b1d5
commit 4d47c1528d
6 changed files with 68 additions and 42 deletions
+35 -11
View File
@@ -1,13 +1,18 @@
import {useCallback} from 'react' import {useCallback, useMemo} from 'react'
import {LayoutAnimation} from 'react-native' import {LayoutAnimation, type TextStyle} from 'react-native'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {HITSLOP_10} from '#/lib/constants' import {HITSLOP_10} from '#/lib/constants'
import {atoms as a} from '#/alf' import {atoms as a, flatten, type TextStyleProp,useTheme} from '#/alf'
import {Button, ButtonText} from '#/components/Button' import {Button} from '#/components/Button'
import {Text} from '#/components/Typography'
export function ShowMore({onPress: onPressProp}: {onPress: () => void}) { export function ShowMore({
onPress: onPressProp,
style,
}: TextStyleProp & {onPress: () => void}) {
const t = useTheme()
const {_} = useLingui() const {_} = useLingui()
const onPress = useCallback(() => { const onPress = useCallback(() => {
@@ -15,17 +20,36 @@ export function ShowMore({onPress: onPressProp}: {onPress: () => void}) {
onPressProp() onPressProp()
}, [onPressProp]) }, [onPressProp])
const textStyle = useMemo(() => {
return flatten([a.leading_snug, a.text_sm, style]) as TextStyle & {
fontSize: number
lineHeight: number
}
}, [style])
return ( return (
<Button <Button
label={_(msg`Expand post text`)} label={_(msg`Expand post text`)}
onPress={onPress} onPress={onPress}
color="primary" style={[
variant="ghost" a.self_start,
style={[a.self_start, a.my_xs, a.rounded_2xs]} {
paddingBottom: textStyle.fontSize / 3,
},
]}
hitSlop={HITSLOP_10}> hitSlop={HITSLOP_10}>
<ButtonText> {({pressed, hovered}) => (
<Trans>Show More</Trans> <Text
</ButtonText> style={[
textStyle,
{
color: t.palette.primary_500,
opacity: pressed || hovered ? 0.6 : 1,
},
]}>
<Trans>Show More</Trans>
</Text>
)}
</Button> </Button>
) )
} }
@@ -300,16 +300,20 @@ const ThreadItemPostInner = memo(function ThreadItemPostInner({
additionalCauses={additionalPostAlerts} additionalCauses={additionalPostAlerts}
/> />
{richText?.text ? ( {richText?.text ? (
<RichText <>
enableTags <RichText
value={richText} enableTags
style={[a.flex_1, a.text_md]} value={richText}
numberOfLines={limitLines ? MAX_POST_LINES : undefined} style={[a.flex_1, a.text_md]}
authorHandle={post.author.handle} numberOfLines={limitLines ? MAX_POST_LINES : undefined}
shouldProxyLinks={true} authorHandle={post.author.handle}
/> shouldProxyLinks={true}
/>
{limitLines && (
<ShowMore style={[a.text_md]} onPress={onPressShowMore} />
)}
</>
) : undefined} ) : undefined}
{limitLines && <ShowMore onPress={onPressShowMore} />}
{post.embed && ( {post.embed && (
<View style={[a.pb_xs]}> <View style={[a.pb_xs]}>
<PostEmbeds <PostEmbeds
@@ -344,7 +344,7 @@ const ThreadItemTreePostInner = memo(function ThreadItemTreePostInner({
additionalCauses={additionalPostAlerts} additionalCauses={additionalPostAlerts}
/> />
{richText?.text ? ( {richText?.text ? (
<View> <>
<RichText <RichText
enableTags enableTags
value={richText} value={richText}
@@ -353,9 +353,14 @@ const ThreadItemTreePostInner = memo(function ThreadItemTreePostInner({
authorHandle={post.author.handle} authorHandle={post.author.handle}
shouldProxyLinks={true} shouldProxyLinks={true}
/> />
</View> {limitLines && (
<ShowMore
style={[a.text_md]}
onPress={onPressShowMore}
/>
)}
</>
) : undefined} ) : undefined}
{limitLines && <ShowMore onPress={onPressShowMore} />}
{post.embed && ( {post.embed && (
<View style={[a.pb_xs]}> <View style={[a.pb_xs]}>
<PostEmbeds <PostEmbeds
+3 -1
View File
@@ -686,9 +686,11 @@ let PostThreadItemLoaded = ({
authorHandle={post.author.handle} authorHandle={post.author.handle}
shouldProxyLinks={true} shouldProxyLinks={true}
/> />
{limitLines && (
<ShowMore style={[a.text_md]} onPress={onPressShowMore} />
)}
</View> </View>
) : undefined} ) : undefined}
{limitLines && <ShowMore onPress={onPressShowMore} />}
{post.embed && ( {post.embed && (
<View style={[a.pb_xs]}> <View style={[a.pb_xs]}>
<PostEmbeds <PostEmbeds
+4 -8
View File
@@ -226,7 +226,7 @@ function PostInner({
style={[a.py_xs]} style={[a.py_xs]}
/> />
{richText.text ? ( {richText.text ? (
<View style={styles.postTextContainer}> <View>
<RichText <RichText
enableTags enableTags
testID="postText" testID="postText"
@@ -236,9 +236,11 @@ function PostInner({
authorHandle={post.author.handle} authorHandle={post.author.handle}
shouldProxyLinks={true} shouldProxyLinks={true}
/> />
{limitLines && (
<ShowMore style={[a.text_md]} onPress={onPressShowMore} />
)}
</View> </View>
) : undefined} ) : undefined}
{limitLines && <ShowMore onPress={onPressShowMore} />}
{post.embed ? ( {post.embed ? (
<PostEmbeds <PostEmbeds
embed={post.embed} embed={post.embed}
@@ -282,12 +284,6 @@ const styles = StyleSheet.create({
alert: { alert: {
marginBottom: 6, marginBottom: 6,
}, },
postTextContainer: {
flexDirection: 'row',
alignItems: 'center',
flexWrap: 'wrap',
overflow: 'hidden',
},
replyLine: { replyLine: {
position: 'absolute', position: 'absolute',
left: 36, left: 36,
+5 -10
View File
@@ -545,7 +545,7 @@ let PostContent = ({
additionalCauses={additionalPostAlerts} additionalCauses={additionalPostAlerts}
/> />
{richText.text ? ( {richText.text ? (
<View style={styles.postTextContainer}> <>
<RichText <RichText
enableTags enableTags
testID="postText" testID="postText"
@@ -555,9 +555,11 @@ let PostContent = ({
authorHandle={postAuthor.handle} authorHandle={postAuthor.handle}
shouldProxyLinks={true} shouldProxyLinks={true}
/> />
</View> {limitLines && (
<ShowMore style={[a.text_md]} onPress={onPressShowMore} />
)}
</>
) : undefined} ) : undefined}
{limitLines && <ShowMore onPress={onPressShowMore} />}
{postEmbed ? ( {postEmbed ? (
<View style={[a.pb_xs]}> <View style={[a.pb_xs]}>
<PostEmbeds <PostEmbeds
@@ -680,13 +682,6 @@ const styles = StyleSheet.create({
marginTop: 6, marginTop: 6,
marginBottom: 6, marginBottom: 6,
}, },
postTextContainer: {
flexDirection: 'row',
alignItems: 'center',
flexWrap: 'wrap',
paddingBottom: 2,
overflow: 'hidden',
},
contentHiderChild: { contentHiderChild: {
marginTop: 6, marginTop: 6,
}, },