Files
notesnook/apps/mobile/app/components/header/index.js

115 lines
2.9 KiB
JavaScript
Raw Normal View History

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
() => {
const colors = useThemeStore((state) => state.colors);
2021-04-11 14:04:14 +05:00
const insets = useSafeAreaInsets();
const [hide, setHide] = useState(true);
const selectionMode = useSelectionStore((state) => state.selectionMode);
const currentScreen = useNavigationStore(
(state) => state.currentScreen?.name
);
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);
}
};
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
return selectionMode ? null : (
2022-06-11 15:13:06 +05:00
<>
<View
style={[
styles.container,
{
marginTop: Platform.OS === "android" ? insets.top : null,
2022-06-11 15:13:06 +05:00
backgroundColor: colors.bg,
overflow: "hidden",
2022-06-11 15:13:06 +05:00
borderBottomWidth: 1,
borderBottomColor: hide ? "transparent" : colors.nav,
justifyContent: "space-between"
2022-06-11 15:13:06 +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: {
flexDirection: "row",
2020-09-07 19:19:00 +05:00
zIndex: 11,
2022-06-11 15:13:06 +05:00
height: 50,
maxHeight: 50,
justifyContent: "center",
alignItems: "center",
2020-09-07 19:19:00 +05:00
paddingHorizontal: 12,
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",
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",
alignItems: "center"
2020-09-07 19:19:00 +05:00
},
rightBtn: {
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
});