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';
|
|
|
|
import { withTheme } from '../../theme';
|
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import sharedStyles from '../../views/Styles';
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IHeaderButtonItem {
|
|
|
|
title: string;
|
|
|
|
iconName: string;
|
|
|
|
onPress(): void;
|
|
|
|
testID: string;
|
|
|
|
theme: string;
|
|
|
|
badge(): void;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const Item = ({ title, iconName, onPress, testID, theme, badge }: IHeaderButtonItem) => (
|
2020-10-30 16:15:58 +00:00
|
|
|
<Touchable onPress={onPress} testID={testID} hitSlop={BUTTON_HIT_SLOP} style={styles.container}>
|
|
|
|
<>
|
2021-09-13 20:41:05 +00:00
|
|
|
{iconName ? (
|
|
|
|
<CustomIcon name={iconName} size={24} color={themes[theme].headerTintColor} />
|
|
|
|
) : (
|
|
|
|
<Text style={[styles.title, { color: themes[theme].headerTintColor }]}>{title}</Text>
|
|
|
|
)}
|
2020-10-30 16:15:58 +00:00
|
|
|
{badge ? badge() : null}
|
|
|
|
</>
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
|
|
|
|
Item.displayName = 'HeaderButton.Item';
|
|
|
|
|
|
|
|
export default withTheme(Item);
|