2018-01-16 18:48:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { View, TouchableOpacity, Text } from 'react-native';
|
|
|
|
import styles from './styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2018-01-16 18:48:05 +00:00
|
|
|
|
2021-08-02 02:11:20 +00:00
|
|
|
interface ITabBarProps {
|
2021-07-16 02:33:57 +00:00
|
|
|
goToPage({}): void;
|
|
|
|
activeTab: number,
|
|
|
|
tabs: [],
|
|
|
|
tabEmojiStyle: object,
|
|
|
|
theme: string
|
|
|
|
}
|
|
|
|
|
2021-08-02 02:11:20 +00:00
|
|
|
export default class TabBar extends React.Component<Partial<ITabBarProps>> {
|
2018-01-16 18:48:05 +00:00
|
|
|
|
2021-07-16 02:33:57 +00:00
|
|
|
shouldComponentUpdate(nextProps: any) {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { activeTab, theme } = this.props;
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextProps.activeTab !== activeTab) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-12-04 16:39:53 +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() {
|
2021-07-16 02:33:57 +00:00
|
|
|
const { tabs, goToPage, tabEmojiStyle, activeTab, theme } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-01-16 18:48:05 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.tabsContainer}>
|
2021-07-19 15:06:45 +00:00
|
|
|
{tabs!.map((tab, i) => (
|
2018-01-30 19:48:26 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
activeOpacity={0.7}
|
|
|
|
key={tab}
|
2021-07-19 15:06:45 +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>
|
2021-07-19 15:06:45 +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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|