2020-12-16 14:57:58 +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-11-26 16:22:32 +05:00
|
|
|
import Navigation from '../../services/Navigation';
|
2020-12-16 14:57:58 +05:00
|
|
|
import { dWidth } from '../../utils';
|
|
|
|
|
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';
|
|
|
|
|
import { HeaderTitle } from './HeaderTitle';
|
2020-11-26 16:22:32 +05:00
|
|
|
|
2020-05-10 22:16:55 +05:00
|
|
|
|
2020-11-09 18:13:47 +05:00
|
|
|
export const Header = ({root}) => {
|
|
|
|
|
const [state] = useTracked();
|
2020-11-23 17:33:14 +05:00
|
|
|
const {colors, currentScreen} = state;
|
2020-09-14 23:00:34 +05:00
|
|
|
const insets = useSafeAreaInsets();
|
2020-11-20 01:23:05 +05:00
|
|
|
const [hide, setHide] = useState(true);
|
2020-10-24 10:10:26 +05:00
|
|
|
|
|
|
|
|
const onScroll = (y) => {
|
2020-11-10 17:16:06 +05:00
|
|
|
if (y > 150) {
|
2020-11-09 18:13:47 +05:00
|
|
|
setHide(false);
|
2020-10-24 10:10:26 +05:00
|
|
|
} else {
|
2020-11-09 18:13:47 +05:00
|
|
|
setHide(true);
|
2020-10-24 10:10:26 +05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eScrollEvent, onScroll);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
2020-05-10 22:16:55 +05:00
|
|
|
|
2019-11-29 11:31:43 +05:00
|
|
|
return (
|
2020-01-27 14:01:24 +05:00
|
|
|
<View
|
2020-09-07 19:19:00 +05:00
|
|
|
style={[
|
|
|
|
|
styles.container,
|
|
|
|
|
{
|
2020-11-20 01:23:05 +05:00
|
|
|
marginTop: Platform.OS === 'android' ? insets.top : null,
|
2020-09-07 19:19:00 +05:00
|
|
|
backgroundColor: colors.bg,
|
2020-09-14 23:00:34 +05:00
|
|
|
overflow: 'hidden',
|
2020-11-09 18:13:47 +05:00
|
|
|
borderBottomWidth: 1,
|
|
|
|
|
borderBottomColor: hide ? 'transparent' : colors.nav,
|
2020-11-14 10:08:37 +05:00
|
|
|
justifyContent: 'center',
|
2020-09-07 19:19:00 +05:00
|
|
|
},
|
|
|
|
|
]}>
|
2020-10-13 17:02:14 +05:00
|
|
|
<View style={styles.leftBtnContainer}>
|
2020-11-09 18:13:47 +05:00
|
|
|
<HeaderLeftMenu />
|
2020-11-14 10:08:37 +05:00
|
|
|
|
2020-12-14 14:06:01 +05:00
|
|
|
{(Platform.OS === 'android' && currentScreen !== 'search') ||
|
|
|
|
|
Platform.isPad ? (
|
2020-11-14 10:08:37 +05:00
|
|
|
<HeaderTitle root={root} />
|
|
|
|
|
) : null}
|
2020-10-13 17:02:14 +05:00
|
|
|
</View>
|
2020-12-14 14:06:01 +05:00
|
|
|
{Platform.OS !== 'android' &&
|
|
|
|
|
!Platform.isPad &&
|
|
|
|
|
currentScreen !== 'search' ? (
|
2020-11-14 10:08:37 +05:00
|
|
|
<HeaderTitle root={root} />
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{currentScreen === 'search' ? (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: '80%',
|
|
|
|
|
}}>
|
|
|
|
|
<SearchInput />
|
|
|
|
|
</View>
|
|
|
|
|
) : null}
|
2020-10-13 17:02:14 +05:00
|
|
|
|
2020-11-14 10:08:37 +05:00
|
|
|
{currentScreen === 'search' ? (
|
2020-12-14 14:06:01 +05:00
|
|
|
<View style={[styles.rightBtnContainer, {right: 6}]}>
|
2020-11-14 10:08:37 +05:00
|
|
|
<ActionIcon
|
|
|
|
|
onPress={async () => {
|
2020-12-14 14:06:01 +05:00
|
|
|
Navigation.navigate('Search', {
|
|
|
|
|
menu: false,
|
2020-11-26 16:22:32 +05:00
|
|
|
});
|
2020-11-14 10:08:37 +05:00
|
|
|
}}
|
|
|
|
|
name="tune"
|
|
|
|
|
size={SIZE.xxxl}
|
|
|
|
|
color={colors.pri}
|
|
|
|
|
style={styles.rightBtn}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
) : (
|
2020-12-14 14:06:01 +05:00
|
|
|
<HeaderRightMenu />
|
2020-11-14 10:08:37 +05:00
|
|
|
)}
|
2020-01-27 14:01:24 +05:00
|
|
|
</View>
|
2019-11-29 11:31:43 +05:00
|
|
|
);
|
|
|
|
|
};
|
2020-09-07 19:19:00 +05:00
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
|
container: {
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
zIndex: 11,
|
|
|
|
|
height: 50,
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
paddingHorizontal: 12,
|
|
|
|
|
width: '100%',
|
|
|
|
|
},
|
|
|
|
|
loadingContainer: {
|
|
|
|
|
alignSelf: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
zIndex: 999,
|
2020-10-13 17:02:14 +05:00
|
|
|
left: dWidth / 2 - 20,
|
2020-09-07 19:19:00 +05:00
|
|
|
top: -20,
|
|
|
|
|
width: 40,
|
|
|
|
|
height: 40,
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
},
|
|
|
|
|
loadingInnerContainer: {
|
|
|
|
|
width: 40,
|
|
|
|
|
height: 20,
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
zIndex: 10,
|
|
|
|
|
top: 0,
|
|
|
|
|
},
|
|
|
|
|
leftBtnContainer: {
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
left: 12,
|
|
|
|
|
},
|
|
|
|
|
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',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
right: 12,
|
|
|
|
|
},
|
|
|
|
|
rightBtn: {
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'flex-end',
|
|
|
|
|
height: 40,
|
|
|
|
|
width: 50,
|
|
|
|
|
paddingRight: 0,
|
|
|
|
|
},
|
|
|
|
|
});
|