当我应该在Index.js页面而不是Routes.js文件上定义我的页面“ React Navigation的道具”时?
随着我的应用程序大小的增加,我的routes.js文件变得太大了,是在页面index.js中配置每个页面选项/属性还是一个更好的做法,还是我应该继续将所有配置存储在我的路线上? js文件?
我的Routes.js文件
import React from 'react';
import { useSelector } from 'react-redux';
import Icon from 'react-native-vector-icons/MaterialIcons';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import SignIn from './pages/SigIn';
import SignUp from './pages/SignUp';
import SelectProvider from './pages/New/SelectProvider';
import SelectDateTime from './pages/New/SelectDateTime';
import Confirm from './pages/New/Confirm';
import Dashboard from './pages/Dashboard';
import Profile from './pages/Profile';
const AppStack = createStackNavigator();
const Tab = createBottomTabNavigator();
function New() {
return (
<AppStack.Navigator
screenOptions={{
headerTransparent: true,
headerTintColor: '#FFF',
headerLeftContainerStyle: {
marginLeft: 20,
},
}}
>
<AppStack.Screen
name="SelectProvider"
component={SelectProvider}
options={{
title: 'Selecione o prestador',
headerTitleAlign: 'center',
}}
/>
<AppStack.Screen name="SelectDateTime" component={SelectDateTime} />
<AppStack.Screen name="Confirm" component={Confirm} />
</AppStack.Navigator>
);
}
function Home() {
return (
<Tab.Navigator
tabBarOptions={{
keyboardHidesTabBar: true,
activeTintColor: '#FFF',
inactiveTintColor: 'rgba(255, 255, 255, 0.6)',
style: {
backgroundColor: '#8d41a8',
borderTopColor: '#8d41a8',
},
}}
>
<Tab.Screen
name="Dashboard"
component={Dashboard}
options={{
tabBarLabel: 'Agendamentos',
tabBarIcon: () => <Icon name="event" size={20} color="#fff" />,
}}
/>
<Tab.Screen
name="New"
component={New}
options={{
tabBarVisible: false,
tabBarLabel: 'Agendar',
tabBarIcon: () => (
<Icon name="add-circle-outline" size={20} color="#fff" />
),
}}
/>
<Tab.Screen
name="Profile"
component={Profile}
options={{
tabBarLabel: 'Perfil',
tabBarIcon: () => <Icon name="person" size={20} color="#fff" />,
}}
/>
</Tab.Navigator>
);
}
export default function Routes() {
const Signed = useSelector((state) => state.auth.signed);
return (
<NavigationContainer>
<AppStack.Navigator
initialRouteName={Signed ? 'Home' : 'SignIn'}
screenOptions={{ headerShown: false }}
>
<AppStack.Screen name="SignIn" component={SignIn} />
<AppStack.Screen name="SignUp" component={SignUp} />
<AppStack.Screen name="Home" component={Home} />
</AppStack.Navigator>
</NavigationContainer>
);
}
我的提供程序页面中带有标题选项
import React from 'react';
import { TouchableOpacity } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import Background from '~/components/Background';
export default function SelectProvider({ navigation }) {
navigation.setOptions({
headerLeft: () => (
<TouchableOpacity
onPress={() => {
navigation.navigate('Dashboard');
}}
>
<Icon name="chevron-left" size={20} color="#fff" />
</TouchableOpacity>
),
});
return <View />;
}