import { View, useWindowDimensions } from "react-native"; import { createDrawerNavigator } from "@react-navigation/drawer"; import { MaterialCommunityIcons, MaterialIcons, Entypo, } from "@expo/vector-icons"; import { useNavigation, CommonActions } from "@react-navigation/native"; import DrawerContent from "~/navigation/DrawerNav/DrawerContent"; import { useDrawerState } from "~/navigation/Context"; import getDefaultDrawerWidth from "~/navigation/DrawerNav/getDefaultDrawerWidth"; import Main from "~/scenes/Main"; import Profile from "~/scenes/Profile"; import Notifications from "~/scenes/Notifications"; import Params from "~/scenes/Params"; import Links from "~/scenes/Links"; import NumberLinks from "~/scenes/NumberLinks"; import Relatives from "~/scenes/Relatives"; import Sheets from "~/scenes/Sheets"; import AlertAggListArchived from "~/scenes/AlertAggListArchived"; import About from "~/scenes/About"; import Contribute from "~/scenes/Contribute"; import Location from "~/scenes/Location"; import Developer from "~/scenes/Developer"; import HelpSignal from "~/scenes/HelpSignal"; import Text from "~/components/Text"; // import ColoredDotLevel from "~/components/ColoredDotLevel"; // import SendAlertConfirm from "~/scenes/SendAlertConfirm"; import NullComponent from "~/components/NullComponent"; import Expired from "~/scenes/Expired"; import NotFound from "~/scenes/NotFound"; import NotFoundOrExpired from "~/scenes/NotFoundOrExpired"; import { useAlertState, navActions, useParamsState, useNotificationsState, } from "~/stores"; import { useTheme } from "~/theme"; import React from "react"; import SendAlertConfirm from "~/scenes/SendAlertConfirm"; import SendAlertFinder from "~/scenes/SendAlertFinder"; const Drawer = createDrawerNavigator(); export default React.memo(function DrawerNav() { // console.debug("Render Drawer", new Date()); const [drawerState, setDrawerState] = useDrawerState(); const { colors, custom } = useTheme(); const iconProps = { size: 20, color: colors.primary, }; const iconFocusedProps = { color: colors.onBackground, }; const dimensions = useWindowDimensions(); const navigation = useNavigation(); const { maxAlertingLevel, alertingListLength } = useAlertState([ "maxAlertingLevel", "alertingListLength", ]); const { newCount } = useNotificationsState(["newCount"]); const maxAlertingColor = maxAlertingLevel ? custom.appColors[maxAlertingLevel] : null; const { devModeEnabled } = useParamsState(["devModeEnabled"]); return ( } drawerStyle={{ width: getDefaultDrawerWidth(dimensions), }} screenOptions={{ headerShown: false, }} screenListeners={{ state: (e) => { navActions.updateRouteFromDrawer(e.data.state); }, }} > {/* start Main section, names are related to ~/stores/nav */} ( ), }} listeners={{ focus: () => setDrawerState({ topTabFocused: "SendAlert", homeFocused: true, }), blur: () => setDrawerState({ topTabFocused: "", homeFocused: false, topTabPrev: "SendAlert", }), }} /> ( Alertes {maxAlertingLevel && ( ({alertingListLength}) )} ), drawerIcon: ({ focused }) => ( <> {/* */} ), unmountOnBlur: true, }} listeners={{ beforeRemove: (e) => { // Prevent default navigation e.preventDefault(); setDrawerState({ topTabFocused: "AlertAgg", homeFocused: true, }); // Handle navigation manually navigation.dispatch( CommonActions.navigate({ name: "AlertAgg", params: { screen: "AlertAggTab", params: { screen: "AlertAggList", }, }, }), ); }, blur: () => setDrawerState({ topTabFocused: "", homeFocused: false, topTabPrev: "AlertAgg", }), }} /> ( ), }} listeners={{ focus: () => setDrawerState({ topTabFocused: "AlertCur", homeFocused: true, }), blur: () => setDrawerState({ topTabFocused: "", homeFocused: false, topTabPrev: "AlertCur", }), }} /> {/* end Main section */} ( ), onItemPress: () => { navigation.navigate("SendAlertConfirm", { level: "yellow", confirmed: true, forceCallEmergency: true, }); }, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> ( Notifications {newCount > 0 && ( ({newCount}) )} ), drawerIcon: ({ focused }) => ( 0 ? "notifications-active" : "notifications-none" } {...iconProps} {...(focused ? iconFocusedProps : {})} /> ), unmountOnBlur: true, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> ( ), unmountOnBlur: true, }} listeners={{}} /> {devModeEnabled && ( ( ), unmountOnBlur: true, }} listeners={{}} /> )} ); });