-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathRNIronSourceInterstitials.js
58 lines (49 loc) · 1.65 KB
/
RNIronSourceInterstitials.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { NativeModules, NativeEventEmitter } from 'react-native';
const RNIronSourceInterstitials = NativeModules.RNIronSourceInterstitials;
const IronSourceInterstialsEventEmitter = new NativeEventEmitter(RNIronSourceInterstitials);
const eventNames = [
'interstitialDidLoad',
'interstitialDidShow',
'interstitialDidFailToShowWithError',
'didClickInterstitial',
'interstitialDidClose',
'interstitialDidOpen',
'interstitialDidFailToLoadWithError'
];
const eventHandlers = eventNames.reduce((result, eventName) => {
result[eventName] = new Map();
return result;
}, {});
const addEventListener = (type, handler) => {
const handlers = eventHandlers[type];
if (!handlers) {
console.warn(`Event with type ${type} does not exist.`);
return;
}
if (handlers.has(handler)) {
console.warn(`Event with type ${type} and handler has already been added.`);
return;
}
handlers.set(handler, IronSourceInterstialsEventEmitter.addListener(type, handler));
};
const removeEventListener = (type, handler) => {
if (!eventHandlers[type] || !eventHandlers[type].has(handler)) {
return;
}
eventHandlers[type].get(handler).remove();
eventHandlers[type].delete(handler);
};
const removeAllListeners = () => {
const count = eventNames.length;
for (let i = 0; i < count; i++) {
IronSourceInterstialsEventEmitter.removeAllListeners(eventNames[i]);
}
};
module.exports = {
...RNIronSourceInterstitials,
loadInterstitial: () => RNIronSourceInterstitials.loadInterstitial(),
showInterstitial: (placementName) => RNIronSourceInterstitials.showInterstitial(placementName),
addEventListener,
removeEventListener,
removeAllListeners
};