Обновление с React-Navigation v4 до v5 - PullRequest
0 голосов
/ 11 июля 2020

Я создаю приложение с react-native и expo, недавно обновился до React Navigation v5 и не могу понять новую конфигурацию. Ниже приведены мои исходные файлы с использованием конфигурации v4.

AppNavigator. js

import React from 'react';
import { NavigationContainer, createSwitchNavigator } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';


import MainTabNavigator from './MainTabNavigator';
import SignInScreen from '../screens/AuthScreens/SignInScreen';
import AuthLoadingScreen from '../screens/AuthLoadingScreen';
import RegisterScreen from '../screens/AuthScreens/RegisterScreen';
import ResetPasswordScreen from '../screens/AuthScreens/ResetPasswordScreen';

const AuthStack = createStackNavigator({ SignIn: SignInScreen, Register: RegisterScreen, ResetPassword: ResetPasswordScreen });

export default NavigationContainer(
  createStackNavigator({
      AuthLoading: AuthLoadingScreen,
      Main: MainTabNavigator,
      Auth: AuthStack,
    },
    {
      initialRouteName: 'AuthLoading',
    }
  )
);

MainTabNavigator. js

import React from 'react';
import { Platform } from 'react-native';
import firebase from 'firebase';
import "@firebase/firestore";
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';

import TabBarIcon from '../components/TabBarIcon';
import TabBarIcon2 from '../components/TabBarIcon2';
import PlayingScreen from '../screens/PlayingScreens/PlayingScreen';
import CreateGame from '../screens/PlayingScreens/CreateGame';
import CreateHoles from '../screens/PlayingScreens/CreateHoles';
import CreateTeams from '../screens/PlayingScreens/CreateTeams';
import PlayerSetup from '../screens/PlayingScreens/PlayerSetup';
import GameSettings from '../screens/PlayingScreens/GameSettings';
import UpdateTeams from '../screens/PlayingScreens/UpdateTeams';
import PlayerScoresList from '../screens/PlayingScreens/PlayerScoresList';
import PlayerScores from '../screens/PlayingScreens/PlayerScores';
import JoinGame from '../screens/PlayingScreens/JoinGame';
import JoinGame2 from '../screens/PlayingScreens/JoinGame2';
import WaitingScreen from '../screens/PlayingScreens/WaitingScreen';
import CancelGame from '../screens/PlayingScreens/CancelGame';
import CurrentGame from '../screens/PlayingScreens/CurrentGame';
import CurrentGameIndividual from '../screens/PlayingScreens/CurrentGameIndividual';
import Chat from '../screens/PlayingScreens/Chat';
import HistoryScreen from '../screens/HistoryScreens/HistoryScreen';
import HistoryGame from '../screens/HistoryScreens/HistoryGame';
import HistoryGameIndividual from '../screens/HistoryScreens/HistoryGameIndividual';
import HistoryChat from '../screens/HistoryScreens/HistoryChat';
import HistoryPlayerScoreList from '../screens/HistoryScreens/HistoryPlayerScoreList';
import HistoryPlayerScores from '../screens/HistoryScreens/HistoryPlayerScores';
import GamesScreen from '../screens/RulesScreens/GamesScreen';
import GameRules from '../screens/RulesScreens/GameRules';
import CoursesScreen from '../screens/CoursesScreens/CoursesScreen';
import AddCourse from '../screens/CoursesScreens/AddCourse';
import MyCourse from '../screens/CoursesScreens/MyCourse';
import ProfileScreen from '../screens/ProfileScreens/ProfileScreen';
import ChangeEmailScreen from '../screens/ProfileScreens/ChangeEmailScreen';
import ChangePasswordScreen from '../screens/ProfileScreens/ChangePasswordScreen';


const config = Platform.select({
  web: { headerMode: 'screen' },
  default: {},
});

const PlayingStack = createStackNavigator(
  {
    Home: PlayingScreen, CreateGame, JoinGame, CreateHoles, PlayerSetup, CreateTeams, JoinGame2, WaitingScreen, CancelGame, CurrentGame, CurrentGameIndividual, Chat, GameSettings, UpdateTeams, PlayerScoresList, PlayerScores
  },
  config
);

PlayingStack.navigationOptions = {
  tabBarLabel: 'Playing',
  tabBarOptions: { 
    activeTintColor: '#8fc0a9',
    inactiveTintColor: '#b5b5b5',
  },
  tabBarIcon: ({ focused }) => (
    <TabBarIcon
      focused={focused}
      name={
        Platform.OS === 'ios' ? 'ios-play-circle' : 'md-play-circle' }
    />
  ),
};

PlayingStack.path = 'CurrentGame';

const ProfileStack = createStackNavigator(
  {
    Home: ProfileScreen, ChangeEmail: ChangeEmailScreen, ChangePassword: ChangePasswordScreen,
  },
  config
);

ProfileStack.navigationOptions = {
  tabBarLabel: 'Profile',
  tabBarOptions: { 
    activeTintColor: '#8fc0a9',
    inactiveTintColor: '#b5b5b5',
  },
  tabBarIcon: ({ focused }) => (
    <TabBarIcon
      focused={focused}
      name={Platform.OS === 'ios' ? 'ios-person' : 'md-person'}
    />
  ),
};

ProfileStack.path = '';

const HistoryStack = createStackNavigator(
  {
    Home: HistoryScreen, HistoryGame, HistoryGameIndividual, HistoryChat, HistoryPlayerScoreList, HistoryPlayerScores
  },
  config
);

HistoryStack.navigationOptions = {
  tabBarLabel: 'Results',
  tabBarOptions: { 
    activeTintColor: '#8fc0a9',
    inactiveTintColor: '#b5b5b5',
  },
  tabBarIcon: ({ focused }) => (
    <TabBarIcon focused={focused} name={Platform.OS === 'ios' ? 'ios-calendar' : 'md-calendar'} />
  ),
};

HistoryStack.path = '';

const GamesStack = createStackNavigator(
  {
    Games: GamesScreen, GameRules,
  },
  config
);

GamesStack.navigationOptions = {
  tabBarLabel: 'Rules',
  tabBarOptions: { 
    activeTintColor: '#8fc0a9',
    inactiveTintColor: '#b5b5b5',
  },
  tabBarIcon: ({ focused }) => (
    <TabBarIcon focused={focused} name={Platform.OS === 'ios' ? 'ios-paper' : 'md-paper'} />
  ),
};

  GamesStack.path = '';

const CourseStack = createStackNavigator(
  {
    Home: CoursesScreen, AddCourse, MyCourse
  },
  config
);

CourseStack.navigationOptions = {
  tabBarLabel: 'Courses',
  tabBarOptions: { 
    activeTintColor: '#8fc0a9',
    inactiveTintColor: '#b5b5b5',
  },
  tabBarIcon: ({ focused }) => (
    <TabBarIcon2
      focused={focused}
      name={'golf-course'}
    />
  ),
};

  CourseStack.path = '';

const tabNavigator = createBottomTabNavigator({
  PlayingStack,
  HistoryStack,
  GamesStack,
  CourseStack,
  ProfileStack,
});

tabNavigator.path = '';

export default tabNavigator;

Может кто-нибудь, пожалуйста, помогите мне понять, как Я должен переписать приведенный выше код, чтобы он работал с React-Navigation v5 ??

Спасибо

...