2018-01-16 18:48:05 +00:00
|
|
|
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';
|
2018-01-16 18:48:05 +00:00
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
export default class TabBar extends React.Component {
|
2018-01-16 18:48:05 +00:00
|
|
|
static propTypes = {
|
|
|
|
goToPage: PropTypes.func,
|
|
|
|
activeTab: PropTypes.number,
|
2018-01-30 19:48:26 +00:00
|
|
|
tabs: PropTypes.array,
|
2019-12-11 23:01:12 +00:00
|
|
|
tabEmojiStyle: PropTypes.object,
|
|
|
|
theme: PropTypes.string
|
2018-01-16 18:48:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
shouldComponentUpdate(nextProps) {
|
2019-12-11 23:01:12 +00:00
|
|
|
const { activeTab, theme } = this.props;
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextProps.activeTab !== activeTab) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-12-11 23:01:12 +00:00
|
|
|
if (nextProps.theme !== theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-16 18:48:05 +00:00
|
|
|
render() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const {
|
2019-12-11 23:01:12 +00:00
|
|
|
tabs, goToPage, tabEmojiStyle, activeTab, theme
|
2018-09-25 19:28:42 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2018-01-16 18:48:05 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.tabsContainer}>
|
2018-09-25 19:28:42 +00:00
|
|
|
{tabs.map((tab, i) => (
|
2018-01-30 19:48:26 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
activeOpacity={0.7}
|
|
|
|
key={tab}
|
2018-09-25 19:28:42 +00:00
|
|
|
onPress={() => goToPage(i)}
|
2018-01-30 19:48:26 +00:00
|
|
|
style={styles.tab}
|
2018-05-23 13:39:18 +00:00
|
|
|
testID={`reaction-picker-${ tab }`}
|
2018-01-30 19:48:26 +00:00
|
|
|
>
|
2018-09-25 19:28:42 +00:00
|
|
|
<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} />}
|
2018-01-16 18:48:05 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
))}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|