0
我有兩個選項卡下面的代碼,我有一個View1.js頁面和View2.js頁面。我想推動這些View1和View2在標籤欄中。如何推TabBar中的視圖爲Android的ReactNative
這是我的代碼。
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View,
TextInput,
Image
} from 'react-native';
var Signin=require('../signin')
var Registration=require('../registration')
var View1=require('./view1')
var View2=require('./view2')
import localStyles from './styles.js'
import componentStyles from '../styles.js'
import TabNavigator from 'react-native-tab-navigator';
class Main extends React.Component{
constructor(props) {
super(props);
this.state = {
selectedTab: 'view1'
};
}
render(){
const { selectedTab } = this.state;
return (
<View style={styles.container}>
<TabNavigator>
<TabNavigator.Item
selected={this.state.selectedTab == 'view1'}
title="SIGNIN"
onPress={() => this.setState({selectedTab:'view1' })}>
{View1}
</TabNavigator.Item>
<TabNavigator.Item
selected={this.state.selectedTab =='view2'}
title="registration"
onPress={() => this.setState({selectedTab:'view2' })}>
{View2}
</TabNavigator.Item>
</TabNavigator>
</View>
)
}
}
const styles = StyleSheet.create(localStyles)
export default Main
而且我view1.js有下面的代碼:
import React, {
AppRegistry,
Component,
Image,
StyleSheet,
Text,
View,
TextInput,
} from 'react-native';
import localStyles from './styles.js'
import componentStyles from '../styles.js'
var view1 = React.createClass({
render(){
return (
<View>
<Text> tab1</Text>
</View>
)
},
})
const styles = StyleSheet.create(localStyles)
export default view1
而且我view2.js有以下代碼:
import React, {
AppRegistry,
Component,
Image,
StyleSheet,
Text,
View,
TextInput,
} from 'react-native';
import localStyles from './styles.js'
import componentStyles from '../styles.js'
var view2 = React.createClass({
render(){
return (
<View>
<Text> tab2</Text>
</View>
)
},
})
const styles = StyleSheet.create(localStyles)
export default view2
我試過這個,但我得到的錯誤只有孩子必須通過一個孩子只有一個智利.. – sandy
每個渲染函數只能返回一個元素。仔細檢查你的,因爲它聽起來像你要返回多個 –