2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
2022-05-07 01:06:08 +00:00
|
|
|
import { StyleProp, Text, TextStyle, TouchableOpacity, View } from 'react-native';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
import styles from './styles';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-04-08 18:02:44 +00:00
|
|
|
import { testProps } from '../../lib/methods/testProps';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes } from '../../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
interface ITabBarProps {
|
2022-05-07 01:06:08 +00:00
|
|
|
goToPage?: (page: number) => void;
|
|
|
|
activeTab?: number;
|
|
|
|
tabs?: string[];
|
|
|
|
tabEmojiStyle: StyleProp<TextStyle>;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-05-07 01:06:08 +00:00
|
|
|
export default class TabBar extends React.Component<ITabBarProps> {
|
|
|
|
shouldComponentUpdate(nextProps: ITabBarProps) {
|
2021-09-13 20:41:05 +00:00
|
|
|
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}>
|
2022-05-07 01:06:08 +00:00
|
|
|
{tabs?.map((tab, i) => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
activeOpacity={0.7}
|
|
|
|
key={tab}
|
2022-05-07 01:06:08 +00:00
|
|
|
onPress={() => {
|
|
|
|
if (goToPage) {
|
|
|
|
goToPage(i);
|
|
|
|
}
|
|
|
|
}}
|
2021-09-13 20:41:05 +00:00
|
|
|
style={styles.tab}
|
2022-04-08 18:02:44 +00:00
|
|
|
{...testProps(`reaction-picker-${tab}`)}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text style={[styles.tabEmoji, tabEmojiStyle]}>{tab}</Text>
|
|
|
|
{activeTab === i ? (
|
2022-05-07 01:06:08 +00:00
|
|
|
<View style={[styles.activeTabLine, { backgroundColor: themes[theme].tintColor }]} />
|
2021-09-13 20:41:05 +00:00
|
|
|
) : (
|
|
|
|
<View style={styles.tabLine} />
|
|
|
|
)}
|
|
|
|
</TouchableOpacity>
|
|
|
|
))}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|