UNPKG

npmchenwei111

Version:

test1111

98 lines (81 loc) 2.02 kB
/** * Created by chenwei on 2017/7/17. */ import React, { Component } from 'react' import { StyleSheet, Text, View } from 'react-native' import { px, sp } from '../../utils/Px2dp' import R from '../../assets/R' const PropTypes = require('prop-types'); class CompanyTagView extends Component { //设置必须属性的检测 static propTypes = { // nav: PropTypes.object.isRequired, } constructor (props) { super(props) this._initData() } //初始化state _initData () { this.data = { fontSize: sp(12), color: R.color.white, tags: [], ...this.props.data } } //@Override 重写方法 componentWillReceiveProps (nextProps) { this.data = {...this.data, ...nextProps.data} } render () { console.log(this.data.tags, 'CompanyTagView1') return ( <View style={[styles.container, this.props.style]}> { this._renderItem(this.data.tags) } </View> ) } _renderItem (tags) { console.log(tags, 'CompanyTagView2') let arr = [] if (!tags) return arr for (let i = 0; i < tags.length; i++) { if (!tags[i]) continue arr.push(<View key={i} style={{ flexDirection: 'row', alignItems: 'center', paddingLeft: px(7), paddingRight: px(7), paddingTop: px(2), paddingBottom: px(2), borderRadius: px(3), borderColor: this.data.color, borderWidth: px(0.8), marginRight: px(8), marginTop: px(8), }} > <Text style={{ color: this.data.color, fontSize: this.data.fontSize, backgroundColor: R.color.transparent }}>{tags[i].labelName} </Text> </View> ) } return arr } } const styles = StyleSheet.create({ container: { flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', } }) export default CompanyTagView