2019-12-06 18:13:15 +05:00
|
|
|
import React, {useEffect, useState} from 'react';
|
2019-11-29 11:31:43 +05:00
|
|
|
import {View, TouchableOpacity, Platform, Text} from 'react-native';
|
2019-11-30 19:56:40 +05:00
|
|
|
import Icon from 'react-native-vector-icons/Feather';
|
2019-11-29 11:31:43 +05:00
|
|
|
import {SIZE, WEIGHT} from '../../common/common';
|
2019-12-11 15:20:18 +05:00
|
|
|
import {h, SideMenuEvent} from '../../utils/utils';
|
2019-12-06 18:13:15 +05:00
|
|
|
import * as Animatable from 'react-native-animatable';
|
2019-12-11 15:20:18 +05:00
|
|
|
import NavigationService from '../../services/NavigationService';
|
2019-12-14 16:00:16 +05:00
|
|
|
import {DDS} from '../../../App';
|
2019-12-14 19:26:44 +05:00
|
|
|
import {useAppContext} from '../../provider/useAppContext';
|
2019-12-06 18:13:15 +05:00
|
|
|
export const Header = ({
|
|
|
|
|
heading,
|
|
|
|
|
canGoBack = true,
|
|
|
|
|
hide,
|
|
|
|
|
showSearch,
|
2019-12-11 15:20:18 +05:00
|
|
|
menu,
|
2019-12-06 18:13:15 +05:00
|
|
|
sendHeight = e => {},
|
|
|
|
|
}) => {
|
2019-12-14 19:26:44 +05:00
|
|
|
const {colors} = useAppContext();
|
2019-12-14 16:00:16 +05:00
|
|
|
const [isOpen, setOpen] = useState(DDS.isTab ? true : false);
|
|
|
|
|
|
2019-11-29 11:31:43 +05:00
|
|
|
return (
|
2019-12-06 18:13:15 +05:00
|
|
|
<Animatable.View
|
|
|
|
|
onLayout={e => {
|
|
|
|
|
if (sendHeight) {
|
|
|
|
|
sendHeight(e.nativeEvent.layout.height);
|
|
|
|
|
}
|
|
|
|
|
}}
|
2019-12-09 13:17:40 +05:00
|
|
|
transition={['minHeight', 'marginBottom']}
|
2019-12-09 08:53:45 +05:00
|
|
|
duration={250}
|
2019-11-29 11:31:43 +05:00
|
|
|
style={{
|
2019-12-09 13:17:40 +05:00
|
|
|
minHeight: hide ? 50 : 50,
|
2019-11-29 11:31:43 +05:00
|
|
|
flexDirection: 'row',
|
2019-12-06 18:13:15 +05:00
|
|
|
zIndex: 10,
|
|
|
|
|
justifyContent: 'space-between',
|
2019-11-29 11:31:43 +05:00
|
|
|
alignItems: 'center',
|
2019-12-14 16:00:16 +05:00
|
|
|
paddingHorizontal: DDS.isTab ? '2.5%' : '5%',
|
2019-12-06 18:13:15 +05:00
|
|
|
paddingTop: Platform.OS == 'ios' ? h * 0.02 : h * 0.06,
|
2019-12-09 08:53:45 +05:00
|
|
|
marginBottom: hide
|
|
|
|
|
? h * 0.03
|
|
|
|
|
: Platform.OS == 'ios'
|
|
|
|
|
? h * 0.04
|
|
|
|
|
: h * 0.04,
|
2019-11-29 11:31:43 +05:00
|
|
|
}}>
|
2019-12-06 18:13:15 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
|
|
|
|
{canGoBack ? (
|
|
|
|
|
<TouchableOpacity
|
2019-12-11 15:20:18 +05:00
|
|
|
hitSlop={{top: 20, bottom: 20, left: 50, right: 40}}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
NavigationService.goBack();
|
|
|
|
|
}}
|
2019-12-06 18:13:15 +05:00
|
|
|
style={{
|
2019-12-11 15:20:18 +05:00
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'flex-start',
|
2019-12-07 12:05:15 +05:00
|
|
|
height: 40,
|
2019-12-11 15:20:18 +05:00
|
|
|
width: 25,
|
2019-12-06 18:13:15 +05:00
|
|
|
}}>
|
2019-12-07 12:05:15 +05:00
|
|
|
<Icon
|
2019-12-11 15:20:18 +05:00
|
|
|
style={{
|
|
|
|
|
marginLeft: -10,
|
|
|
|
|
}}
|
2019-12-07 12:05:15 +05:00
|
|
|
color={colors.pri}
|
|
|
|
|
name={'chevron-left'}
|
2019-12-14 16:00:16 +05:00
|
|
|
size={SIZE.xl}
|
2019-12-07 12:05:15 +05:00
|
|
|
/>
|
2019-12-06 18:13:15 +05:00
|
|
|
</TouchableOpacity>
|
|
|
|
|
) : (
|
|
|
|
|
undefined
|
|
|
|
|
)}
|
2019-12-11 15:20:18 +05:00
|
|
|
{menu ? (
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
hitSlop={{top: 20, bottom: 20, left: 50, right: 40}}
|
|
|
|
|
onPress={() => {
|
2019-12-14 16:00:16 +05:00
|
|
|
if (isOpen) {
|
|
|
|
|
SideMenuEvent.close();
|
|
|
|
|
setOpen(false);
|
|
|
|
|
} else {
|
|
|
|
|
SideMenuEvent.open();
|
|
|
|
|
setOpen(true);
|
|
|
|
|
}
|
2019-12-11 15:20:18 +05:00
|
|
|
}}
|
|
|
|
|
style={{
|
2019-12-14 16:00:16 +05:00
|
|
|
justifyContent: 'center',
|
2019-12-11 15:20:18 +05:00
|
|
|
alignItems: 'flex-start',
|
|
|
|
|
height: 40,
|
2019-12-14 16:00:16 +05:00
|
|
|
width: 45,
|
2019-12-11 15:20:18 +05:00
|
|
|
}}>
|
2019-12-14 16:00:16 +05:00
|
|
|
<Icon color={colors.pri} name={'menu'} size={SIZE.xl} />
|
2019-12-11 15:20:18 +05:00
|
|
|
</TouchableOpacity>
|
|
|
|
|
) : (
|
|
|
|
|
undefined
|
|
|
|
|
)}
|
2019-12-06 18:13:15 +05:00
|
|
|
|
|
|
|
|
<Animatable.Text
|
|
|
|
|
transition="fontSize"
|
|
|
|
|
duration={300}
|
|
|
|
|
style={{
|
2019-12-14 16:00:16 +05:00
|
|
|
fontSize: hide ? SIZE.xl : SIZE.xl,
|
2019-12-06 18:13:15 +05:00
|
|
|
color: colors.pri,
|
|
|
|
|
fontFamily: WEIGHT.bold,
|
|
|
|
|
}}>
|
|
|
|
|
{heading}
|
|
|
|
|
</Animatable.Text>
|
|
|
|
|
</View>
|
|
|
|
|
<Animatable.View
|
|
|
|
|
transition="opacity"
|
|
|
|
|
duration={500}
|
|
|
|
|
style={{
|
|
|
|
|
opacity: hide ? 1 : 0,
|
|
|
|
|
}}>
|
2019-11-29 11:31:43 +05:00
|
|
|
<TouchableOpacity
|
2019-12-06 18:13:15 +05:00
|
|
|
onPress={() => showSearch()}
|
2019-11-29 11:31:43 +05:00
|
|
|
style={{
|
|
|
|
|
justifyContent: 'center',
|
2019-12-06 18:13:15 +05:00
|
|
|
alignItems: 'flex-end',
|
|
|
|
|
height: 40,
|
|
|
|
|
width: 60,
|
|
|
|
|
paddingRight: 0,
|
|
|
|
|
marginTop: 7,
|
2019-11-29 11:31:43 +05:00
|
|
|
}}>
|
2019-12-07 12:05:15 +05:00
|
|
|
<Icon name={'search'} size={SIZE.xl} color={colors.icon} />
|
2019-11-29 11:31:43 +05:00
|
|
|
</TouchableOpacity>
|
2019-12-06 18:13:15 +05:00
|
|
|
</Animatable.View>
|
|
|
|
|
</Animatable.View>
|
2019-11-29 11:31:43 +05:00
|
|
|
);
|
|
|
|
|
};
|