diff --git a/lib/modules/admob/Banner.js b/lib/modules/admob/Banner.js index 9ac725ad..70d93ded 100644 --- a/lib/modules/admob/Banner.js +++ b/lib/modules/admob/Banner.js @@ -1,18 +1,29 @@ import React, { PropTypes } from 'react'; import { requireNativeComponent, View } from 'react-native'; +import { statics } from './'; +import { nativeToJSError } from '../../utils'; class Banner extends React.Component { static propTypes = { ...View.propTypes, + // TODO ehesp: cant init this outside of the component; statics isn't defined + ...(() => { + const eventProps = {}; + Object.keys(statics.EventTypes).forEach((key) => { + eventProps[key] = PropTypes.func; + }); + return eventProps; + }), size: PropTypes.string, unitId: PropTypes.string, - onAdLoaded: PropTypes.func, + testing: PropTypes.bool, }; static defaultProps = { size: 'SMART_BANNER', unitId: 'ca-app-pub-3940256099942544/6300978111', // Testing + testing: true, }; constructor() { @@ -23,12 +34,16 @@ class Banner extends React.Component { }; } + /** + * Handle a single banner event and pass to + * any props watching it + * @param nativeEvent + */ onBannerEvent = ({ nativeEvent }) => { if (this.props[nativeEvent.type]) { if (nativeEvent.type === 'onAdFailedToLoad') { - const error = new Error(nativeEvent.payload.message); - error.code = nativeEvent.payload.code; - this.props[nativeEvent.type](error); + const { code, message } = nativeEvent.payload; + this.props[nativeEvent.type](nativeToJSError(code, message)); } else { this.props[nativeEvent.type](nativeEvent.payload || {}); } @@ -37,10 +52,19 @@ class Banner extends React.Component { if (nativeEvent.type === 'onSizeChange') this.updateSize(nativeEvent.payload); }; + /** + * Handle a native onSizeChange event + * @param width + * @param height + */ updateSize = ({ width, height }) => { this.setState({ width, height }); }; + /** + * Render the native component + * @returns {XML} + */ render() { return (