From c1b9b5d53230416d52ed79ea6106af0df63cdf64 Mon Sep 17 00:00:00 2001 From: Ben Richards Date: Sun, 20 Aug 2017 22:58:40 -0700 Subject: [PATCH] moved EventTypes to new file to avoid enumerable key in AdMobComponent.propTypes --- lib/modules/admob/AdMobComponent.js | 44 +++++++++++------------------ lib/modules/admob/EventTypes.js | 21 ++++++++++++++ lib/modules/admob/index.js | 27 ++++++------------ 3 files changed, 45 insertions(+), 47 deletions(-) create mode 100644 lib/modules/admob/EventTypes.js diff --git a/lib/modules/admob/AdMobComponent.js b/lib/modules/admob/AdMobComponent.js index 2d53877b..a8bc1da9 100644 --- a/lib/modules/admob/AdMobComponent.js +++ b/lib/modules/admob/AdMobComponent.js @@ -1,39 +1,28 @@ import React from 'react'; import { ViewPropTypes, requireNativeComponent } from 'react-native'; import PropTypes from 'prop-types'; -import { statics } from './'; +import EventTypes, { NativeExpressEventTypes } from './EventTypes'; import { nativeToJSError } from '../../utils'; import AdRequest from './AdRequest'; import VideoOptions from './VideoOptions'; +const adMobPropTypes = { + ...ViewPropTypes, + size: PropTypes.string.isRequired, + unitId: PropTypes.string.isRequired, + request: PropTypes.object, + video: PropTypes.object, +} +Object.keys(EventTypes).forEach(eventType => { + adMobPropTypes[eventType] = PropTypes.func; +}); +Object.keys(NativeExpressEventTypes).forEach(eventType => { + adMobPropTypes[eventType] = PropTypes.func; +}); + class AdMobComponent extends React.Component { - - static propTypes = { - ...ViewPropTypes, - - // 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; - }), - - ...(() => { - const eventProps = {}; - Object.keys(statics.NativeExpressEventTypes).forEach((key) => { - eventProps[key] = PropTypes.func; - }); - return eventProps; - }), - - size: PropTypes.string.isRequired, - unitId: PropTypes.string.isRequired, - request: PropTypes.object, - video: PropTypes.object, - }; + static propTypes = adMobPropTypes; static defaultProps = { request: new AdRequest().addTestDevice().build(), @@ -94,7 +83,6 @@ class AdMobComponent extends React.Component { /> ); } - } export default AdMobComponent; diff --git a/lib/modules/admob/EventTypes.js b/lib/modules/admob/EventTypes.js new file mode 100644 index 00000000..d4343633 --- /dev/null +++ b/lib/modules/admob/EventTypes.js @@ -0,0 +1,21 @@ + +export default { + onAdLoaded: 'onAdLoaded', + onAdOpened: 'onAdOpened', + onAdLeftApplication: 'onAdLeftApplication', + onAdClosed: 'onAdClosed', + onAdFailedToLoad: 'onAdFailedToLoad', +}; + +export const NativeExpressEventTypes = { + onVideoEnd: 'onVideoEnd', + onVideoMute: 'onVideoMute', + onVideoPause: 'onVideoPause', + onVideoPlay: 'onVideoPlay', + onVideoStart: 'onVideoStart', +}; + +export const RewardedVideoEventTypes = { + onRewarded: 'onRewarded', + onRewardedVideoStarted: 'onRewardedVideoStarted', +}; \ No newline at end of file diff --git a/lib/modules/admob/index.js b/lib/modules/admob/index.js index 5eb969ff..f9096404 100644 --- a/lib/modules/admob/index.js +++ b/lib/modules/admob/index.js @@ -7,7 +7,11 @@ import AdRequest from './AdRequest'; import VideoOptions from './VideoOptions'; import Banner from './Banner'; import NativeExpress from './NativeExpress'; -import { Base } from './../base'; +import EventTypes, { + NativeExpressEventTypes, + RewardedVideoEventTypes +} from './EventTypes' +import { Base } from '../base'; const FirebaseAdMob = NativeModules.RNFirebaseAdMob; const FirebaseAdMobEvt = FirebaseAdMob && new NativeEventEmitter(FirebaseAdMob); @@ -87,22 +91,7 @@ export const statics = { NativeExpress, AdRequest, VideoOptions, - EventTypes: { - onAdLoaded: 'onAdLoaded', - onAdOpened: 'onAdOpened', - onAdLeftApplication: 'onAdLeftApplication', - onAdClosed: 'onAdClosed', - onAdFailedToLoad: 'onAdFailedToLoad', - }, - RewardedVideoEventTypes: { - onRewarded: 'onRewarded', - onRewardedVideoStarted: 'onRewardedVideoStarted', - }, - NativeExpressEventTypes: { - onVideoEnd: 'onVideoEnd', - onVideoMute: 'onVideoMute', - onVideoPause: 'onVideoPause', - onVideoPlay: 'onVideoPlay', - onVideoStart: 'onVideoStart', - }, + EventTypes, + RewardedVideoEventTypes, + NativeExpressEventTypes };