2019-10-30 14:14:41 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { FlatList } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import equal from 'deep-equal';
|
|
|
|
|
|
|
|
import Item from './Item';
|
|
|
|
import styles from '../styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
|
|
|
import { withTheme } from '../../../theme';
|
2019-10-30 14:14:41 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
const CommandsPreview = React.memo(({ theme, commandPreview, showCommandPreview }) => {
|
2019-10-30 14:14:41 +00:00
|
|
|
if (!showCommandPreview) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<FlatList
|
|
|
|
testID='commandbox-container'
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.mentionList, { backgroundColor: themes[theme].messageboxBackground }]}
|
2019-10-30 14:14:41 +00:00
|
|
|
data={commandPreview}
|
2019-12-04 16:39:53 +00:00
|
|
|
renderItem={({ item }) => <Item item={item} theme={theme} />}
|
2019-10-30 14:14:41 +00:00
|
|
|
keyExtractor={item => item.id}
|
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
horizontal
|
|
|
|
showsHorizontalScrollIndicator={false}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}, (prevProps, nextProps) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
if (prevProps.theme !== nextProps.theme) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-30 14:14:41 +00:00
|
|
|
if (prevProps.showCommandPreview !== nextProps.showCommandPreview) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!equal(prevProps.commandPreview, nextProps.commandPreview)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
CommandsPreview.propTypes = {
|
|
|
|
commandPreview: PropTypes.array,
|
2019-12-04 16:39:53 +00:00
|
|
|
showCommandPreview: PropTypes.bool,
|
|
|
|
theme: PropTypes.string
|
2019-10-30 14:14:41 +00:00
|
|
|
};
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default withTheme(CommandsPreview);
|