import {Text, View} from 'react-native' import {Trans, useLingui} from '@lingui/react/macro' import {useEnableSquareButtons} from '#/state/preferences/enable-square-buttons' import {atoms as a, ios, platform, useTheme} from '#/alf' import {useNativeFontScale} from '#/alf/util/dimensions' import {type app} from '#/lexicons' /** * Map of Android font scale values to inline offsets. */ const ANDROID_INLINE_OFFSETS = [ [0.85, 2], [1, 4], [1.15, 6], [1.3, 8], [1.5, 10], [1.8, 12], [2, 14], ] as const /** * Max amount the inline badge is nudged below the text baseline. Android's * containing `RichText` reserves matching room via `suffixOffset`. */ export const POST_NUMBER_INLINE_OFFSET = 14 function getAndroidInlineOffset(fontScale: number) { return ANDROID_INLINE_OFFSETS.reduce((nearest, candidate) => Math.abs(candidate[0] - fontScale) < Math.abs(nearest[0] - fontScale) ? candidate : nearest, )[1] } export type ThreadItemPostNumbering = Pick< app.bsky.unspecced.defs.ThreadItemPost, 'opThreadPostIndex' | 'opThreadPostCount' > export function useHasThreadItemPostNumber( value: ThreadItemPostNumbering | undefined, ) { const index = value?.opThreadPostIndex const count = value?.opThreadPostCount return ( 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 square = useEnableSquareButtons() const {t: l} = useLingui() const nativeFontScale = useNativeFontScale() const shouldRender = useHasThreadItemPostNumber(value) const index = value?.opThreadPostIndex const count = value?.opThreadPostCount if (!shouldRender) { return null } return ( {index}/{count} ) }