如何在React Native中将状态对象传递到屏幕?

时间:2020-05-01 08:58:39

标签: reactjs react-native

**我想将setScreen对象传递给Signup屏幕 请告诉我如何通过它,以便可以从“注册”屏幕更改屏幕状态**

import React, { useState } from 'react';
import 'react-native-gesture-handler';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';

import AccountScreen from './src/screens/AccountScreen';
import SigninScreen from './src/screens/SigninScreen';
import SignupScreen from './src/screens/SignupScreen';
import TrackCreateScreen from './src/screens/TrackCreateScreen';
import TrackDetailScreen from './src/screens/TrackDetailScreen';
import TrackListScreen from './src/screens/TrackListScreen';

const Stack = createStackNavigator();
const TrackStack = createStackNavigator();
const Tab = createBottomTabNavigator();

const TrackScreenStack = () => {
  return (
    <TrackStack.Navigator initialRouteName="TrackList">
      <TrackStack.Screen
        name="TrackList"
        component={TrackListScreen}
      />
      <TrackStack.Screen
        name="TrackDetail"
        component={TrackDetailScreen}
      />
    </TrackStack.Navigator>
  )
}

**这里我已经声明了状态对象 我希望在“注册”屏幕中通过 这样我就可以在屏幕堆栈之间切换**

const App = () => {
  const [screen, setScreen] = useState(true);
  return (
    <NavigationContainer>
      {screen ? (
        <Stack.Navigator initialRouteName="Signup">
          <Stack.Screen
            name="Signup"
            component={SignupScreen}
          />
          <Stack.Screen
            name="Signin"
            component={SigninScreen}
          />
        </Stack.Navigator>
      ) :
        <Tab.Navigator>
          <Tab.Screen
            name="Track"
            component={TrackScreenStack}
          />
          <Tab.Screen
            name="Account"
            component={AccountScreen}
          />
          <Tab.Screen
            name="TrackCreate"
            component={TrackCreateScreen}
          />
        </Tab.Navigator>
      }
    </NavigationContainer>
  )
}

export default App;

0 个答案:

没有答案