通过数组循环渲染(生成)组件

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
  View,
  Image,
  StyleSheet,
  TouchableOpacity,
  Alert,
  Text
} from 'react-native';

import Size from '../Common/Size';
import Images from '../Common/Images';
import Color from '../Common/Color';

class FAQHeader extends Component {
  constructor(props) {
    super(props);
  
    this.state = {
      tag_selected: 0,
    };
  }
 
  renderCenterBtn(index, value) {
    
      return (
          <TouchableOpacity style = {Styles.btn_center} key = {index}>
                <Text style = {Styles.font_btn_center}>
                    {value} 
                </Text>
          </TouchableOpacity>
        )
     
  }
  render() {
    return (
        <View style = {[Styles.main]} >
            <TouchableOpacity style = {Styles.btn_left_arrow}>
                <Image style = {Styles.image}
                source = {Images.arrow_left}
                >
                </Image>
            </TouchableOpacity>
            <View style = {Styles.view_center}>
                {this.props.centerBtnData.map((value, index) => this.renderCenterBtn(index, value))}
            </View>
            <TouchableOpacity style = {Styles.btn_right_arrow}>
                  <Image style = {Styles.image} 
                   source = {Images.arrow_right}
                  >
                </Image>
            </TouchableOpacity>
        </View>
      )
  }
}

const Styles = StyleSheet.create({
  main: {
    alignSelf: 'stretch',
    height: 40,
    marginTop: 15,
    marginLeft: 15,
    marginRight: 15,
    flexDirection: 'row',
  },
  image: {
    height: 20,
    width: 20,
    resizeMode: 'cover',
  },
  btn_left_arrow: {
    width: 40,
    alignSelf: 'stretch',
    alignItems: 'center',
    justifyContent: 'center',
  },
  view_center: {
    flex: 1,
    flexDirection: 'row',
    alignSelf: 'stretch',
  },
  btn_right_arrow: {
    width: 40,
    alignSelf: 'stretch',
    alignItems: 'center',
    justifyContent: 'center',
  },
  btn_center: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: Color.clearColor,
  },
  font_btn_center: {
    fontSize: 18,
    color: 'rgb(167, 157, 157)',
  },
});

FAQHeader.defaultProps = {
  centerBtnData: [],
};

 
FAQHeader.propTypes = {
  centerBtnData: PropTypes.array,
};

export default FAQHeader;

使用:

<FAQHeader  centerBtnData = {["aa", "bb", 'adsd']}/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值