2020-10-30 16:15:58 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { Platform, StyleSheet, Text } from 'react-native';
|
2020-10-30 16:15:58 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
|
|
|
|
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2022-03-24 19:55:01 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2020-10-30 16:15:58 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import sharedStyles from '../../views/Styles';
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IHeaderButtonItem {
|
2022-01-17 16:10:39 +00:00
|
|
|
title?: string;
|
|
|
|
iconName?: string;
|
2022-03-24 19:55:01 +00:00
|
|
|
onPress?: <T>(arg: T) => void;
|
2022-01-17 16:10:39 +00:00
|
|
|
testID?: string;
|
|
|
|
badge?(): void;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 16:15:58 +00:00
|
|
|
export const BUTTON_HIT_SLOP = {
|
2021-09-13 20:41:05 +00:00
|
|
|
top: 5,
|
|
|
|
right: 5,
|
|
|
|
bottom: 5,
|
|
|
|
left: 5
|
2020-10-30 16:15:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
marginHorizontal: 6
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
...Platform.select({
|
|
|
|
android: {
|
|
|
|
fontSize: 14
|
|
|
|
},
|
|
|
|
default: {
|
|
|
|
fontSize: 17
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
...sharedStyles.textRegular
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-24 19:55:01 +00:00
|
|
|
const Item = ({ title, iconName, onPress, testID, badge }: IHeaderButtonItem): React.ReactElement => {
|
|
|
|
const { theme } = useTheme();
|
|
|
|
return (
|
|
|
|
<Touchable onPress={onPress} testID={testID} hitSlop={BUTTON_HIT_SLOP} style={styles.container}>
|
|
|
|
<>
|
|
|
|
{iconName ? (
|
|
|
|
<CustomIcon name={iconName} size={24} color={themes[theme].headerTintColor} />
|
|
|
|
) : (
|
|
|
|
<Text style={[styles.title, { color: themes[theme].headerTintColor }]}>{title}</Text>
|
|
|
|
)}
|
|
|
|
{badge ? badge() : null}
|
|
|
|
</>
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
};
|
2020-10-30 16:15:58 +00:00
|
|
|
|
|
|
|
Item.displayName = 'HeaderButton.Item';
|
|
|
|
|
2022-03-24 19:55:01 +00:00
|
|
|
export default Item;
|