YH_SectionView.js 1.57 KB
import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';

let {
	requireNativeComponent
} = ReactNative;

// requireNativeComponent automatically resolves this to "YH_SectionViewManager"
module.exports = requireNativeComponent('YH_SectionView', null);

class SectionView extends React.Component {

	constructor(props) {
		super(props);

    	this._onClick = this._onClick.bind(this);
  	}

  	_onClick(event: Event) {
    	if (!this.props.onClick) {
      		return;
    	}

    	this.props.onClick(event.nativeEvent);
  	}

	render() {
		return <YH_SectionView {...this.props} items={this.props.items} onClick={this._onClick} />;
	}
}

SectionView.propTypes = {
	items: React.PropTypes.arrayOf(
		React.PropTypes.shape({
			header: React.PropTypes.shape({
				id: React.PropTypes.number.isRequired,
				logo: React.PropTypes.string.isRequired,
				title: React.PropTypes.string.isRequired,
				postNum: React.PropTypes.number.isRequired,
				commentNum: React.PropTypes.number.isRequired,
				laudCount: React.PropTypes.number.isRequired,
			}),
			hot: React.PropTypes.shape({
				avatar: React.PropTypes.string,
				content: React.PropTypes.string.isRequired,
			}),
			new: React.PropTypes.shape({
				avatar: React.PropTypes.string,
				content: React.PropTypes.string.isRequired,
			}),
			num: React.PropTypes.shape({
				onedayAddNum: React.PropTypes.number.isRequired,
			}),
		})
	),
	onClick: React.PropTypes.func,
};

let YH_SectionView = requireNativeComponent('YH_SectionView', SectionView);

module.exports = SectionView;