美文网首页
react-navigation高性能导航使用之页面tab

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

作者: 既然可以颠覆何必循规蹈矩 | 来源:发表于2017-04-05 16:42 被阅读0次

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

    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);
    

    相关文章

      网友评论

          本文标题:react-navigation高性能导航使用之页面tab

          本文链接:https://www.haomeiwen.com/subject/wkhxattx.html