2022-01-22 12:57:05 +05:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
import { Platform, StyleSheet, View } from 'react-native';
|
|
|
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
2022-02-28 23:25:18 +05:00
|
|
|
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
|
2022-04-24 05:59:14 +05:00
|
|
|
import { useThemeStore } from '../../stores/use-theme-store';
|
2022-02-28 13:48:59 +05:00
|
|
|
import { eScrollEvent } from '../../utils/events';
|
|
|
|
|
import { LeftMenus } from './left-menus';
|
|
|
|
|
import { RightMenus } from './right-menus';
|
2022-01-22 12:57:05 +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(
|
2022-04-24 05:59:14 +05:00
|
|
|
() => {
|
2022-02-28 23:25:18 +05:00
|
|
|
const colors = useThemeStore(state => state.colors);
|
2021-04-11 14:04:14 +05:00
|
|
|
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.y > 150) {
|
2022-04-24 05:59:14 +05:00
|
|
|
if (!hide) return;
|
2021-04-11 14:04:14 +05:00
|
|
|
setHide(false);
|
|
|
|
|
} else {
|
2022-04-24 05:59:14 +05:00
|
|
|
if (hide) return;
|
2021-04-11 14:04:14 +05:00
|
|
|
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);
|
|
|
|
|
};
|
2022-04-24 05:59:14 +05:00
|
|
|
}, [hide]);
|
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,
|
2022-01-22 12:57:05 +05:00
|
|
|
justifyContent: 'space-between'
|
2021-07-28 14:15:20 +05:00
|
|
|
}
|
2022-01-22 12:57:05 +05:00
|
|
|
]}
|
|
|
|
|
>
|
2021-04-11 14:04:14 +05:00
|
|
|
<View style={styles.leftBtnContainer}>
|
2022-04-24 05:59:14 +05:00
|
|
|
<LeftMenus />
|
|
|
|
|
<Title />
|
2021-04-11 14:04:14 +05:00
|
|
|
</View>
|
2022-04-24 05:59:14 +05:00
|
|
|
<RightMenus />
|
2021-04-11 14:04:14 +05:00
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
},
|
2022-04-24 05:59:14 +05:00
|
|
|
() => true
|
2021-04-11 14:04:14 +05:00
|
|
|
);
|
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,
|
2021-07-28 14:15:20 +05:00
|
|
|
width: '100%'
|
2020-09-07 19:19:00 +05:00
|
|
|
},
|
|
|
|
|
leftBtnContainer: {
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'center',
|
2021-07-28 14:15:20 +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,
|
2021-07-28 14:15:20 +05:00
|
|
|
marginRight: 25
|
2020-09-07 19:19:00 +05:00
|
|
|
},
|
|
|
|
|
rightBtnContainer: {
|
|
|
|
|
flexDirection: 'row',
|
2021-07-28 14:15:20 +05:00
|
|
|
alignItems: 'center'
|
2020-09-07 19:19:00 +05:00
|
|
|
},
|
|
|
|
|
rightBtn: {
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'flex-end',
|
|
|
|
|
height: 40,
|
2021-07-09 12:15:06 +05:00
|
|
|
width: 40,
|
2021-07-28 14:15:20 +05:00
|
|
|
paddingRight: 0
|
|
|
|
|
}
|
2020-09-07 19:19:00 +05:00
|
|
|
});
|