reactnative tabnavigator

前端之家收集整理的这篇文章主要介绍了reactnative tabnavigator前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

代码如下

  1. import React,{Component} from 'react';
  2. import {
  3. View,Text,Image,ActivityIndicator,StyleSheet,Dimensions,Animated,Easing
  4. } from 'react-native';
  5.  
  6. import {
  7. StackNavigator,TabNavigator,} from 'react-navigation'
  8.  
  9. import ShopInfo from './ShopInfo';
  10. import ShopUrl from './ShopUrl';
  11. import ShopEvaluate from './ShopEvaluate';
  12.  
  13. const {width,height} = Dimensions.get('window');
  14. const tabWidthPadding = (((width)/3)-30)/2;
  15.  
  16.  
  17.  
  18. const MainScreen = TabNavigator({
  19. shopInfo:{
  20. screen:ShopInfo,navigationOptions:{
  21. title:'商品',}
  22. },shopUrl:{
  23. screen:ShopUrl,navigationOptions:{
  24. title:'详情'
  25. }
  26. },shopEvaluate:{
  27. screen:ShopEvaluate,navigationOptions:{
  28. title:'评价'
  29. }
  30. }
  31. },{
  32. tabBarOptions:{
  33. activeTintColor:'#000000',inactiveTintColor:'#666666',style:{
  34. backgroundColor:'white',height:50,},indicatorStyle:{
  35. height:3,width:30,backgroundColor:'#fa372d',marginLeft:tabWidthPadding,marginRight:tabWidthPadding,justifyContent:'center'
  36. }
  37. }
  38. });
  39.  
  40. const Shop = StackNavigator({
  41. mainScreen:{
  42. screen:MainScreen,navigationOptions:{
  43. gesturesEnabled:true,header:null
  44. }
  45. }
  46. })
  47.  
  48.  
  49. export default class ShopHomeInfo extends Component{
  50.  
  51. constructor(props){
  52. super(props)
  53.  
  54. }
  55.  
  56. render(){
  57. const {params} = this.props.navigation.state;
  58. return(
  59. <View style={styles.container}>
  60. <Shop style={{flex:1}} />
  61. </View>
  62. );
  63. }
  64. }
  65.  
  66. const styles = StyleSheet.create({
  67. container:{
  68. width:width,height:height,})

ShopInfo.js的代码如下
  1. import React,ScrollView,} from 'react-native';
  2.  
  3. export default class ShopInfo extends Component{
  4.  
  5. constructor(props){
  6. super(props)
  7. this.state={
  8.  
  9. }
  10. }
  11.  
  12. componentDidMount(){
  13.  
  14. }
  15.  
  16. render(){
  17. return(
  18. <View>
  19. <Text>商品信息参数是:</Text>
  20. </View>
  21. );
  22. }
  23.  
  24. }

ShopUrl.js
  1. import React,WebView,} from 'react-native';
  2.  
  3. export default class ShopUrl extends Component{
  4.  
  5. render(){
  6. return(
  7. <WebView
  8. source={{uri:'http://blog.csdn.net/u010648159/article/details/78636281'}}
  9. style={{flex:1}}
  10. />
  11. );
  12. }
  13. }

ShopEvaluate.js
  1. import React,} from 'react-native';
  2.  
  3. export default class ShopEvaluate extends Component{
  4.  
  5. render(){
  6. return(
  7. <View style={{width:50,height:50}}>
  8. <Text>商品评价</Text>
  9. </View>
  10. );
  11. }
  12. }
就是这么的简单,如果如果要在导航栏加上左边返回按钮,就比较麻烦了,大家可以想一想啊!!!!

猜你在找的React相关文章