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

136 lines
3.6 KiB
JavaScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
Copyright (C) 2022 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-08-30 16:13:11 +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";
2022-08-30 18:27:09 +05:00
import { useCallback } from "react";
2020-05-10 22:16:55 +05:00
const _Header = () => {
const colors = useThemeStore((state) => state.colors);
const insets = useSafeAreaInsets();
const [hide, setHide] = useState(true);
const selectionMode = useSelectionStore((state) => state.selectionMode);
const currentScreen = useNavigationStore(
(state) => state.currentScreen?.name
);
2022-08-30 18:27:09 +05:00
const onScroll = useCallback(
(data) => {
if (data.y > 150) {
if (!hide) return;
setHide(false);
} else {
if (hide) return;
setHide(true);
}
},
[hide]
);
2020-10-24 10:10:26 +05:00
useEffect(() => {
eSubscribeEvent(eScrollEvent, onScroll);
return () => {
eUnSubscribeEvent(eScrollEvent, onScroll);
};
2022-08-30 18:27:09 +05:00
}, [hide, onScroll]);
2020-05-10 22:16:55 +05:00
return selectionMode ? null : (
<>
<View
style={[
styles.container,
{
marginTop: Platform.OS === "android" ? insets.top : null,
backgroundColor: colors.bg,
overflow: "hidden",
borderBottomWidth: 1,
borderBottomColor: hide ? "transparent" : colors.nav,
justifyContent: "space-between"
}
]}
>
{currentScreen === "Search" ? (
<SearchBar />
) : (
<>
<View style={styles.leftBtnContainer}>
<LeftMenus />
<Title />
</View>
<RightMenus />
</>
)}
</View>
</>
);
};
export const Header = React.memo(_Header, () => true);
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
});