react-navigation高性能导航使用之页面tab

国际惯例,先来看看效果图

B6CF840D-C4B3-4737-841C-3C42FAB5DC71.png

使用起来简单

安装

npm install --save react-navigation

然后把我的代码复制。 覆盖你原来的index.ios.js文件即可
跑跑看,然后看看代码完全能懂怎么使用
这里是详细使用教程地址。 https://reactnavigation.org/docs/intro/

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Button,
  Image
} from 'react-native';


import { TabNavigator } from 'react-navigation';

class A extends Component {
  static navigationOptions = {
    tabBar: {
      label: 'A',
      icon: ({ tintColor }) => (
        <Image
           source={{uri:'https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png'}}
          style={[styles.icon, {tintColor: tintColor}]}
        />
      ),
    },
  }

  render() {
    return (
       <View style={styles.container}>
         <Button
            onPress={() => this.props.navigation.navigate('C')}
            title="去第三个页面"
          />
      </View>
    );
  }

}


class B extends React.Component {
  static navigationOptions = {
    tabBar: {
      label: 'B',
      icon: ({ tintColor }) => (
        <Image
          source={{uri:'https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png'}}
          style={[styles.icon, {tintColor: tintColor}]}
        />
      ),
    },
  }

  render() {
    return (
     <View style={styles.container}>
        <Text >第二个页面</Text>
      </View>
    );
  }
}



class C extends React.Component {
  static navigationOptions = {
    tabBar: {
      label: 'C',
      icon: ({ tintColor }) => (
        <Image
          source={{uri:'https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png'}}
          style={[styles.icon, {tintColor: tintColor}]}
        />
      ),
    },
  }

  render() {
    return (

       <View style={styles.container}>
          <Button
            onPress={() => this.props.navigation.goBack()}
            title="第三个页面,点我返回第一个页面"
          />
      </View>
    );
  }
}

class D extends React.Component {
  static navigationOptions = {
    tabBar: {
      label: 'D',
      icon: ({ tintColor }) => (
        <Image
          source={{uri:'https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png'}}
          style={[styles.icon, {tintColor: tintColor}]}
        />
      ),
    },
  }

  render() {
    return (
        <View style={styles.container}>
        <Text >第四个页面</Text>
      </View>
    );
  }
}




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

  icon: {
    width: 26,
    height: 26,
  },
});

  const demo = TabNavigator(
    {
      A: {
        screen: A,
      },

      B: {
        screen: B,
      },

      C: {
        screen: C,
      },

      D: {
        screen: D,
      },

    }, 

    {
      tabBarOptions: {
        activeTintColor: '#FF6400',
      },
    }
  );

AppRegistry.registerComponent('demo', () => demo);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容