reactnative tabnavigator

这种效果相信大家见的很多,那么是怎么实现的呢?使用的是reactNavigation

代码如下

import React,{Component} from 'react';
import {
	View,Text,Image,ActivityIndicator,StyleSheet,Dimensions,Animated,Easing
} from 'react-native';

import {
	StackNavigator,TabNavigator,} from 'react-navigation'

import ShopInfo from './ShopInfo';
import ShopUrl from './ShopUrl';
import ShopEvaluate from './ShopEvaluate';

const {width,height} = Dimensions.get('window');
const tabWidthPadding = (((width)/3)-30)/2;



const MainScreen = TabNavigator({
	shopInfo:{
		screen:ShopInfo,navigationoptions:{
			title:'商品',}
	},shopUrl:{
		screen:ShopUrl,navigationoptions:{
			title:'详情'
		}
	},shopEvaluate:{
		screen:ShopEvaluate,navigationoptions:{
			title:'评价'
		}
	}
},{
	tabBarOptions:{
		activeTintColor:'#000000',inactiveTintColor:'#666666',style:{
			backgroundColor:'white',height:50,},indicatorStyle:{
			height:3,width:30,backgroundColor:'#fa372d',marginLeft:tabWidthPadding,marginRight:tabWidthPadding,justifyContent:'center'
		}
	}
});

const Shop = StackNavigator({
	mainScreen:{
		screen:MainScreen,navigationoptions:{
			gesturesEnabled:true,header:null
		}
	}
})


export default class ShopHomeInfo extends Component{

	constructor(props){
		super(props)

	}

	render(){
		const {params} = this.props.navigation.state;
		return(
			<View style={styles.container}>
				<Shop style={{flex:1}} />
			</View>
		);
	}
}

const styles = StyleSheet.create({
  container:{
  	width:width,height:height,})

ShopInfo.js的代码如下
import React,ScrollView,} from 'react-native';

export default class ShopInfo extends Component{

	constructor(props){
		super(props)
		this.state={

		}
	}

	componentDidMount(){

	}

	render(){
		return(
			<View>
				<Text>商品信息参数是:</Text>
			</View>
		);
	}

}

ShopUrl.js
import React,WebView,} from 'react-native';

export default class ShopUrl extends Component{

	render(){
		return(
			<WebView 
				source={{uri:'http://blog.csdn.net/u010648159/article/details/78636281'}}
				style={{flex:1}}
			/>
		);
	}
}

ShopEvaluate.js
import React,} from 'react-native';

export default class ShopEvaluate extends Component{

	render(){
		return(
			<View style={{width:50,height:50}}>
				<Text>商品评价</Text>
			</View>
		);
	}
}
就是这么的简单,如果如果要在导航栏加上左边返回按钮,就比较麻烦了,大家可以想一想啊!!!!

相关文章

react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...
react 本身提供了克隆组件的方法,但是平时开发中可能很少使...
mobx 是一个简单可扩展的状态管理库,中文官网链接。小编在接...
我们在平常的开发中不可避免的会有很多列表渲染逻辑,在 pc ...