2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { FlatList } from 'react-native';
|
|
|
|
import { dequal } from 'dequal';
|
|
|
|
|
|
|
|
import Item from './Item';
|
|
|
|
import styles from '../styles';
|
|
|
|
import { themes } from '../../../constants/colors';
|
|
|
|
import { withTheme } from '../../../theme';
|
2022-03-15 14:41:23 +00:00
|
|
|
import { IPreviewItem } from '../../../definitions';
|
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;
|
2022-01-17 16:10:39 +00:00
|
|
|
theme?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const CommandsPreview = React.memo(
|
|
|
|
({ theme, commandPreview, showCommandPreview }: IMessageBoxCommandsPreview) => {
|
|
|
|
if (!showCommandPreview) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<FlatList
|
|
|
|
testID='commandbox-container'
|
2022-01-17 16:10:39 +00:00
|
|
|
style={[styles.mentionList, { backgroundColor: themes[theme!].messageboxBackground }]}
|
2021-09-13 20:41:05 +00:00
|
|
|
data={commandPreview}
|
|
|
|
renderItem={({ item }) => <Item item={item} theme={theme} />}
|
|
|
|
keyExtractor={(item: any) => item.id}
|
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
horizontal
|
|
|
|
showsHorizontalScrollIndicator={false}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
(prevProps, nextProps) => {
|
|
|
|
if (prevProps.theme !== nextProps.theme) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (prevProps.showCommandPreview !== nextProps.showCommandPreview) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!dequal(prevProps.commandPreview, nextProps.commandPreview)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export default withTheme(CommandsPreview);
|