Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#14/이전에 삭제됐던 것들 #66

Merged
merged 12 commits into from
May 2, 2024
30 changes: 19 additions & 11 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import HomeIcon from './src/assets/navbar/Home.svg';
import MyPageIcon from './src/assets/navbar/MyPage.svg';
import SignIn from './src/components/Auth/SignIn';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { BottomBarProvider, useBottomBar } from './contexts/BottomBarContext';

export type StackProps = {
Home: undefined;
Expand All @@ -37,17 +38,19 @@ const GlobalTheme = {

function App(): React.JSX.Element {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer theme={GlobalTheme}>
<Stack.Navigator
screenOptions={() => ({
headerShown: false,
})}>
<Stack.Screen name="Home" component={HomeTab} />
<Stack.Screen name="Signin" component={SignIn} />
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
<BottomBarProvider>
<GestureHandlerRootView style={{ flex: 1 }}>
<NavigationContainer theme={GlobalTheme}>
<Stack.Navigator
screenOptions={() => ({
headerShown: false,
})}>
<Stack.Screen name="Home" component={HomeTab} />
<Stack.Screen name="Signin" component={SignIn} />
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
</BottomBarProvider>
);
}

Expand All @@ -59,6 +62,11 @@ export type TabProps = {
const CustomTab = ({ state, descriptors, navigation }: BottomTabBarProps) => {
const loginGuard = useLoginGuard();
const { options } = descriptors;
const { isVisible } = useBottomBar(); // 바텀바 보임/숨김 상태를 가져옵니다.

if (!isVisible) {
return null; // isVisible이 false일 경우 탭바를 렌더링하지 않습니다.
}

return (
<View
Expand Down
34 changes: 34 additions & 0 deletions contexts/BottomBarContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { createContext, useContext, useState, ReactNode } from 'react';

interface BottomBarContextType {
isVisible: boolean;
showBottomBar: () => void;
hideBottomBar: () => void;
}

interface BottomBarProviderProps {
children: ReactNode; // ReactNode 타입을 사용하여 children을 정의합니다.
}

const BottomBarContext = createContext<BottomBarContextType | undefined>(undefined);

export const useBottomBar = () => {
const context = useContext(BottomBarContext);
if (context === undefined) {
throw new Error('useBottomBar must be used within a BottomBarProvider');
}
return context;
};

export const BottomBarProvider: React.FC<BottomBarProviderProps> = ({ children }) => { // 여기서 타입을 명시합니다.
const [isVisible, setIsVisible] = useState(true);

const showBottomBar = () => setIsVisible(true);
const hideBottomBar = () => setIsVisible(false);

return (
<BottomBarContext.Provider value={{ isVisible, showBottomBar, hideBottomBar }}>
{children}
</BottomBarContext.Provider>
);
};
Loading