Skip to content

Commit

Permalink
Pushing the hiding headers when we are in login page
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis95Yang committed Feb 28, 2024
1 parent b3c06c5 commit 3dea292
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum ACCOUNT_NAVIGATOR_ROUTES {
LOGIN = 'LOGIN',

Check failure

Code scanning / ESLint

disallow unused variables Error

'LOGIN' is defined but never used.
REGISTER = 'REGISTER',

Check failure

Code scanning / ESLint

disallow unused variables Error

'REGISTER' is defined but never used.
PROFILE = 'PROFILE',

Check failure

Code scanning / ESLint

disallow unused variables Error

'PROFILE' is defined but never used.
}

export type AccountNavigatorParamList = {
[ACCOUNT_NAVIGATOR_ROUTES.LOGIN]: undefined;
[ACCOUNT_NAVIGATOR_ROUTES.REGISTER]: undefined;
[ACCOUNT_NAVIGATOR_ROUTES.PROFILE]: undefined;
};
34 changes: 27 additions & 7 deletions src/components/navigators/AccountNavigator/AccountNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,45 @@ import {useSelector} from 'react-redux';

import {createNativeStackNavigator} from '@react-navigation/native-stack';
import Example from '../../../screens/example/example.tsx';
import {ACCOUNT_NAVIGATOR_ROUTES} from './account-navigator.interfaces.ts';
import {
ACCOUNT_NAVIGATOR_ROUTES,
AccountNavigatorParamList,
} from './AccountNavigator.interfaces.ts';
import LoginScreen from '../../../screens/login/LoginScreen.tsx';

const Stack = createNativeStackNavigator();
const Stack = createNativeStackNavigator<AccountNavigatorParamList>();

export default function AccountNavigator() {
// @ts-ignore
const {user} = useSelector(state => state.user);
if (user) {
return (
<Stack.Navigator
initialRouteName={ACCOUNT_NAVIGATOR_ROUTES.PROFILE}
screenOptions={{
headerShown: false,
orientation: 'portrait_up',
}}>
<Stack.Screen
name={ACCOUNT_NAVIGATOR_ROUTES.PROFILE}
component={Example}
/>
</Stack.Navigator>
);
}
return (
<Stack.Navigator
initialRouteName={
user ? ACCOUNT_NAVIGATOR_ROUTES.LOGIN : ACCOUNT_NAVIGATOR_ROUTES.PROFILE
}
initialRouteName={ACCOUNT_NAVIGATOR_ROUTES.LOGIN}
screenOptions={{
headerShown: false,
orientation: 'portrait_up',
}}>
<Stack.Screen name={ACCOUNT_NAVIGATOR_ROUTES.LOGIN} component={Example} />
<Stack.Screen
name={ACCOUNT_NAVIGATOR_ROUTES.PROFILE}
name={ACCOUNT_NAVIGATOR_ROUTES.LOGIN}
component={LoginScreen}
/>
<Stack.Screen
name={ACCOUNT_NAVIGATOR_ROUTES.REGISTER}
component={Example}
/>
</Stack.Navigator>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export enum TAB_BAR_NAVIGATOR_ROUTES {
ACCOUNT = 'ACCOUNT',

Check failure

Code scanning / ESLint

disallow unused variables Error

'ACCOUNT' is defined but never used.
CARROT = 'CARROT',

Check failure

Code scanning / ESLint

disallow unused variables Error

'CARROT' is defined but never used.
SEARCH = 'SEARCH',

Check failure

Code scanning / ESLint

disallow unused variables Error

'SEARCH' is defined but never used.
QRSCAN = 'QRSCAN',

Check failure

Code scanning / ESLint

disallow unused variables Error

'QRSCAN' is defined but never used.
PLATE = 'PLATE',

Check failure

Code scanning / ESLint

disallow unused variables Error

'PLATE' is defined but never used.
}

export type TabBarNavigatorParamList = {
[TAB_BAR_NAVIGATOR_ROUTES.ACCOUNT]: undefined;
[TAB_BAR_NAVIGATOR_ROUTES.CARROT]: undefined;
[TAB_BAR_NAVIGATOR_ROUTES.SEARCH]: undefined;
[TAB_BAR_NAVIGATOR_ROUTES.QRSCAN]: undefined;
[TAB_BAR_NAVIGATOR_ROUTES.PLATE]: undefined;
};
36 changes: 25 additions & 11 deletions src/components/navigators/TabBarNavigation/TabNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import {useNavigation} from '@react-navigation/native';

import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import AccountNavigator from '../AccountNavigator';
import {ACCOUNT_NAVIGATOR_ROUTES} from '../AccountNavigator/account-navigator.interfaces.ts';
import {ACCOUNT_NAVIGATOR_ROUTES} from '../AccountNavigator/AccountNavigator.interfaces.ts';
import CarrotScreen from '../../../screens/carrot/CarrotScreen';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {
TAB_BAR_NAVIGATOR_ROUTES,
TabBarNavigatorParamList,
} from './TabNavigator.interfaces.ts';

const Tab = createBottomTabNavigator();
const Tab = createBottomTabNavigator<TabBarNavigatorParamList>();

const PlateScreen = () => null;
const QRScanScreen = () => null;
Expand All @@ -26,7 +30,7 @@ const TabNavigator = () => {
} else {
console.log('user token not found');
// @ts-ignore
navigate('Account');
navigate(TAB_BAR_NAVIGATOR_ROUTES.LOGIN);
}
});
}, [navigate]);
Expand All @@ -37,42 +41,52 @@ const TabNavigator = () => {
({color, size}: {color: ColorValue; size: number}) =>
<Icon name={name} color={color} size={size} />;

Check warning

Code scanning / ESLint

Disallow creating unstable components inside components Warning

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “TabNavigator” and pass data as props.
return (
<Tab.Navigator initialRouteName="Carrot">
<Tab.Navigator
initialRouteName={TAB_BAR_NAVIGATOR_ROUTES.ACCOUNT}
screenOptions={{
headerShown: false,
}}>
<Tab.Screen
name="Carrot"
name={TAB_BAR_NAVIGATOR_ROUTES.CARROT}
component={CarrotScreen}
options={{
tabBarIcon: renderIcon('carrot'),
}}
/>
<Tab.Screen
name="Plate"
name={TAB_BAR_NAVIGATOR_ROUTES.PLATE}
component={PlateScreen}
options={{
tabBarIcon: renderIcon('food'),
}}
/>
<Tab.Screen
name="QRScan"
name={TAB_BAR_NAVIGATOR_ROUTES.QRSCAN}
component={QRScanScreen}
options={{
tabBarIcon: renderIcon('qrcode-scan'),
}}
/>
<Tab.Screen
name="Search"
name={TAB_BAR_NAVIGATOR_ROUTES.SEARCH}
component={SearchScreen}
options={{
tabBarIcon: renderIcon('magnify'),
}}
/>
<Tab.Screen
name="Account"
name={TAB_BAR_NAVIGATOR_ROUTES.ACCOUNT}
component={AccountNavigator}
options={({route}) => {
const routeName = getFocusedRouteNameFromRoute(route) ?? '';
if (routeName === ACCOUNT_NAVIGATOR_ROUTES.LOGIN) {
console.log('routeName', routeName);
console.log(routeName);

if (routeName === ACCOUNT_NAVIGATOR_ROUTES.PROFILE) {
return {
tabBarIcon: renderIcon('account'),
};
}
if (routeName === ACCOUNT_NAVIGATOR_ROUTES.LOGIN || routeName === ACCOUNT_NAVIGATOR_ROUTES.REGISTER) {

Check failure

Code scanning / ESLint

Replace routeName·===·ACCOUNT_NAVIGATOR_ROUTES.LOGIN·||·routeName·===·ACCOUNT_NAVIGATOR_ROUTES.REGISTER with ⏎············routeName·===·ACCOUNT_NAVIGATOR_ROUTES.LOGIN·||⏎············routeName·===·ACCOUNT_NAVIGATOR_ROUTES.REGISTER⏎·········· Error

Replace routeName·===·ACCOUNT\_NAVIGATOR\_ROUTES.LOGIN·||·routeName·===·ACCOUNT\_NAVIGATOR\_ROUTES.REGISTER with ⏎············routeName·===·ACCOUNT\_NAVIGATOR\_ROUTES.LOGIN·||⏎············routeName·===·ACCOUNT\_NAVIGATOR\_ROUTES.REGISTER⏎··········
return {
tabBarStyle: {
display: 'none',
Expand Down

0 comments on commit 3dea292

Please sign in to comment.