verdnatura-chat/app/containers/MessageBox/CommandsPreview/index.js

47 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

import React from 'react';
import { FlatList } from 'react-native';
import PropTypes from 'prop-types';
import { dequal } from 'dequal';
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-12-04 16:39:53 +00:00
const CommandsPreview = React.memo(({ theme, commandPreview, showCommandPreview }) => {
if (!showCommandPreview) {
return null;
}
return (
<FlatList
testID='commandbox-container'
2019-12-04 16:39:53 +00:00
style={[styles.mentionList, { backgroundColor: themes[theme].messageboxBackground }]}
data={commandPreview}
2019-12-04 16:39:53 +00:00
renderItem={({ item }) => <Item item={item} theme={theme} />}
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;
}
if (prevProps.showCommandPreview !== nextProps.showCommandPreview) {
return false;
}
if (!dequal(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-12-04 16:39:53 +00:00
export default withTheme(CommandsPreview);