From fed544c16732c07dd1b6c66f792bb1a784d56daf Mon Sep 17 00:00:00 2001 From: himanshu8443 Date: Thu, 12 Sep 2024 15:59:46 +0530 Subject: [PATCH] feat: add hamburger meu to open drawer --- src/components/Hero.tsx | 39 ++++++++++++++++++++++++----- src/screens/home/Home.tsx | 12 ++++++++- src/screens/settings/Preference.tsx | 30 ++++++++++++++++++++++ 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/components/Hero.tsx b/src/components/Hero.tsx index 48f5267..fcfd285 100644 --- a/src/components/Hero.tsx +++ b/src/components/Hero.tsx @@ -11,17 +11,29 @@ import {HomeStackParamList, SearchStackParamList} from '../App'; import useContentStore from '../lib/zustand/contentStore'; import useHeroStore from '../lib/zustand/herostore'; import {Skeleton} from 'moti/skeleton'; -import {MmmkvCache} from '../lib/Mmkv'; +import {MMKV, MmmkvCache} from '../lib/Mmkv'; import {manifest} from '../lib/Manifest'; import {Info} from '../lib/providers/types'; import {Feather} from '@expo/vector-icons'; +import Ionicons from '@expo/vector-icons/Ionicons'; +import {DrawerLayout} from 'react-native-gesture-handler'; -function Hero() { +function Hero({ + isDrawerOpen, + drawerRef, +}: { + isDrawerOpen: boolean; + drawerRef: React.RefObject; +}) { const [post, setPost] = useState(); const [loading, setLoading] = useState(true); const [searchActive, setSearchActive] = useState(false); const {provider} = useContentStore(state => state); const {hero} = useHeroStore(state => state); + const [showHamburgerMenu] = useState( + MMKV.getBool('showHamburgerMenu') || false, + ); + const [isDrawerDisabled] = useState(MMKV.getBool('disableDrawer') || false); const navigation = useNavigation>(); const searchNavigation = @@ -74,7 +86,23 @@ function Hero() { }); return ( - + + {!searchActive && ( + + { + drawerRef.current?.openDrawer(); + }}> + + + + )} {searchActive && ( )} {!searchActive && ( - setSearchActive(true)}> + setSearchActive(true)}> )} + { const recentlyWatched = useWatchHistoryStore(state => state).history; const ShowRecentlyWatched = MMKV.getBool('showRecentlyWatched'); const drawer = useRef(null); + const [isDrawerOpen, setIsDrawerOpen] = useState(false); const disableDrawer = MMKV.getBool('disableDrawer') || false; const {provider} = useContentStore(state => state); @@ -141,6 +142,15 @@ const Home = ({}: Props) => { drawerType="slide" edgeWidth={70} useNativeAnimations={false} + // onDrawerOpen={() => setIsDrawerOpen(true)} + // onDrawerClose={() => setIsDrawerOpen(false)} + // onDrawerStateChanged={(newState, drawerWillShow) => { + // if (drawerWillShow) { + // setIsDrawerOpen(true); + // } else { + // setIsDrawerOpen(false); + // } + // }} ref={drawer} drawerBackgroundColor={'black'} renderNavigationView={() => @@ -168,7 +178,7 @@ const Home = ({}: Props) => { }} /> }> - + {!loading && recentlyWatched?.length > 0 && diff --git a/src/screens/settings/Preference.tsx b/src/screens/settings/Preference.tsx index fee2373..51e405a 100644 --- a/src/screens/settings/Preference.tsx +++ b/src/screens/settings/Preference.tsx @@ -40,6 +40,10 @@ const Preferences = () => { MMKV.getBool('showMediaControls') || true, ); + const [showHamburgerMenu, setShowHamburgerMenu] = useState( + MMKV.getBool('showHamburgerMenu') || false, + ); + return ( @@ -151,6 +155,28 @@ const Preferences = () => { /> + {/* show hamburger menu */} + {!disableDrawer && ( + + + Show Hamburger Menu + + + { + MMKV.setBool('showHamburgerMenu', !showHamburgerMenu); + setShowHamburgerMenu(!showHamburgerMenu); + ToastAndroid.show( + 'Restart App to Apply Changes', + ToastAndroid.SHORT, + ); + }} + /> + + )} + {/* show media controls */} @@ -179,6 +205,10 @@ const Preferences = () => { onValueChange={() => { MMKV.setBool('showRecentlyWatched', !showRecentlyWatched); setShowRecentlyWatched(!showRecentlyWatched); + ToastAndroid.show( + 'Restart App to Apply Changes', + ToastAndroid.SHORT, + ); }} />