YH_SectionView.js 1.54 KB
import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';

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: PropTypes.arrayOf(
		PropTypes.shape({
			header: PropTypes.shape({
				id: PropTypes.number.isRequired,
				logo: PropTypes.string.isRequired,
				title: PropTypes.string.isRequired,
				post: PropTypes.string.isRequired,
				comment: PropTypes.string.isRequired,
				like: PropTypes.string.isRequired,
			}),
			hot: PropTypes.shape({
				avatar: PropTypes.string,
				title: PropTypes.string,
				content: PropTypes.string.isRequired,
			}),
			new: PropTypes.shape({
				avatar: PropTypes.string,
				title: PropTypes.string,
				content: PropTypes.string.isRequired,
			}),
			num: PropTypes.shape({
				onedayAddNum: PropTypes.number.isRequired,
			}),
		})
	),
	onClick: PropTypes.func,
};

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

module.exports = SectionView;