verdnatura-chat/app/containers/EmojiPicker/TabBar.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { View, TouchableOpacity, Text } from 'react-native';
import styles from './styles';
2019-12-11 23:01:12 +00:00
import { themes } from '../../constants/colors';
export default class TabBar extends React.Component {
static propTypes = {
goToPage: PropTypes.func,
activeTab: PropTypes.number,
tabs: PropTypes.array,
2019-12-11 23:01:12 +00:00
tabEmojiStyle: PropTypes.object,
theme: PropTypes.string
}
shouldComponentUpdate(nextProps) {
2019-12-11 23:01:12 +00:00
const { activeTab, theme } = this.props;
if (nextProps.activeTab !== activeTab) {
return true;
}
2019-12-11 23:01:12 +00:00
if (nextProps.theme !== theme) {
return true;
}
return false;
}
render() {
const {
2019-12-11 23:01:12 +00:00
tabs, goToPage, tabEmojiStyle, activeTab, theme
} = this.props;
return (
<View style={styles.tabsContainer}>
{tabs.map((tab, i) => (
<TouchableOpacity
activeOpacity={0.7}
key={tab}
onPress={() => goToPage(i)}
style={styles.tab}
2018-05-23 13:39:18 +00:00
testID={`reaction-picker-${ tab }`}
>
<Text style={[styles.tabEmoji, tabEmojiStyle]}>{tab}</Text>
2019-12-11 23:01:12 +00:00
{activeTab === i ? <View style={[styles.activeTabLine, { backgroundColor: themes[theme].tintColor }]} /> : <View style={styles.tabLine} />}
</TouchableOpacity>
))}
</View>
);
}
}