gpt4 book ai didi

javascript - 使用 Expo 和 Typescript 的 createStackNavigator,不呈现任何内容

转载 作者:搜寻专家 更新时间:2023-10-30 21:32:29 25 4
gpt4 key购买 nike

更新:

Git Repo of NotWorkingProject


尝试使用

react-navigation 包在 React Native(Expo-Typescript)

与我们处理常规 React Native(Expo - Vanilla JS)的方式相同

但它不会在屏幕上呈现任何内容。


AppNavigator.tsx

import {createAppContainer, createStackNavigator} from 'react-navigation';
import * as React from 'react';
import {StyleSheet, View, Text} from 'react-native';

const styles = StyleSheet.create({
container: {
backgroundColor: '#f0f',
flex: 1
}
});

const HomeScreen = () => (
<View style={styles.container}>
<View>
<Text>PLEASE PLEASE PLEASE RENDER THIS</Text>
</View>
</View>
);

HomeScreen.navigationOptions = {
title: 'Home'
};

const AppNavigator = createStackNavigator({Home: HomeScreen});

export default createAppContainer(AppNavigator);

App.tsx

import React from 'react';
import { StyleSheet, Text, View, ViewStyle } from 'react-native';
import AppContainer from './navigation/AppNavigator'

const styles = {
container: {
flex: 1,
backgroundColor: 'red',
alignItems: 'center',
justifyContent: 'center',
} as ViewStyle
};


const App = (style:Object): {} => {
const { container } = styles;
return (
<View style={container}>
<AppContainer/>
</View>
);
}

export default App;

如果需要的话:

package.json

{
dependencies: {
expo: "^34.0.1",
react: "16.8.3",
"react-dom": "^16.8.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-34.0.0.tar.gz",
"react-native-gesture-handler": "^1.3.0",
"react-native-web": "^0.11.4",
"react-navigation": "^3.11.1"
},
devDependencies: {
"@types/react": "^16.8.23",
"@types/react-native": "^0.57.65",
"babel-preset-expo": "^6.0.0",
typescript: "^3.4.5"
}
}

请让我知道哪里出了问题。

最佳答案

您需要导入 AppContainer

import AppNavigator from "./config/router";



import React from 'react';
import { StyleSheet, Text, View, ViewStyle } from 'react-native';
import AppContainer from './navigation/AppNavigator'

const styles = {
container: {
flex: 1,
backgroundColor: 'red',
alignItems: 'center',
justifyContent: 'center',
} as ViewStyle
};


const App = (style:Object): {} => {
const { container } = styles;
return (

<AppContainer/>

);
}
export default App;

关于javascript - 使用 Expo 和 Typescript 的 createStackNavigator,不呈现任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57440630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com