2020-06-15 14:00:46 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
|
|
import { View, StyleSheet } from 'react-native';
|
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { themedHeader } from '../../utils/navigation';
|
2020-06-26 20:22:56 +00:00
|
|
|
import { isIOS, isTablet } from '../../utils/deviceInfo';
|
2020-10-30 16:15:58 +00:00
|
|
|
import { withTheme } from '../../theme';
|
2020-06-15 14:00:46 +00:00
|
|
|
|
|
|
|
// Get from https://github.com/react-navigation/react-navigation/blob/master/packages/stack/src/views/Header/HeaderSegment.tsx#L69
|
|
|
|
export const headerHeight = isIOS ? 44 : 56;
|
|
|
|
|
2021-07-19 19:52:45 +00:00
|
|
|
export const getHeaderHeight = (isLandscape: boolean) => {
|
2020-06-26 20:22:56 +00:00
|
|
|
if (isIOS) {
|
|
|
|
if (isLandscape && !isTablet) {
|
|
|
|
return 32;
|
|
|
|
} else {
|
|
|
|
return 44;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 56;
|
|
|
|
};
|
|
|
|
|
2021-07-19 19:52:45 +00:00
|
|
|
type THeaderTitlePosition = {
|
|
|
|
insets: {
|
|
|
|
left: number;
|
|
|
|
right: number;
|
|
|
|
};
|
|
|
|
numIconsRight: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getHeaderTitlePosition = ({ insets, numIconsRight }: THeaderTitlePosition) => ({
|
2020-11-04 19:13:29 +00:00
|
|
|
left: insets.left + 60,
|
2021-04-01 14:09:02 +00:00
|
|
|
right: insets.right + Math.max(45 * numIconsRight, 15)
|
2020-07-06 20:56:28 +00:00
|
|
|
});
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
height: headerHeight,
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'center',
|
|
|
|
elevation: 4
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-19 19:52:45 +00:00
|
|
|
interface IHeader {
|
|
|
|
theme: string;
|
|
|
|
headerLeft(): void;
|
|
|
|
headerTitle(): void;
|
|
|
|
headerRight(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Header = ({ theme, headerLeft, headerTitle, headerRight }: IHeader) => (
|
2020-06-15 14:00:46 +00:00
|
|
|
<SafeAreaView style={{ backgroundColor: themes[theme].headerBackground }} edges={['top', 'left', 'right']}>
|
|
|
|
<View style={[styles.container, { ...themedHeader(theme).headerStyle }]}>
|
|
|
|
{headerLeft ? headerLeft() : null}
|
|
|
|
{headerTitle ? headerTitle() : null}
|
|
|
|
{headerRight ? headerRight() : null}
|
|
|
|
</View>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
|
2020-10-30 16:15:58 +00:00
|
|
|
export default withTheme(Header);
|