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';
|
|
|
|
|
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,
|
|
|
|
tabEmojiStyle: PropTypes.object
|
2018-01-16 18:48:05 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
const { activeTab } = this.props;
|
|
|
|
if (nextProps.activeTab !== activeTab) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-16 18:48:05 +00:00
|
|
|
render() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const {
|
|
|
|
tabs, goToPage, tabEmojiStyle, activeTab
|
|
|
|
} = 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>
|
|
|
|
{activeTab === i ? <View style={styles.activeTabLine} /> : <View style={styles.tabLine} />}
|
2018-01-16 18:48:05 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
))}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|