import React from 'react' import {TextStyle, StyleProp} from 'react-native' import {RichText as RichTextObj, AppBskyRichtextFacet} from '@atproto/api' import {TextLink} from '../Link' import {Text} from './Text' import {lh} from 'lib/styles' import {toShortUrl} from 'lib/strings/url-helpers' import {useTheme, TypographyVariant} from 'lib/ThemeContext' import {usePalette} from 'lib/hooks/usePalette' import {makeTagLink} from 'lib/routes/links' import {TagMenu, useTagMenuControl} from '#/components/TagMenu' import {isNative} from '#/platform/detection' const WORD_WRAP = {wordWrap: 1} /** * @deprecated use `#/components/RichText` */ export function RichText({ testID, type = 'md', richText, lineHeight = 1.2, style, numberOfLines, selectable, noLinks, }: { testID?: string type?: TypographyVariant richText?: RichTextObj lineHeight?: number style?: StyleProp numberOfLines?: number selectable?: boolean noLinks?: boolean }) { const theme = useTheme() const pal = usePalette('default') const lineHeightStyle = lh(theme, type, lineHeight) if (!richText) { return null } const {text, facets} = richText if (!facets?.length) { if (/^\p{Extended_Pictographic}+$/u.test(text) && text.length <= 5) { style = { fontSize: 26, lineHeight: 30, } return ( // @ts-ignore web only -prf {text} ) } return ( {text} ) } if (!style) { style = [] } else if (!Array.isArray(style)) { style = [style] } const els = [] let key = 0 for (const segment of richText.segments()) { const link = segment.link const mention = segment.mention const tag = segment.tag if ( !noLinks && mention && AppBskyRichtextFacet.validateMention(mention).success ) { els.push( , ) } else if (link && AppBskyRichtextFacet.validateLink(link).success) { if (noLinks) { els.push(toShortUrl(segment.text)) } else { els.push( , ) } } else if ( !noLinks && tag && AppBskyRichtextFacet.validateTag(tag).success ) { els.push( , ) } else { els.push(segment.text) } key++ } return ( {els} ) } function RichTextTag({ text: tag, type, style, lineHeightStyle, selectable, }: { text: string type?: TypographyVariant style?: StyleProp lineHeightStyle?: TextStyle selectable?: boolean }) { const pal = usePalette('default') const control = useTagMenuControl() const open = React.useCallback(() => { control.open() }, [control]) return ( {isNative ? ( ) : ( {tag} )} ) }