import {Text, View} from 'react-native' import {Trans, useLingui} from '@lingui/react/macro' import {atoms as a, ios, platform, useTheme} from '#/alf' import {useAnalytics} from '#/analytics' import {type app} from '#/lexicons' /** * How far the inline badge is nudged below the text baseline. Android's * containing `RichText` reserves matching room via `suffixOffset`. */ export const POST_NUMBER_INLINE_OFFSET = 6 export type ThreadItemPostNumbering = Pick< app.bsky.unspecced.defs.ThreadItemPost, 'opThreadPostIndex' | 'opThreadPostCount' > export function useHasThreadItemPostNumber( value: ThreadItemPostNumbering | undefined, ) { const ax = useAnalytics() const index = value?.opThreadPostIndex const count = value?.opThreadPostCount return ( ax.features.enabled(ax.features.CanonicalPostNumberingEnable) && index !== undefined && count !== undefined && index >= 1 && count >= 1 && index <= count ) } export function ThreadItemPostNumber({ value, inline = true, }: { value: ThreadItemPostNumbering | undefined inline?: boolean }) { const t = useTheme() const {t: l} = useLingui() const shouldRender = useHasThreadItemPostNumber(value) const index = value?.opThreadPostIndex const count = value?.opThreadPostCount if (!shouldRender) { return null } return ( {index}/{count} ) }