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 {LayoutAnimation} from 'react-native'
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} from '#/alf'
import {Button, ButtonText} from '#/components/Button'
import {atoms as a, flatten, type TextStyleProp,useTheme} from '#/alf'
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 onPress = useCallback(() => {
@@ -15,17 +20,36 @@ export function ShowMore({onPress: onPressProp}: {onPress: () => void}) {
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}
color="primary"
variant="ghost"
style={[a.self_start, a.my_xs, a.rounded_2xs]}
style={[
a.self_start,
{
paddingBottom: textStyle.fontSize / 3,
},
]}
hitSlop={HITSLOP_10}>
<ButtonText>
<Trans>Show More</Trans>
</ButtonText>
{({pressed, hovered}) => (
<Text
style={[
textStyle,
{
color: t.palette.primary_500,
opacity: pressed || hovered ? 0.6 : 1,
},
]}>
<Trans>Show More</Trans>
</Text>
)}
</Button>
)
}
@@ -300,16 +300,20 @@ const ThreadItemPostInner = memo(function ThreadItemPostInner({
additionalCauses={additionalPostAlerts}
/>
{richText?.text ? (
<RichText
enableTags
value={richText}
style={[a.flex_1, a.text_md]}
numberOfLines={limitLines ? MAX_POST_LINES : undefined}
authorHandle={post.author.handle}
shouldProxyLinks={true}
/>
<>
<RichText
enableTags
value={richText}
style={[a.flex_1, a.text_md]}
numberOfLines={limitLines ? MAX_POST_LINES : undefined}
authorHandle={post.author.handle}
shouldProxyLinks={true}
/>
{limitLines && (
<ShowMore style={[a.text_md]} onPress={onPressShowMore} />
)}
</>
) : undefined}
{limitLines && <ShowMore onPress={onPressShowMore} />}
{post.embed && (
<View style={[a.pb_xs]}>
<PostEmbeds
@@ -344,7 +344,7 @@ const ThreadItemTreePostInner = memo(function ThreadItemTreePostInner({
additionalCauses={additionalPostAlerts}
/>
{richText?.text ? (
<View>
<>
<RichText
enableTags
value={richText}
@@ -353,9 +353,14 @@ const ThreadItemTreePostInner = memo(function ThreadItemTreePostInner({
authorHandle={post.author.handle}
shouldProxyLinks={true}
/>
</View>
{limitLines && (
<ShowMore
style={[a.text_md]}
onPress={onPressShowMore}
/>
)}
</>
) : undefined}
{limitLines && <ShowMore onPress={onPressShowMore} />}
{post.embed && (
<View style={[a.pb_xs]}>
<PostEmbeds
+3 -1
View File
@@ -686,9 +686,11 @@ let PostThreadItemLoaded = ({
authorHandle={post.author.handle}
shouldProxyLinks={true}
/>
{limitLines && (
<ShowMore style={[a.text_md]} onPress={onPressShowMore} />
)}
</View>
) : undefined}
{limitLines && <ShowMore onPress={onPressShowMore} />}
{post.embed && (
<View style={[a.pb_xs]}>
<PostEmbeds
+4 -8
View File
@@ -226,7 +226,7 @@ function PostInner({
style={[a.py_xs]}
/>
{richText.text ? (
<View style={styles.postTextContainer}>
<View>
<RichText
enableTags
testID="postText"
@@ -236,9 +236,11 @@ function PostInner({
authorHandle={post.author.handle}
shouldProxyLinks={true}
/>
{limitLines && (
<ShowMore style={[a.text_md]} onPress={onPressShowMore} />
)}
</View>
) : undefined}
{limitLines && <ShowMore onPress={onPressShowMore} />}
{post.embed ? (
<PostEmbeds
embed={post.embed}
@@ -282,12 +284,6 @@ const styles = StyleSheet.create({
alert: {
marginBottom: 6,
},
postTextContainer: {
flexDirection: 'row',
alignItems: 'center',
flexWrap: 'wrap',
overflow: 'hidden',
},
replyLine: {
position: 'absolute',
left: 36,
+5 -10
View File
@@ -545,7 +545,7 @@ let PostContent = ({
additionalCauses={additionalPostAlerts}
/>
{richText.text ? (
<View style={styles.postTextContainer}>
<>
<RichText
enableTags
testID="postText"
@@ -555,9 +555,11 @@ let PostContent = ({
authorHandle={postAuthor.handle}
shouldProxyLinks={true}
/>
</View>
{limitLines && (
<ShowMore style={[a.text_md]} onPress={onPressShowMore} />
)}
</>
) : undefined}
{limitLines && <ShowMore onPress={onPressShowMore} />}
{postEmbed ? (
<View style={[a.pb_xs]}>
<PostEmbeds
@@ -680,13 +682,6 @@ const styles = StyleSheet.create({
marginTop: 6,
marginBottom: 6,
},
postTextContainer: {
flexDirection: 'row',
alignItems: 'center',
flexWrap: 'wrap',
paddingBottom: 2,
overflow: 'hidden',
},
contentHiderChild: {
marginTop: 6,
},