BannerView.js 1.01 KB
import React, {Component} from 'react';
import ReactNative from 'react-native';

let { requireNativeComponent } = ReactNative;

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

class BannerView extends React.Component {

	constructor(props) {
		super(props);

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

  	_onSelectBanner(event: Event) {

    	if (!this.props.onSelectBanner) {
      		return;
    	}

    	this.props.onSelectBanner(event.nativeEvent.url);
  	}

	render() {

		return <YH_BannerView {...this.props} onPress={this._onSelectBanner} />;
	}
}

BannerView.propTypes = {
	autoLooping: React.PropTypes.bool,
	items: React.PropTypes.arrayOf(
		React.PropTypes.shape({
			src: React.PropTypes.string.isRequired,
			url: React.PropTypes.string.isRequired,
		})
	),
	onSelectBanner: React.PropTypes.func,
};

let YH_BannerView = requireNativeComponent('YH_BannerView', BannerView);

module.exports = BannerView;