Update posts in feed to use the theming system

This commit is contained in:
Paul Frazee 2022-12-28 19:20:02 -06:00
parent 8f55e3149e
commit 607203134e
9 changed files with 133 additions and 82 deletions

View file

@ -2,9 +2,9 @@ import React from 'react'
import {TextStyle, StyleProp} from 'react-native'
import {TextLink} from '../Link'
import {Text} from './Text'
import {s} from '../../../lib/styles'
import {lh} from '../../../lib/styles'
import {toShortUrl} from '../../../../lib/strings'
import {TypographyVariant} from '../../../lib/ThemeContext'
import {useTheme, TypographyVariant} from '../../../lib/ThemeContext'
import {usePalette} from '../../../lib/hooks/usePalette'
type TextSlice = {start: number; end: number}
@ -21,22 +21,24 @@ export function RichText({
style,
numberOfLines,
}: {
type: TypographyVariant
type?: TypographyVariant
text: string
entities?: Entity[]
style?: StyleProp<TextStyle>
numberOfLines?: number
}) {
const theme = useTheme()
const pal = usePalette('default')
const lineHeightStyle = lh(theme, 'body1', 1.2)
if (!entities?.length) {
if (/^\p{Extended_Pictographic}+$/u.test(text) && text.length <= 5) {
style = {
fontSize: 26,
lineHeight: 30,
}
return <Text style={style}>{text}</Text>
return <Text style={[style, pal.text]}>{text}</Text>
}
return <Text style={style}>{text}</Text>
return <Text style={[style, pal.text, lineHeightStyle]}>{text}</Text>
}
if (!style) style = []
else if (!Array.isArray(style)) style = [style]
@ -55,7 +57,7 @@ export function RichText({
type={type}
text={segment.text}
href={`/profile/${segment.entity.value}`}
style={[style, pal.link]}
style={[style, lineHeightStyle, pal.link]}
/>,
)
} else if (segment.entity.type === 'link') {
@ -65,7 +67,7 @@ export function RichText({
type={type}
text={toShortUrl(segment.text)}
href={segment.entity.value}
style={[style, pal.link]}
style={[style, lineHeightStyle, pal.link]}
/>,
)
}
@ -73,7 +75,10 @@ export function RichText({
key++
}
return (
<Text type={type} style={[pal.text, style]} numberOfLines={numberOfLines}>
<Text
type={type}
style={[style, pal.text, lineHeightStyle]}
numberOfLines={numberOfLines}>
{els}
</Text>
)