2021-04-09 10:27:46 +05:00
|
|
|
import React, {useEffect, useState} from 'react';
|
|
|
|
|
import {Platform, StyleSheet, View} from 'react-native';
|
|
|
|
|
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
|
|
|
import {useTracked} from '../../provider';
|
|
|
|
|
import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
|
2020-12-31 13:02:31 +05:00
|
|
|
import SearchService from '../../services/SearchService';
|
2021-07-09 12:15:06 +05:00
|
|
|
import {dWidth, getElevation} from '../../utils';
|
2021-04-09 10:27:46 +05:00
|
|
|
import {eScrollEvent} from '../../utils/Events';
|
|
|
|
|
import {SIZE} from '../../utils/SizeUtils';
|
|
|
|
|
import {ActionIcon} from '../ActionIcon';
|
|
|
|
|
import {SearchInput} from '../SearchInput';
|
|
|
|
|
import {HeaderLeftMenu} from './HeaderLeftMenu';
|
|
|
|
|
import {HeaderRightMenu} from './HeaderRightMenu';
|
2021-06-15 23:57:38 +05:00
|
|
|
import {Title} from './title';
|
2020-05-10 22:16:55 +05:00
|
|
|
|
2021-04-11 14:04:14 +05:00
|
|
|
export const Header = React.memo(
|
2021-07-09 12:15:06 +05:00
|
|
|
({root, title, screen, isBack, color, action, rightButtons}) => {
|
2021-04-11 14:04:14 +05:00
|
|
|
const [state] = useTracked();
|
|
|
|
|
const {colors} = state;
|
|
|
|
|
const insets = useSafeAreaInsets();
|
|
|
|
|
const [hide, setHide] = useState(true);
|
2021-02-08 19:02:47 +05:00
|
|
|
|
2021-04-11 14:04:14 +05:00
|
|
|
const onScroll = data => {
|
|
|
|
|
if (data.screen !== screen) return;
|
|
|
|
|
if (data.y > 150) {
|
|
|
|
|
setHide(false);
|
|
|
|
|
} else {
|
|
|
|
|
setHide(true);
|
|
|
|
|
}
|
2021-02-08 19:02:47 +05:00
|
|
|
};
|
2020-10-24 10:10:26 +05:00
|
|
|
|
2021-04-11 14:04:14 +05:00
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
2020-05-10 22:16:55 +05:00
|
|
|
|
2021-04-11 14:04:14 +05:00
|
|
|
return (
|
|
|
|
|
<View
|
|
|
|
|
style={[
|
|
|
|
|
styles.container,
|
|
|
|
|
{
|
|
|
|
|
marginTop: Platform.OS === 'android' ? insets.top : null,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
|
borderBottomColor: hide ? 'transparent' : colors.nav,
|
2021-07-09 12:15:06 +05:00
|
|
|
justifyContent: 'space-between',
|
2021-04-11 14:04:14 +05:00
|
|
|
},
|
|
|
|
|
]}>
|
|
|
|
|
<View style={styles.leftBtnContainer}>
|
|
|
|
|
<HeaderLeftMenu headerMenuState={!isBack} currentScreen={screen} />
|
2020-11-14 10:08:37 +05:00
|
|
|
|
2021-07-09 12:15:06 +05:00
|
|
|
{screen !== 'Search' ? (
|
2021-06-15 23:57:38 +05:00
|
|
|
<Title
|
2021-04-11 14:04:14 +05:00
|
|
|
headerColor={color}
|
|
|
|
|
heading={title}
|
|
|
|
|
screen={screen}
|
|
|
|
|
root={root}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
</View>
|
2020-11-14 10:08:37 +05:00
|
|
|
|
2021-04-11 14:04:14 +05:00
|
|
|
{screen === 'Search' ? (
|
|
|
|
|
<>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: '80%',
|
|
|
|
|
}}>
|
|
|
|
|
<SearchInput />
|
|
|
|
|
</View>
|
2021-07-09 12:15:06 +05:00
|
|
|
<View style={[styles.rightBtnContainer]}>
|
2021-04-11 14:04:14 +05:00
|
|
|
<ActionIcon
|
|
|
|
|
onPress={() => {
|
|
|
|
|
SearchService.search();
|
|
|
|
|
}}
|
|
|
|
|
name="magnify"
|
|
|
|
|
color={colors.pri}
|
|
|
|
|
style={styles.rightBtn}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
2021-07-09 12:15:06 +05:00
|
|
|
<HeaderRightMenu
|
|
|
|
|
rightButtons={rightButtons}
|
|
|
|
|
action={action}
|
|
|
|
|
currentScreen={screen}
|
|
|
|
|
/>
|
2021-04-11 14:04:14 +05:00
|
|
|
)}
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
(prev, next) => prev.title === next.title,
|
|
|
|
|
);
|
2020-09-07 19:19:00 +05:00
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
|
container: {
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
zIndex: 11,
|
2021-07-09 12:15:06 +05:00
|
|
|
minHeight: 50,
|
2020-09-07 19:19:00 +05:00
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
width: '100%',
|
|
|
|
|
},
|
|
|
|
|
leftBtnContainer: {
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'center',
|
2021-07-09 12:15:06 +05:00
|
|
|
flexShrink: 1,
|
2020-09-07 19:19:00 +05:00
|
|
|
},
|
|
|
|
|
leftBtn: {
|
|
|
|
|
justifyContent: 'center',
|
2020-09-21 15:40:19 +05:00
|
|
|
alignItems: 'center',
|
2020-09-07 19:19:00 +05:00
|
|
|
height: 40,
|
2020-09-21 15:40:19 +05:00
|
|
|
width: 40,
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
marginLeft: -5,
|
|
|
|
|
marginRight: 25,
|
2020-09-07 19:19:00 +05:00
|
|
|
},
|
|
|
|
|
rightBtnContainer: {
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
},
|
|
|
|
|
rightBtn: {
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'flex-end',
|
|
|
|
|
height: 40,
|
2021-07-09 12:15:06 +05:00
|
|
|
width: 40,
|
2020-09-07 19:19:00 +05:00
|
|
|
paddingRight: 0,
|
|
|
|
|
},
|
|
|
|
|
});
|