import * as React from 'react';
import { SectionListData, View } from 'react-native';
import type { ContactModel } from '../../chat';
import { useColors } from '../../hook';
import { useI18nContext } from '../../i18n';
import { usePaletteContext } from '../../theme';
import { IconButton, Text2Button } from '../../ui/Button';
import { Icon } from '../../ui/Image';
import { PressableHighlight } from '../../ui/Pressable';
import { SingleLineText } from '../../ui/Text';
import { Avatar } from '../Avatar';
import type { IndexModel } from '../ListIndex';
import { ListItem } from '../ListItem';
import type { ContactItemProps, ContactListItemProps } from './types';
/**
* Contact list item component.
*/
export function ContactListItem(props: ContactListItemProps) {
const {
section,
onClicked,
onCheckClicked,
onLongPressed,
contactType,
onForwardClicked,
} = props;
const { checked, disable, forwarded } = section;
const { tr } = useI18nContext();
const { colors } = usePaletteContext();
const { getColor } = useColors({
btn_bg: {
light: colors.neutral[95],
dark: colors.neutral[2],
},
right: {
light: colors.neutral[95],
dark: colors.neutral[2],
},
});
const _onForwardClicked = React.useCallback(() => {
if (contactType === 'forward-message' && forwarded !== true) {
onForwardClicked?.(section);
}
}, [contactType, forwarded, onForwardClicked, section]);
const getNickName = React.useCallback((section: ContactModel) => {
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 (
{
if (contactType === 'forward-message') {
return;
}
if (checked !== undefined) {
if (disable !== true) {
onCheckClicked?.(section);
}
} else {
onClicked?.(section);
}
}}
onLongPress={() => {
if (contactType === 'forward-message') {
return;
}
onLongPressed?.(section);
}}
>
{checked !== undefined ? (
{
if (disable !== true) {
onCheckClicked?.(section);
}
}}
/>
) : null}
{getNickName(section)}
{contactType === 'forward-message' ? (
<>
>
) : null}
);
}
export const ContactListItemMemo = React.memo(ContactListItem);
/**
* Contact list item header component.
*/
export function ContactListItemHeader(
props: SectionListData
) {
const { indexTitle } = props;
const { colors } = usePaletteContext();
const { getColor } = useColors({
t2: {
light: colors.neutral[5],
dark: colors.neutral[6],
},
});
return (
{indexTitle}
);
}
export const ContactListItemHeaderMemo = React.memo(ContactListItemHeader);
/**
* Contact list item header component.
*/
export function ContactItem(props: ContactItemProps) {
const { icon, name, count, hasArrow, onClicked } = props;
const { getColor } = useColors();
return (
{icon ? (
<>
>
) : null}
{name}
}
RightText={count}
RightIcon={
hasArrow ? (
) : undefined
}
onClicked={onClicked}
containerStyle={{
marginHorizontal: 16,
}}
/>
);
}