2022-03-31 22:39:24 +00:00
|
|
|
import { dequal } from 'dequal';
|
2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { FlatList } from 'react-native';
|
|
|
|
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../../lib/constants';
|
2022-03-15 14:41:23 +00:00
|
|
|
import { IPreviewItem } from '../../../definitions';
|
2022-03-31 22:39:24 +00:00
|
|
|
import { useTheme } from '../../../theme';
|
|
|
|
import styles from '../styles';
|
|
|
|
import Item from './Item';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
interface IMessageBoxCommandsPreview {
|
2022-03-15 14:41:23 +00:00
|
|
|
commandPreview: IPreviewItem[];
|
2021-09-13 20:41:05 +00:00
|
|
|
showCommandPreview: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CommandsPreview = React.memo(
|
2022-03-31 22:39:24 +00:00
|
|
|
({ commandPreview, showCommandPreview }: IMessageBoxCommandsPreview) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
if (!showCommandPreview) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-03-31 22:39:24 +00:00
|
|
|
const { theme } = useTheme();
|
2021-09-13 20:41:05 +00:00
|
|
|
return (
|
|
|
|
<FlatList
|
|
|
|
testID='commandbox-container'
|
2022-03-31 22:39:24 +00:00
|
|
|
style={[styles.mentionList, { backgroundColor: themes[theme].messageboxBackground }]}
|
2021-09-13 20:41:05 +00:00
|
|
|
data={commandPreview}
|
2022-03-31 22:39:24 +00:00
|
|
|
renderItem={({ item }) => <Item item={item} />}
|
2021-09-13 20:41:05 +00:00
|
|
|
keyExtractor={(item: any) => item.id}
|
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
horizontal
|
|
|
|
showsHorizontalScrollIndicator={false}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
(prevProps, nextProps) => {
|
|
|
|
if (prevProps.showCommandPreview !== nextProps.showCommandPreview) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!dequal(prevProps.commandPreview, nextProps.commandPreview)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-03-31 22:39:24 +00:00
|
|
|
export default CommandsPreview;
|