[admob] move native component to singleton

This commit is contained in:
Elliot Hesp 2017-10-20 19:39:45 +01:00
parent fb638ea92f
commit 54c92d0640
1 changed files with 20 additions and 11 deletions

View File

@ -13,13 +13,26 @@ const adMobPropTypes = {
unitId: PropTypes.string.isRequired, unitId: PropTypes.string.isRequired,
request: PropTypes.object, request: PropTypes.object,
video: 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 { class AdMobComponent extends React.Component {
static propTypes = adMobPropTypes; static propTypes = adMobPropTypes;
@ -36,11 +49,7 @@ class AdMobComponent extends React.Component {
height: 0, height: 0,
}; };
this.nativeView = requireNativeComponent(props.class, AdMobComponent, { this.nativeView = getNativeComponent(props.class);
nativeOnly: {
onBannerEvent: true,
},
});
} }
/** /**