YH_SectionView.js 1.59 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) {
		console.log(event.nativeEvent);
    	if (!this.props.onClick) {
      		return;
    	}

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

	render() {

		return <YH_SectionView {...this.props} onClick={this._onClick} />;
	}
}

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

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

module.exports = SectionView;