UNPKG

npmchenwei111

Version:

test1111

103 lines (85 loc) 2.1 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' import Device from '../../utils/Device' import Utils from '../../utils/Utils' const PropTypes = require('prop-types'); class CompanyInformListView extends Component { //设置必须属性的检测 static propTypes = { // nav: PropTypes.object.isRequired, } constructor (props) { super(props) this._initData() } //初始化state _initData () { this.data = { informs: [], ...this.props.data } } //@Override 重写方法 componentWillReceiveProps (nextProps) { this.data = {...this.data, ...nextProps.data} } render () { return ( <View style={styles.container}> { this._renderQuestion(this.data.informs) } </View> ) } /** * 渲染常见问题 * @param questions * @private */ _renderQuestion (array) { let arr = [] if (Utils.isEmpty(array)) return arr for (let inform of array) { arr.push(<View key={arr.length} style={{ flexDirection: 'column', marginLeft: px(16), marginTop: px(12), marginBottom: px(12) }}> <Text style={{marginLeft: px(2), fontSize: sp(18), color: R.color.font_black}}> {inform.title} </Text> <Text style={{ fontSize: sp(14), color: R.color.font_gray, marginLeft: px(2), marginTop: px(6), lineHeight: px(25) }}> {inform.content} </Text> </View>) if (arr.length < array.length * 2 - 1) { arr.push(<View key={arr.length} style={{ backgroundColor: R.color.gray_line, marginLeft: px(16), height: px(0.5) }}/>) } } return arr } } const styles = StyleSheet.create({ container: { flexDirection: 'column', width: Device.width } }) export default CompanyInformListView