import React, { useContext } from 'react';
import { Pressable, ScrollView, View, useWindowDimensions } from 'react-native';
import {
Avatar,
Divider,
Icon,
Text,
createStyleSheet,
useHeaderStyle,
useUIKitTheme,
} from '@sendbird/uikit-react-native-foundation';
import { conditionChaining, useSafeAreaPadding } from '@sendbird/uikit-utils';
import { useLocalization, useSendbirdChat } from '../../../hooks/useContext';
import useKeyboardStatus from '../../../hooks/useKeyboardStatus';
import useMentionSuggestion from '../../../hooks/useMentionSuggestion';
import { GroupChannelThreadContexts } from '../module/moduleContext';
import type { GroupChannelThreadProps } from '../types';
const GroupChannelThreadSuggestedMentionList = ({
text,
selection,
inputHeight,
bottomInset,
onPressToMention,
mentionedUsers,
showUserId = true,
}: GroupChannelThreadProps['SuggestedMentionList']) => {
const { width: screenWidth, height: screenHeight } = useWindowDimensions();
const { channel } = useContext(GroupChannelThreadContexts.Fragment);
const { sdk, mentionManager } = useSendbirdChat();
const { STRINGS } = useLocalization();
const { colors } = useUIKitTheme();
const { topInset } = useHeaderStyle();
const safeArea = useSafeAreaPadding(['left', 'right']);
const keyboard = useKeyboardStatus();
const { members, reset, searchStringRange, searchLimited } = useMentionSuggestion({
sdk,
text,
selection,
channel,
mentionedUsers,
});
const isLandscape = screenWidth > screenHeight;
const isShortened = isLandscape && keyboard.visible;
const canRenderMembers = members.length > 0;
const maxHeight = isShortened ? screenHeight - (topInset + inputHeight + keyboard.height) : styles.suggestion.height;
const renderLimitGuide = () => {
return (
{STRINGS.GROUP_CHANNEL_THREAD.MENTION_LIMITED(mentionManager.config.mentionLimit)}
);
};
const renderMembers = () => {
return (
{members.map((member) => {
return (
{
onPressToMention(member, searchStringRange);
reset();
}}
key={member.userId}
style={styles.userContainer}
>
{member.nickname || STRINGS.LABELS.USER_NO_NAME}
{!!showUserId && (
{member.userId}
)}
);
})}
);
};
return (
{conditionChaining([searchLimited, canRenderMembers], [renderLimitGuide(), renderMembers(), null])}
);
};
const styles = createStyleSheet({
suggestion: {
height: 196,
},
container: {
position: 'absolute',
top: 0,
start: 0,
end: 0,
},
scrollView: {
position: 'absolute',
start: 0,
end: 0,
},
userContainer: {
paddingStart: 16,
flexDirection: 'row',
height: 44,
alignItems: 'center',
justifyContent: 'center',
},
userAvatar: {
marginEnd: 16,
},
userInfo: {
flexDirection: 'row',
flex: 1,
},
userNickname: {
flexShrink: 1,
lineHeight: 44,
textAlignVertical: 'center',
marginEnd: 6,
},
userId: {
lineHeight: 44,
textAlignVertical: 'center',
minWidth: 32,
flexShrink: 1,
marginEnd: 16,
},
searchLimited: {
borderTopWidth: 1,
paddingHorizontal: 16,
height: 44,
flexDirection: 'row',
alignItems: 'center',
},
});
export default GroupChannelThreadSuggestedMentionList;