zoukankan      html  css  js  c++  java
  • React Native商城项目实战09

    1.新建组件CommonMyCell.js 

    /**
     * 个人中心自定义cell
     */
    import React, { Component } from 'react';
    import {
        AppRegistry,
        StyleSheet,
        Text,
        View,
        Image,
        TouchableOpacity,
        Platform,
    } from 'react-native';
    
    // ES5
    var MyCell = React.createClass({
        getDefaultProps(){
            return{
                leftIconName:'',    // cell左侧图标
                leftTitle:'',   // cell左侧标题
                rightIconName:'',   //  cell右侧图标
                rightTitle:'',  // cell右侧标题
            }
        },
    
        render() {
            return (
                <TouchableOpacity onPress={()=>{alert('点击了')}}>
                    <View style={styles.container}>
                        <View style={styles.leftViewStyle}>
                            <Image source={{uri:this.props.leftIconName}} style={styles.leftImgStyle} />
                            <Text style={styles.leftTitleStyle}>{this.props.leftTitle}</Text>
                        </View>
                        <View style={styles.rightViewStyle}>
                            {this.rightSubView()}
                        </View>
                    </View>
                </TouchableOpacity>
            );
        },
    
        // cell右侧子视图
        rightSubView(){
            return(
                <View style={{flexDirection:'row',alignItems:'center'}}>
                    {this.renderRightContent()}
                    <Image source={{uri:'icon_cell_rightArrow'}} style={{8, height:13, marginRight:8, marginLeft:5}} />
                </View>
            )
        },
    
        // cell右侧具体内容
        renderRightContent(){
            if(this.props.rightIconName.length == 0){   // 不返回图片
                return(
                    <Text style={{color:'gray'}}>{this.props.rightTitle}</Text>
                )
            }else{
                <Image source={{uri:this.props.rightIconName}} style={{24, height:13}} />
            }
        },
    });
    
    const styles = StyleSheet.create({
        container: {
            // 主轴的方向
            flexDirection:'row',
            // 主轴的对齐方式
            justifyContent:'space-between',
            // 背景颜色
            backgroundColor:'white',
            // 垂直居中
            alignItems:'center',
            // 高度
            height:Platform.OS == 'ios' ? 40 : 36,
    
            // 下边框
            borderBottomColor:'#e8e8e8',
            borderBottomWidth:0.5
        },
        leftViewStyle:{
            // 主轴的方向
            flexDirection:'row',
            // 侧轴居中
            alignItems:'center',
            // 左外边距
            marginLeft:8
        },
    
        rightViewStyle:{
    
        },
    
        leftImgStyle:{ // 左边的图片
            24,
            height:24,
            marginRight:6,
            // 圆角
            borderRadius:12
        },
    
        leftTitleStyle:{
            fontSize:16
        }
    });
    
    // 输出
    module.exports = MyCell;
     
    

    2.Mine.js里如何使用?

    /**
     * 我的
     */
    import React, { Component } from 'react';
    import {
        AppRegistry,
        StyleSheet,
        Text,
        View,
        ScrollView
    } from 'react-native';
    
    /*======导入外部组件类======*/
    var MyCell = require('./CommonMyCell');
    
    // ES5
    var Mine = React.createClass({
        render() {
            return (
                <ScrollView>
                    <View style={{marginTop:20}}>
                        <MyCell
                            leftIconName="draft"
                            leftTitle="钱包"
                            rightTitle="账户余额:¥100.88"
                        />
                    </View>
                </ScrollView>
            );
        }
    });
    
    const styles = StyleSheet.create({
    
    });
    
    // 输出
    module.exports = Mine;
    

    3.效果图

  • 相关阅读:
    老男孩Day17作业:后台管理平台编辑表格
    老男孩Day16作业:登录、注册、后台管理页面(动态)
    老男孩Day15作业:商城列表页面(静态)
    老男孩Day14作业:堡垒机
    老男孩Day13作业:ORM学员管理系统
    老男孩Day12作业:RabbitMQ-RPC版主机管理程序
    老男孩Day10作业:主机管理程序
    老男孩Day9作业:高级FTP
    面试遇见钓鱼公司怎么办?
    宝能技术岗面试
  • 原文地址:https://www.cnblogs.com/crazycode2/p/7375837.html
Copyright © 2011-2022 走看看