就像我在标题中说的,我试图在React导航中显示一个带有.Screen的组件,但由于某种原因,它没有这样做
index.js
import React from 'react'
import { StyleSheet , View, Text } from 'react-native'
import 'react-native-gesture-handler'
import { StatusBar } from 'expo-status-bar'
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import Home from './source/fragments/Home'
export default function App() {
const AuthStack = createStackNavigator()
return (
<View style = { styles.container }>
<StatusBar style = "auto" />
<NavigationContainer>
<AuthStack.Navigator initialRouteName = "Home">
<AuthStack.Screen
name = "Home"
component = {Home}
/>
</AuthStack.Navigator>
</NavigationContainer>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#ffff',
alignItems: 'center'
}
})
Home.js
import React, { Component } from 'react'
import { View, Text } from 'react-native'
export default class Home extends Component {
render() {
return (
<View>
<Text> Home screen </Text>
</View>
)
}
}
谢谢你在这里滚动
4条答案
按热度按时间6g8kf2rb1#
下面的答案都不是我的解决方案,我通过删除
index.js
中的<View>
组件来修复它就像下面的代码:
index.js
8i9zcol22#
导出主组件,如下所示
nx7onnlm3#
我也有同样的问题时,添加新的堆栈到我的导航,只是重新启动应用程序
vu8f3i0k4#
将高度设置为组件:
我使用“尺寸”获取屏幕高度