React Native List列表

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

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

const Header=require('./header');

class FirstRN extends Component {
  render() {
    return (
        <View style={styles.flex}>
          <Header></Header>
          <List title="一线城市楼市退烧 有房源一夜跌价160万"></List>
          <List title="上海市民称墓地太贵买不起 买房存骨灰"></List>
          <List title="朝鲜再发视频:摧毁青瓦台 一切化作灰机"></List>
          <List title="生活大爆炸任务原型都好牛掰"></List>
          <ImportantNews news={['一线城市楼市退烧 有房源一夜跌价160万',
                                  '上海市民称墓地太贵买不起 买房存骨灰',
                                  '上海市民称墓地太贵买不起 买房存骨灰',
                                  '上海市民称墓地太贵买不起 买房存骨灰上海市民称墓地太贵买不起 买房存骨灰上海市民称墓地太贵买不起 买房存骨灰上海市民称墓地太贵买不起 买房存骨灰',
                                  '上海市民称墓地太贵买不起 买房存骨灰上海市民称墓地太贵买不起 买房存骨灰上海市民称墓地太贵买不起 买房存骨灰',
                                  '上海市民称墓地太贵买不起 买房存骨灰'
                                  ]}>
          </ImportantNews>
        </View>


    );
  }
}

class List extends  Component {
    render() {
      return (
          <View style={styles.list_item}>
            <Text style={styles.list_item_font}>{this.props.title}</Text>
          </View>
          //{this.props.title} 属性的传递
      );
    }

}

class ImportantNews extends Component {

  //方法
  show(title) {
    alert(title);
  }

  render() {//渲染的方法

    var news = [];//定义数组
    for(var i in this.props.news) {//循环
      var  text = (
          <Text onPress={this.show.bind(this, this.props.news[i])}
                numberOfLines={2}
                style={styles.news_item}
                key={i}>

            {this.props.news[i]}
          </Text>

      );
      news.push(text);//添加到news数组中
    }

   return(
       <View style={styles.flex}>
          <Text style={styles.news_title}>今日要闻</Text>
         {news}
       </View>

   );
  }
}

const styles = StyleSheet.create({
    flex: {
      flex: 1,
    },
    list_item: {
      height: 40,     //高度
      marginLeft: 10, //左边距
      marginRight:10, //右边距
      borderBottomWidth: 1, //底部边框
      borderBottomColor: '#ddd', //底部边框颜色
      justifyContent: 'center', //justify-content 用于设置或检索弹性盒子元素在主轴(横轴)方向上的对齐方式。
    },
    list_item_font: {
      fontSize: 16, //字体大小
    },

    news_title: {
      fontSize: 20,
      fontWeight: 'bold',
      color: '#CD1D1C',
      marginRight: 10,
      marginLeft: 10,
      marginTop: 10,
    },
    news_item: {
      marginLeft: 10,
      marginRight: 10,
      fontSize: 15,
      lineHeight: 40,//line-height 属性设置行间的距离(行高)。注释:不允许使用负值。
      borderBottomWidth: 1, //底部边框
      borderBottomColor: '#ddd', //底部边框颜色

    },
});
AppRegistry.registerComponent('FirstRN', () => FirstRN);

这里写图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值