2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Text, TouchableOpacity, View } from 'react-native';
|
|
|
|
|
|
|
|
import styles from './styles';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes } from '../../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
interface ITabBarProps {
|
|
|
|
goToPage: Function;
|
|
|
|
activeTab: number;
|
|
|
|
tabs: [];
|
|
|
|
tabEmojiStyle: object;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class TabBar extends React.Component<Partial<ITabBarProps>> {
|
|
|
|
shouldComponentUpdate(nextProps: any) {
|
|
|
|
const { activeTab, theme } = this.props;
|
|
|
|
if (nextProps.activeTab !== activeTab) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.theme !== theme) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { 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}
|
|
|
|
testID={`reaction-picker-${tab}`}>
|
|
|
|
<Text style={[styles.tabEmoji, tabEmojiStyle]}>{tab}</Text>
|
|
|
|
{activeTab === i ? (
|
|
|
|
<View style={[styles.activeTabLine, { backgroundColor: themes[theme!].tintColor }]} />
|
|
|
|
) : (
|
|
|
|
<View style={styles.tabLine} />
|
|
|
|
)}
|
|
|
|
</TouchableOpacity>
|
|
|
|
))}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|