Rocket.Chat.ReactNative/app/containers/MessageBox/Mentions/index.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { FlatList } from 'react-native';
import PropTypes from 'prop-types';
import equal from 'deep-equal';
import styles from '../styles';
import MentionItem from './MentionItem';
2019-12-04 16:39:53 +00:00
import { themes } from '../../../constants/colors';
2019-12-04 16:39:53 +00:00
const Mentions = React.memo(({ mentions, trackingType, theme }) => {
if (!trackingType) {
return null;
}
return (
<FlatList
testID='messagebox-container'
2019-12-04 16:39:53 +00:00
style={[styles.mentionList, { backgroundColor: themes[theme].auxiliaryBackground }]}
data={mentions}
extraData={mentions}
2019-12-04 16:39:53 +00:00
renderItem={({ item }) => <MentionItem item={item} trackingType={trackingType} theme={theme} />}
keyExtractor={item => item.id || item.username || item.command || item}
keyboardShouldPersistTaps='always'
/>
);
}, (prevProps, nextProps) => {
2019-12-04 16:39:53 +00:00
if (prevProps.theme !== nextProps.theme) {
return false;
}
if (prevProps.trackingType !== nextProps.trackingType) {
return false;
}
if (!equal(prevProps.mentions, nextProps.mentions)) {
return false;
}
return true;
});
Mentions.propTypes = {
mentions: PropTypes.array,
2019-12-04 16:39:53 +00:00
trackingType: PropTypes.string,
theme: PropTypes.string
};
export default Mentions;