zoukankan      html  css  js  c++  java
  • reactnative(2)

    'use strict';
    import React, { Component } from 'react';
    import {
      AppRegistry,
      ScrollView,
      StyleSheet,
      Text,
      View,
      TouchableHighlight,
      Navigator,
    } from 'react-native';
    
    class NavButton extends React.Component{
       render(){
         return(
           <TouchableHighlight style={styles.button}
           underlayColor='#b5b5b5' onPress={this.props.onPress}>
           <Text style={styles.text}>{this.props.text}</Text>
           </TouchableHighlight>
         );
       }
    
    }
    class NavMenu extends React.Component{
      render(){
        return(
          <View style={{flex:1,}}>
          <Text style={styles.messageText}>{this.props.message}</Text>
          <NavButton onPress={()=>{this.props.navigator.push({
            message:'Push进来的页面',
            sceneConfig:Navigator.SceneConfigs.FloatFromRight,
          });}} text='Push到下一级页面' />
    
          <NavButton onPress={() => {
                this.props.navigator.push({
                  message: 'Present进来的页面',
                  sceneConfig: Navigator.SceneConfigs.FloatFromBottom,
                });
              }}
              text="Present到下一级页面"
            />
            <NavButton onPress={() => {
                this.props.navigator.pop();
              }}
              text="Pop到上一级页面"
            />
            <NavButton  onPress={() => {
                this.props.navigator.popToTop();
              }}
              text="Pop到主页面"
            />
          </View>
        );
      }
    }
    class MyProject extends Component {
    
      render() {
        return (
          <Navigator style={styles.container}  initialRoute={{message:'主页面',}}
          renderScene={(route,navigator)=><NavMenu
                message={route.message}
                navigator={navigator}
              />} configureScene={(route)=>{
                 if (route.sceneConfig) {
                   return route.sceneConfig;
                 }
                 return Navigator.SceneConfigs.FloatFromBottom;
              }}/>
        );
      }
    
    }
    
    const styles = StyleSheet.create({
      container: {
          flex: 1,
         },
         messageText: {
          fontSize: 14,
          fontWeight: '500',
          padding: 15,
          marginTop: 50,
          marginLeft: 15,
        },
        button: {
          backgroundColor: 'green',
          padding: 15,
          borderBottomWidth: StyleSheet.hairlineWidth,
          borderBottomColor: 'black',
        },
        text:{
          fontSize:14,
          color:'white',
        },
    });
    
    AppRegistry.registerComponent('MyProject', () => MyProject);

    效果图:

    参考案例:

    http://www.lcode.org/%E3%80%90react-native%E5%BC%80%E5%8F%91%E3%80%91react-native%E6%8E%A7%E4%BB%B6%E4%B9%8Bnavigator%E7%BB%84%E4%BB%B6%E8%AF%A6%E8%A7%A3%E4%BB%A5%E5%8F%8A%E5%AE%9E%E4%BE%8B23/

  • 相关阅读:
    创建目录(单个目录和多级子目录)方法
    C++中创建目录
    C/C++中判断某一文件或目录是否存在
    Eclipse快捷键大全(转载)
    关于注册模型失败的分析
    框架Model注册失败
    nop中导航属性的写法
    CodeFirst中导航属性的代码实现 理解
    MVC下验证码
    Androidi学习笔记 1
  • 原文地址:https://www.cnblogs.com/thbbsky/p/5773500.html
Copyright © 2011-2022 走看看