BannerView.js 1.01 KB
import React, {Component} from 'react';
import ReactNative from 'react-native';
import PropTypes from 'prop-types';
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: PropTypes.bool,
	items: PropTypes.arrayOf(
		PropTypes.shape({
			src: PropTypes.string.isRequired,
			url: PropTypes.string.isRequired,
		})
	),
	onSelectBanner: PropTypes.func,
};

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

module.exports = BannerView;