import * as React from 'react'; import { SectionListData, View } from 'react-native'; import type { BlockModel } from '../../chat'; import { useColors } from '../../hook'; import { usePaletteContext } from '../../theme'; import { PressableHighlight } from '../../ui/Pressable'; import { SingleLineText } from '../../ui/Text'; import { Avatar } from '../Avatar'; import { IndexModel } from '../ListIndex'; import type { BlockListItemProps } from './types'; /** * Block list item component. */ export function BlockListItem(props: BlockListItemProps) { const { section, onClicked, onLongPressed } = props; const { colors } = usePaletteContext(); const { getColor } = useColors({ fg2: { light: colors.neutral[5], dark: colors.neutral[6], }, }); const getNickName = React.useCallback((section: BlockModel) => { if (section.remark && section.remark.length > 0) { return section.remark; } else if (section.userName && section.userName.length > 0) { return section.userName; } else { return section.userId; } }, []); return ( { onClicked?.(section); }} onLongPress={() => { onLongPressed?.(section); }} > {getNickName(section)} ); } export const BlockListItemMemo = React.memo(BlockListItem); /** * Block list item header component. */ export function BlockListItemHeader( props: SectionListData ) { const { indexTitle } = props; const { colors } = usePaletteContext(); const { getColor } = useColors({ fg2: { light: colors.neutral[5], dark: colors.neutral[6], }, }); return ( {indexTitle} ); } export const BlockListItemHeaderMemo = React.memo(BlockListItemHeader);