gpt4 book ai didi

ios - react native 选项卡 View

转载 作者:行者123 更新时间:2023-11-29 11:29:18 24 4
gpt4 key购买 nike

我正在构建我的第一个 react-native 应用程序,并使用 react-native-tabview 实现选项卡。卡在错误中:

"TypeError: undefined is not an object (evaluating '_this.props.navigationState.routes.length').

这是我遇到的错误的屏幕截图。

screenshot

import * as React from 'react';
import {
Platform, StyleSheet, Text, View, Dimensions, StatusBar, FlatList, ImageBackground, TextInput
} from 'react-native';
import { TabView, SceneMap } from 'react-native-tab-view';

const FirstRoute = () => (
<View style={[styles.scene, { backgroundColor: '#ff4081' }]} />
);

const SecondRoute = () => (
<View style={[styles.scene, { backgroundColor: '#673ab7' }]} />
);

export default class App extends React.Component {
state = {
index: 0,
routes: [
{ key: 'first', title: 'First' },
{ key: 'second', title: 'Second' },
],
};

render() {
return (
<View style={styles.container}>
<TabView
navigationState={this.state}
renderScene={SceneMap({
first: FirstRoute,
second: SecondRoute,
})}
onIndexChange={index => this.setState({ index })}
initialLayout={{ width: Dimensions.get('window').width }}
style={styles.container}
/>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
marginTop: StatusBar.currentHeight
},

scene: {
flex: 1,
},
});

最佳答案

所以我在这里复制/粘贴并运行了您的代码(使用不同的背景颜色)作为展览小吃:https://snack.expo.io/B1-xKYu2N它正在运行。

如果这是您的第一个项目,最有可能的问题是缺少或安装不正确的包。仔细检查您的 package.json 是否有类似 "react-native-tab-view": "^2.0.1" 的内容。如果它在那里(或在您添加它之后),请尝试从项目目录内的终端中运行 rm -rf ./node_modules && npm install 以删除包并重新安装它们。希望我能提供更多帮助!

关于ios - react native 选项卡 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55161087/

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