2022-08-26 16:19:39 +05:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
|
import { Platform, StyleSheet, View } from "react-native";
|
|
|
|
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
|
|
|
import { SearchBar } from "../../screens/search/search-bar";
|
|
|
|
|
import {
|
|
|
|
|
eSubscribeEvent,
|
|
|
|
|
eUnSubscribeEvent
|
|
|
|
|
} from "../../services/event-manager";
|
|
|
|
|
import useNavigationStore from "../../stores/use-navigation-store";
|
|
|
|
|
import { useSelectionStore } from "../../stores/use-selection-store";
|
|
|
|
|
import { useThemeStore } from "../../stores/use-theme-store";
|
|
|
|
|
import { eScrollEvent } from "../../utils/events";
|
|
|
|
|
import { LeftMenus } from "./left-menus";
|
|
|
|
|
import { RightMenus } from "./right-menus";
|
|
|
|
|
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-08-26 16:19:39 +05:00
|
|
|
const colors = useThemeStore((state) => state.colors);
|
2021-04-11 14:04:14 +05:00
|
|
|
const insets = useSafeAreaInsets();
|
|
|
|
|
const [hide, setHide] = useState(true);
|
2022-08-26 16:19:39 +05:00
|
|
|
const selectionMode = useSelectionStore((state) => state.selectionMode);
|
|
|
|
|
const currentScreen = useNavigationStore(
|
|
|
|
|
(state) => state.currentScreen?.name
|
|
|
|
|
);
|
2021-02-08 19:02:47 +05:00
|
|
|
|
2022-08-26 16:19:39 +05:00
|
|
|
const onScroll = (data) => {
|
2021-04-11 14:04:14 +05:00
|
|
|
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
|
|
|
|
2022-05-10 18:04:56 +05:00
|
|
|
return selectionMode ? null : (
|
2022-06-11 15:13:06 +05:00
|
|
|
<>
|
|
|
|
|
<View
|
|
|
|
|
style={[
|
|
|
|
|
styles.container,
|
|
|
|
|
{
|
2022-08-26 16:19:39 +05:00
|
|
|
marginTop: Platform.OS === "android" ? insets.top : null,
|
2022-06-11 15:13:06 +05:00
|
|
|
backgroundColor: colors.bg,
|
2022-08-26 16:19:39 +05:00
|
|
|
overflow: "hidden",
|
2022-06-11 15:13:06 +05:00
|
|
|
borderBottomWidth: 1,
|
2022-08-26 16:19:39 +05:00
|
|
|
borderBottomColor: hide ? "transparent" : colors.nav,
|
|
|
|
|
justifyContent: "space-between"
|
2022-06-11 15:13:06 +05:00
|
|
|
}
|
|
|
|
|
]}
|
|
|
|
|
>
|
2022-08-26 16:19:39 +05:00
|
|
|
{currentScreen === "Search" ? (
|
2022-06-11 15:13:06 +05:00
|
|
|
<SearchBar />
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<View style={styles.leftBtnContainer}>
|
|
|
|
|
<LeftMenus />
|
|
|
|
|
<Title />
|
|
|
|
|
</View>
|
|
|
|
|
<RightMenus />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2021-04-11 14:04:14 +05:00
|
|
|
</View>
|
2022-06-11 15:13:06 +05:00
|
|
|
</>
|
2021-04-11 14:04:14 +05:00
|
|
|
);
|
|
|
|
|
},
|
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: {
|
2022-08-26 16:19:39 +05:00
|
|
|
flexDirection: "row",
|
2020-09-07 19:19:00 +05:00
|
|
|
zIndex: 11,
|
2022-06-11 15:13:06 +05:00
|
|
|
height: 50,
|
|
|
|
|
maxHeight: 50,
|
2022-08-26 16:19:39 +05:00
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center",
|
2020-09-07 19:19:00 +05:00
|
|
|
paddingHorizontal: 12,
|
2022-08-26 16:19:39 +05:00
|
|
|
width: "100%"
|
2020-09-07 19:19:00 +05:00
|
|
|
},
|
|
|
|
|
leftBtnContainer: {
|
2022-08-26 16:19:39 +05:00
|
|
|
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: {
|
2022-08-26 16:19:39 +05:00
|
|
|
justifyContent: "center",
|
|
|
|
|
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: {
|
2022-08-26 16:19:39 +05:00
|
|
|
flexDirection: "row",
|
|
|
|
|
alignItems: "center"
|
2020-09-07 19:19:00 +05:00
|
|
|
},
|
|
|
|
|
rightBtn: {
|
2022-08-26 16:19:39 +05:00
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "flex-end",
|
2020-09-07 19:19:00 +05:00
|
|
|
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
|
|
|
});
|