[admob] move native component to singleton
This commit is contained in:
parent
6d9ffb16a0
commit
9e8281c39a
|
@ -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,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue