我对React Native还是比较陌生的,并且在ReactJS上有一些经验。我一直在关注文档和教程,但似乎找不到问题在我的stackNavigator中。我正在使用expo在手机上模拟应用程序。
App.js
import "react-native-gesture-handler"
import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import Routes from "./Routes"
export default function App() {
return (
<Routes />
)
}
Routes.js
import React from "react"
import {createStackNavigator} from "react-navigation-stack"
import {NavigationContainer} from "react-navigation"
import Home from "./screens/Home"
import createWorkout from "./screens/createWorkout"
const Stack = createStackNavigator()
export default function Routes(){
return(
<NavigationContainer>
<Stack.Navigator initialRouteName="Home" screenOptions={{gestureEnabled:true}}>
<Stack.Screen name="Home" component={Home} options={{title: 'Home Screen'}}/>
<Stack.Screen name="Create Workout" component={createWorkout} options={{title: 'Create Workout'}}/>
</Stack.Navigator>
</NavigationContainer>
)
}
Home.js
import React from 'react'
import { StyleSheet, Text, View, Button } from 'react-native'
export default function Home(props) {
const {navigation} = props
return (
<View style={styles.container}>
<Text>Workout Creator & Logger</Text>
<Button title="Create Workout" onPress={() => navigation.navigate("createWorkout")} />
</View>
)
}
createWorkout.js
import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
export default function createWorkout(props) {
const {navigation} = props
return (
<View style={styles.container}>
<Text>Create Workout</Text>
</View>
)
}
我省去了样式表,以避免使代码段变得比必要的更长。
我觉得我正在按照文档进行所有操作,而唯一引起我确切问题的搜索是:https://github.com/react-navigation/react-navigation/issues/7499#event-3068928498,案件被移至此案并结案,我看不到评论或找到它。