diff --git a/lib/modules/admob/AdMobComponent.js b/lib/modules/admob/AdMobComponent.js index a8bc1da9..36ec08d0 100644 --- a/lib/modules/admob/AdMobComponent.js +++ b/lib/modules/admob/AdMobComponent.js @@ -13,13 +13,26 @@ const adMobPropTypes = { 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; +}); + +const nativeComponents = {}; + +function getNativeComponent(name) { + if (nativeComponents[name]) return nativeComponents[name]; + const component = requireNativeComponent(name, AdMobComponent, { + nativeOnly: { + onBannerEvent: true, + }, + }); + nativeComponents[name] = component; + return component; } -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 = adMobPropTypes; @@ -36,11 +49,7 @@ class AdMobComponent extends React.Component { height: 0, }; - this.nativeView = requireNativeComponent(props.class, AdMobComponent, { - nativeOnly: { - onBannerEvent: true, - }, - }); + this.nativeView = getNativeComponent(props.class); } /**