@bigcrunch/react-native-ads 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +417 -0
- package/android/build.gradle +70 -0
- package/android/settings.gradle +6 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/bigcrunch/ads/react/BigCrunchAdsModule.kt +653 -0
- package/android/src/main/java/com/bigcrunch/ads/react/BigCrunchAdsPackage.kt +20 -0
- package/android/src/main/java/com/bigcrunch/ads/react/BigCrunchBannerViewManager.kt +296 -0
- package/ios/BigCrunchAdsModule.swift +588 -0
- package/ios/BigCrunchBannerViewManager.swift +270 -0
- package/ios/react-native-bigcrunch-ads-Bridging-Header.h +8 -0
- package/lib/BigCrunchAds.d.ts +168 -0
- package/lib/BigCrunchAds.d.ts.map +1 -0
- package/lib/BigCrunchAds.js +241 -0
- package/lib/BigCrunchBannerView.d.ts +21 -0
- package/lib/BigCrunchBannerView.d.ts.map +1 -0
- package/lib/BigCrunchBannerView.js +176 -0
- package/lib/BigCrunchInterstitial.d.ts +66 -0
- package/lib/BigCrunchInterstitial.d.ts.map +1 -0
- package/lib/BigCrunchInterstitial.js +222 -0
- package/lib/BigCrunchRewarded.d.ts +85 -0
- package/lib/BigCrunchRewarded.d.ts.map +1 -0
- package/lib/BigCrunchRewarded.js +257 -0
- package/lib/NativeBigCrunchAds.d.ts +71 -0
- package/lib/NativeBigCrunchAds.d.ts.map +1 -0
- package/lib/NativeBigCrunchAds.js +54 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +32 -0
- package/lib/types/ads.d.ts +101 -0
- package/lib/types/ads.d.ts.map +1 -0
- package/lib/types/ads.js +4 -0
- package/lib/types/config.d.ts +137 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +4 -0
- package/lib/types/events.d.ts +306 -0
- package/lib/types/events.d.ts.map +1 -0
- package/lib/types/events.js +4 -0
- package/lib/types/index.d.ts +175 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +23 -0
- package/package.json +88 -0
- package/react-native-bigcrunch-ads.podspec +27 -0
- package/src/BigCrunchAds.ts +298 -0
- package/src/BigCrunchBannerView.tsx +262 -0
- package/src/BigCrunchInterstitial.ts +266 -0
- package/src/BigCrunchRewarded.ts +307 -0
- package/src/NativeBigCrunchAds.ts +120 -0
- package/src/index.ts +71 -0
- package/src/types/ads.ts +112 -0
- package/src/types/config.ts +145 -0
- package/src/types/events.ts +337 -0
- package/src/types/index.ts +193 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigCrunchBannerView - React Native component for displaying banner ads
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import type { BigCrunchBannerViewProps } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* React component for displaying BigCrunch banner ads
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <BigCrunchBannerView
|
|
12
|
+
* placementId="banner-home"
|
|
13
|
+
* size="BANNER"
|
|
14
|
+
* onAdLoaded={() => console.log('Ad loaded')}
|
|
15
|
+
* onAdFailedToLoad={(error) => console.error('Ad failed to load', error)}
|
|
16
|
+
* />
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const BigCrunchBannerView: React.FC<BigCrunchBannerViewProps>;
|
|
20
|
+
export default BigCrunchBannerView;
|
|
21
|
+
//# sourceMappingURL=BigCrunchBannerView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BigCrunchBannerView.d.ts","sourceRoot":"","sources":["../src/BigCrunchBannerView.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAkD,MAAM,OAAO,CAAC;AASvE,OAAO,KAAK,EACV,wBAAwB,EAKzB,MAAM,SAAS,CAAC;AAmBjB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CA+MlE,CAAC;AAGF,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigCrunchBannerView - React Native component for displaying banner ads
|
|
3
|
+
*/
|
|
4
|
+
import React, { useEffect, useRef, useCallback, useMemo } from 'react';
|
|
5
|
+
import { requireNativeComponent, StyleSheet, findNodeHandle, UIManager, } from 'react-native';
|
|
6
|
+
import { BigCrunchAdsEventEmitter, NativeEventNames } from './NativeBigCrunchAds';
|
|
7
|
+
// Native component name
|
|
8
|
+
const NATIVE_COMPONENT_NAME = 'BigCrunchBannerView';
|
|
9
|
+
// Banner size dimensions
|
|
10
|
+
const BANNER_SIZES = {
|
|
11
|
+
BANNER: { width: 320, height: 50 },
|
|
12
|
+
LARGE_BANNER: { width: 320, height: 100 },
|
|
13
|
+
MEDIUM_RECTANGLE: { width: 300, height: 250 },
|
|
14
|
+
FULL_BANNER: { width: 468, height: 60 },
|
|
15
|
+
LEADERBOARD: { width: 728, height: 90 },
|
|
16
|
+
ADAPTIVE: { width: -1, height: -1 }, // Calculated dynamically
|
|
17
|
+
SMART: { width: -1, height: -1 }, // Deprecated, use ADAPTIVE
|
|
18
|
+
};
|
|
19
|
+
// Native view component
|
|
20
|
+
const NativeBannerView = requireNativeComponent(NATIVE_COMPONENT_NAME);
|
|
21
|
+
/**
|
|
22
|
+
* React component for displaying BigCrunch banner ads
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* <BigCrunchBannerView
|
|
27
|
+
* placementId="banner-home"
|
|
28
|
+
* size="BANNER"
|
|
29
|
+
* onAdLoaded={() => console.log('Ad loaded')}
|
|
30
|
+
* onAdFailedToLoad={(error) => console.error('Ad failed to load', error)}
|
|
31
|
+
* />
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const BigCrunchBannerView = ({ placementId, size = 'BANNER', autoLoad = true, refreshInterval = 0, customTargeting, style, onAdLoaded, onAdFailedToLoad, onAdImpression, onAdClicked, onAdOpened, onAdClosed, onAdRevenue, }) => {
|
|
35
|
+
const viewRef = useRef(null);
|
|
36
|
+
const subscriptionsRef = useRef([]);
|
|
37
|
+
const viewIdRef = useRef(`banner_${placementId}_${Date.now()}`);
|
|
38
|
+
// Calculate banner size
|
|
39
|
+
const bannerSize = useMemo(() => {
|
|
40
|
+
if (typeof size === 'object' && 'width' in size && 'height' in size) {
|
|
41
|
+
// Custom size
|
|
42
|
+
return size;
|
|
43
|
+
}
|
|
44
|
+
else if (typeof size === 'string' && size in BANNER_SIZES) {
|
|
45
|
+
// Predefined size
|
|
46
|
+
const dimensions = BANNER_SIZES[size];
|
|
47
|
+
if (dimensions.width === -1 || dimensions.height === -1) {
|
|
48
|
+
// Adaptive/Smart banner - will be calculated natively
|
|
49
|
+
return { width: 0, height: 0, adaptive: true };
|
|
50
|
+
}
|
|
51
|
+
return dimensions;
|
|
52
|
+
}
|
|
53
|
+
// Default to BANNER size
|
|
54
|
+
return BANNER_SIZES.BANNER;
|
|
55
|
+
}, [size]);
|
|
56
|
+
// Handle native events
|
|
57
|
+
const handleNativeEvent = useCallback((_eventName, handler) => {
|
|
58
|
+
return (event) => {
|
|
59
|
+
// Check if event is for this specific banner view
|
|
60
|
+
if (event.viewId === viewIdRef.current || event.placementId === placementId) {
|
|
61
|
+
handler?.(event);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}, [placementId]);
|
|
65
|
+
// Setup event listeners
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const subscriptions = [];
|
|
68
|
+
if (onAdLoaded) {
|
|
69
|
+
subscriptions.push(BigCrunchAdsEventEmitter.addListener(NativeEventNames.BANNER_AD_LOADED, handleNativeEvent(NativeEventNames.BANNER_AD_LOADED, onAdLoaded)));
|
|
70
|
+
}
|
|
71
|
+
if (onAdFailedToLoad) {
|
|
72
|
+
subscriptions.push(BigCrunchAdsEventEmitter.addListener(NativeEventNames.BANNER_AD_FAILED_TO_LOAD, handleNativeEvent(NativeEventNames.BANNER_AD_FAILED_TO_LOAD, (event) => {
|
|
73
|
+
const error = {
|
|
74
|
+
code: event.errorCode || 'UNKNOWN',
|
|
75
|
+
message: event.errorMessage || 'Ad failed to load',
|
|
76
|
+
underlyingError: event.underlyingError,
|
|
77
|
+
};
|
|
78
|
+
onAdFailedToLoad(error);
|
|
79
|
+
})));
|
|
80
|
+
}
|
|
81
|
+
if (onAdImpression) {
|
|
82
|
+
subscriptions.push(BigCrunchAdsEventEmitter.addListener(NativeEventNames.BANNER_AD_IMPRESSION, handleNativeEvent(NativeEventNames.BANNER_AD_IMPRESSION, onAdImpression)));
|
|
83
|
+
}
|
|
84
|
+
if (onAdClicked) {
|
|
85
|
+
subscriptions.push(BigCrunchAdsEventEmitter.addListener(NativeEventNames.BANNER_AD_CLICKED, handleNativeEvent(NativeEventNames.BANNER_AD_CLICKED, onAdClicked)));
|
|
86
|
+
}
|
|
87
|
+
if (onAdOpened) {
|
|
88
|
+
subscriptions.push(BigCrunchAdsEventEmitter.addListener(NativeEventNames.BANNER_AD_OPENED, handleNativeEvent(NativeEventNames.BANNER_AD_OPENED, onAdOpened)));
|
|
89
|
+
}
|
|
90
|
+
if (onAdClosed) {
|
|
91
|
+
subscriptions.push(BigCrunchAdsEventEmitter.addListener(NativeEventNames.BANNER_AD_CLOSED, handleNativeEvent(NativeEventNames.BANNER_AD_CLOSED, onAdClosed)));
|
|
92
|
+
}
|
|
93
|
+
if (onAdRevenue) {
|
|
94
|
+
subscriptions.push(BigCrunchAdsEventEmitter.addListener(NativeEventNames.BANNER_AD_REVENUE, handleNativeEvent(NativeEventNames.BANNER_AD_REVENUE, (event) => {
|
|
95
|
+
const revenue = {
|
|
96
|
+
valueMicros: event.valueMicros,
|
|
97
|
+
currencyCode: event.currencyCode,
|
|
98
|
+
adUnitId: event.adUnitId,
|
|
99
|
+
precision: event.precision,
|
|
100
|
+
};
|
|
101
|
+
onAdRevenue(revenue);
|
|
102
|
+
})));
|
|
103
|
+
}
|
|
104
|
+
subscriptionsRef.current = subscriptions;
|
|
105
|
+
// Cleanup on unmount
|
|
106
|
+
return () => {
|
|
107
|
+
subscriptions.forEach(sub => sub.remove());
|
|
108
|
+
subscriptionsRef.current = [];
|
|
109
|
+
};
|
|
110
|
+
}, [
|
|
111
|
+
placementId,
|
|
112
|
+
handleNativeEvent,
|
|
113
|
+
onAdLoaded,
|
|
114
|
+
onAdFailedToLoad,
|
|
115
|
+
onAdImpression,
|
|
116
|
+
onAdClicked,
|
|
117
|
+
onAdOpened,
|
|
118
|
+
onAdClosed,
|
|
119
|
+
onAdRevenue,
|
|
120
|
+
]);
|
|
121
|
+
// Load ad programmatically
|
|
122
|
+
const loadAd = useCallback(() => {
|
|
123
|
+
if (viewRef.current) {
|
|
124
|
+
const handle = findNodeHandle(viewRef.current);
|
|
125
|
+
if (handle) {
|
|
126
|
+
const viewManagerConfig = UIManager.getViewManagerConfig(NATIVE_COMPONENT_NAME);
|
|
127
|
+
const command = viewManagerConfig?.Commands?.loadAd;
|
|
128
|
+
if (command !== undefined) {
|
|
129
|
+
UIManager.dispatchViewManagerCommand(handle, command, []);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}, []);
|
|
134
|
+
// Auto-load ad on mount if enabled
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (autoLoad) {
|
|
137
|
+
// Delay to ensure native view is ready
|
|
138
|
+
const timer = setTimeout(loadAd, 100);
|
|
139
|
+
return () => clearTimeout(timer);
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
142
|
+
}, [autoLoad, loadAd]);
|
|
143
|
+
// Container styles
|
|
144
|
+
const containerStyle = useMemo(() => {
|
|
145
|
+
const baseStyle = {
|
|
146
|
+
width: bannerSize.width > 0 ? bannerSize.width : 320,
|
|
147
|
+
height: bannerSize.height > 0 ? bannerSize.height : 50,
|
|
148
|
+
// Remove overflow: 'hidden' to avoid clipping the ad content
|
|
149
|
+
};
|
|
150
|
+
if (bannerSize.adaptive) {
|
|
151
|
+
// Adaptive banner - let it size itself
|
|
152
|
+
baseStyle.alignSelf = 'stretch';
|
|
153
|
+
baseStyle.width = '100%';
|
|
154
|
+
}
|
|
155
|
+
return StyleSheet.flatten([baseStyle, style]);
|
|
156
|
+
}, [bannerSize, style]);
|
|
157
|
+
// Native view props
|
|
158
|
+
// Always pass explicit dimensions to the native view
|
|
159
|
+
const nativeProps = {
|
|
160
|
+
ref: viewRef,
|
|
161
|
+
style: containerStyle,
|
|
162
|
+
placementId,
|
|
163
|
+
size: typeof size === 'string' ? size : 'CUSTOM',
|
|
164
|
+
// Always pass width and height, even for standard sizes
|
|
165
|
+
customWidth: bannerSize.width > 0 ? bannerSize.width : undefined,
|
|
166
|
+
customHeight: bannerSize.height > 0 ? bannerSize.height : undefined,
|
|
167
|
+
autoLoad,
|
|
168
|
+
refreshInterval,
|
|
169
|
+
customTargeting,
|
|
170
|
+
viewId: viewIdRef.current,
|
|
171
|
+
};
|
|
172
|
+
// Return the native view directly with the container style
|
|
173
|
+
return React.createElement(NativeBannerView, { ...nativeProps });
|
|
174
|
+
};
|
|
175
|
+
// Export as default
|
|
176
|
+
export default BigCrunchBannerView;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigCrunchInterstitial - API for interstitial ads
|
|
3
|
+
*/
|
|
4
|
+
import type { InterstitialAd, AdRequestOptions, AdEvent, AdEventListener, EventSubscription } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Static API for BigCrunch interstitial ads
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Load an interstitial
|
|
11
|
+
* await BigCrunchInterstitial.load({ placementId: 'interstitial-level-complete' });
|
|
12
|
+
*
|
|
13
|
+
* // Show when ready
|
|
14
|
+
* if (await BigCrunchInterstitial.isLoaded('interstitial-level-complete')) {
|
|
15
|
+
* await BigCrunchInterstitial.show('interstitial-level-complete');
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare class BigCrunchInterstitial {
|
|
20
|
+
private static instances;
|
|
21
|
+
/**
|
|
22
|
+
* Load an interstitial ad
|
|
23
|
+
*
|
|
24
|
+
* @param options - Ad request options including placementId
|
|
25
|
+
*/
|
|
26
|
+
static load(options: AdRequestOptions): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Show a loaded interstitial ad
|
|
29
|
+
*
|
|
30
|
+
* @param placementId - The placement ID of the ad to show
|
|
31
|
+
*/
|
|
32
|
+
static show(placementId: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Check if an interstitial is loaded and ready to show
|
|
35
|
+
*
|
|
36
|
+
* @param placementId - The placement ID to check
|
|
37
|
+
*/
|
|
38
|
+
static isLoaded(placementId: string): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Destroy an interstitial instance
|
|
41
|
+
*
|
|
42
|
+
* @param placementId - The placement ID of the ad to destroy
|
|
43
|
+
*/
|
|
44
|
+
static destroy(placementId: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Destroy all interstitial instances
|
|
47
|
+
*/
|
|
48
|
+
static destroyAll(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Create an interstitial ad instance
|
|
51
|
+
* Alternative to static methods for more control
|
|
52
|
+
*
|
|
53
|
+
* @param placementId - The placement ID for this ad
|
|
54
|
+
*/
|
|
55
|
+
static createAd(placementId: string): InterstitialAd;
|
|
56
|
+
/**
|
|
57
|
+
* Add event listener for a specific placement
|
|
58
|
+
*
|
|
59
|
+
* @param placementId - The placement ID to listen to
|
|
60
|
+
* @param eventType - The event type to listen for
|
|
61
|
+
* @param listener - The callback function
|
|
62
|
+
*/
|
|
63
|
+
static addEventListener<T extends AdEvent>(placementId: string, eventType: T['type'], listener: AdEventListener<T>): EventSubscription;
|
|
64
|
+
}
|
|
65
|
+
export default BigCrunchInterstitial;
|
|
66
|
+
//# sourceMappingURL=BigCrunchInterstitial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BigCrunchInterstitial.d.ts","sourceRoot":"","sources":["../src/BigCrunchInterstitial.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,eAAe,EACf,iBAAiB,EAGlB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;GAaG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAA6C;IAErE;;;;OAIG;WACU,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAa3D;;;;OAIG;WACU,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrD;;;;OAIG;WACU,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ5D;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAQzC;;OAEG;IACH,MAAM,CAAC,UAAU,IAAI,IAAI;IAKzB;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc;IASpD;;;;;;OAMG;IACH,MAAM,CAAC,gBAAgB,CAAC,CAAC,SAAS,OAAO,EACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EACpB,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,GAC3B,iBAAiB;CASrB;AAqID,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigCrunchInterstitial - API for interstitial ads
|
|
3
|
+
*/
|
|
4
|
+
import { NativeBigCrunchAds, BigCrunchAdsEventEmitter, NativeEventNames } from './NativeBigCrunchAds';
|
|
5
|
+
/**
|
|
6
|
+
* Static API for BigCrunch interstitial ads
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Load an interstitial
|
|
11
|
+
* await BigCrunchInterstitial.load({ placementId: 'interstitial-level-complete' });
|
|
12
|
+
*
|
|
13
|
+
* // Show when ready
|
|
14
|
+
* if (await BigCrunchInterstitial.isLoaded('interstitial-level-complete')) {
|
|
15
|
+
* await BigCrunchInterstitial.show('interstitial-level-complete');
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export class BigCrunchInterstitial {
|
|
20
|
+
static instances = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* Load an interstitial ad
|
|
23
|
+
*
|
|
24
|
+
* @param options - Ad request options including placementId
|
|
25
|
+
*/
|
|
26
|
+
static async load(options) {
|
|
27
|
+
const { placementId } = options;
|
|
28
|
+
// Create or get existing instance
|
|
29
|
+
let instance = this.instances.get(placementId);
|
|
30
|
+
if (!instance) {
|
|
31
|
+
instance = new InterstitialAdInstance(placementId);
|
|
32
|
+
this.instances.set(placementId, instance);
|
|
33
|
+
}
|
|
34
|
+
return instance.load(options);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Show a loaded interstitial ad
|
|
38
|
+
*
|
|
39
|
+
* @param placementId - The placement ID of the ad to show
|
|
40
|
+
*/
|
|
41
|
+
static async show(placementId) {
|
|
42
|
+
const instance = this.instances.get(placementId);
|
|
43
|
+
if (!instance) {
|
|
44
|
+
throw new Error(`No interstitial loaded for placement: ${placementId}`);
|
|
45
|
+
}
|
|
46
|
+
return instance.show();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if an interstitial is loaded and ready to show
|
|
50
|
+
*
|
|
51
|
+
* @param placementId - The placement ID to check
|
|
52
|
+
*/
|
|
53
|
+
static async isLoaded(placementId) {
|
|
54
|
+
const instance = this.instances.get(placementId);
|
|
55
|
+
if (!instance) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return instance.isLoaded();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Destroy an interstitial instance
|
|
62
|
+
*
|
|
63
|
+
* @param placementId - The placement ID of the ad to destroy
|
|
64
|
+
*/
|
|
65
|
+
static destroy(placementId) {
|
|
66
|
+
const instance = this.instances.get(placementId);
|
|
67
|
+
if (instance) {
|
|
68
|
+
instance.destroy();
|
|
69
|
+
this.instances.delete(placementId);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Destroy all interstitial instances
|
|
74
|
+
*/
|
|
75
|
+
static destroyAll() {
|
|
76
|
+
this.instances.forEach(instance => instance.destroy());
|
|
77
|
+
this.instances.clear();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create an interstitial ad instance
|
|
81
|
+
* Alternative to static methods for more control
|
|
82
|
+
*
|
|
83
|
+
* @param placementId - The placement ID for this ad
|
|
84
|
+
*/
|
|
85
|
+
static createAd(placementId) {
|
|
86
|
+
let instance = this.instances.get(placementId);
|
|
87
|
+
if (!instance) {
|
|
88
|
+
instance = new InterstitialAdInstance(placementId);
|
|
89
|
+
this.instances.set(placementId, instance);
|
|
90
|
+
}
|
|
91
|
+
return instance;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Add event listener for a specific placement
|
|
95
|
+
*
|
|
96
|
+
* @param placementId - The placement ID to listen to
|
|
97
|
+
* @param eventType - The event type to listen for
|
|
98
|
+
* @param listener - The callback function
|
|
99
|
+
*/
|
|
100
|
+
static addEventListener(placementId, eventType, listener) {
|
|
101
|
+
const instance = this.instances.get(placementId);
|
|
102
|
+
if (!instance) {
|
|
103
|
+
const newInstance = new InterstitialAdInstance(placementId);
|
|
104
|
+
this.instances.set(placementId, newInstance);
|
|
105
|
+
return newInstance.addEventListener(eventType, listener);
|
|
106
|
+
}
|
|
107
|
+
return instance.addEventListener(eventType, listener);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Internal interstitial ad instance
|
|
112
|
+
*/
|
|
113
|
+
class InterstitialAdInstance {
|
|
114
|
+
placementId;
|
|
115
|
+
subscriptions = [];
|
|
116
|
+
listeners = new Map();
|
|
117
|
+
constructor(placementId) {
|
|
118
|
+
this.placementId = placementId;
|
|
119
|
+
this.setupEventListeners();
|
|
120
|
+
}
|
|
121
|
+
async load(options) {
|
|
122
|
+
return NativeBigCrunchAds.loadInterstitial(options);
|
|
123
|
+
}
|
|
124
|
+
async show() {
|
|
125
|
+
return NativeBigCrunchAds.showInterstitial(this.placementId);
|
|
126
|
+
}
|
|
127
|
+
async isLoaded() {
|
|
128
|
+
return NativeBigCrunchAds.isInterstitialLoaded(this.placementId);
|
|
129
|
+
}
|
|
130
|
+
destroy() {
|
|
131
|
+
this.removeAllListeners();
|
|
132
|
+
NativeBigCrunchAds.destroyInterstitial(this.placementId).catch(console.error);
|
|
133
|
+
}
|
|
134
|
+
addEventListener(eventType, listener) {
|
|
135
|
+
// Add to local listeners
|
|
136
|
+
if (!this.listeners.has(eventType)) {
|
|
137
|
+
this.listeners.set(eventType, new Set());
|
|
138
|
+
}
|
|
139
|
+
// Cast listener to base type for storage - runtime behavior is the same
|
|
140
|
+
const typedListener = listener;
|
|
141
|
+
this.listeners.get(eventType).add(typedListener);
|
|
142
|
+
// Return subscription
|
|
143
|
+
return {
|
|
144
|
+
remove: () => {
|
|
145
|
+
const listeners = this.listeners.get(eventType);
|
|
146
|
+
if (listeners) {
|
|
147
|
+
listeners.delete(typedListener);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
removeAllListeners() {
|
|
153
|
+
this.subscriptions.forEach(sub => sub.remove());
|
|
154
|
+
this.subscriptions = [];
|
|
155
|
+
this.listeners.clear();
|
|
156
|
+
}
|
|
157
|
+
setupEventListeners() {
|
|
158
|
+
const eventMap = {
|
|
159
|
+
adLoaded: NativeEventNames.INTERSTITIAL_AD_LOADED,
|
|
160
|
+
adFailedToLoad: NativeEventNames.INTERSTITIAL_AD_FAILED_TO_LOAD,
|
|
161
|
+
adImpression: NativeEventNames.INTERSTITIAL_AD_IMPRESSION,
|
|
162
|
+
adClicked: NativeEventNames.INTERSTITIAL_AD_CLICKED,
|
|
163
|
+
adOpened: NativeEventNames.INTERSTITIAL_AD_OPENED,
|
|
164
|
+
adClosed: NativeEventNames.INTERSTITIAL_AD_CLOSED,
|
|
165
|
+
adRevenue: NativeEventNames.INTERSTITIAL_AD_REVENUE,
|
|
166
|
+
};
|
|
167
|
+
Object.entries(eventMap).forEach(([eventType, nativeEvent]) => {
|
|
168
|
+
const subscription = BigCrunchAdsEventEmitter.addListener(nativeEvent, (event) => {
|
|
169
|
+
// Check if event is for this placement
|
|
170
|
+
if (event.placementId === this.placementId) {
|
|
171
|
+
// Transform event data if needed
|
|
172
|
+
let transformedEvent;
|
|
173
|
+
switch (eventType) {
|
|
174
|
+
case 'adFailedToLoad':
|
|
175
|
+
transformedEvent = {
|
|
176
|
+
type: eventType,
|
|
177
|
+
placementId: this.placementId,
|
|
178
|
+
format: 'interstitial',
|
|
179
|
+
timestamp: Date.now(),
|
|
180
|
+
error: {
|
|
181
|
+
code: event.errorCode || 'UNKNOWN',
|
|
182
|
+
message: event.errorMessage || 'Ad failed to load',
|
|
183
|
+
underlyingError: event.underlyingError,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
break;
|
|
187
|
+
case 'adRevenue':
|
|
188
|
+
transformedEvent = {
|
|
189
|
+
type: eventType,
|
|
190
|
+
placementId: this.placementId,
|
|
191
|
+
format: 'interstitial',
|
|
192
|
+
timestamp: Date.now(),
|
|
193
|
+
revenue: {
|
|
194
|
+
valueMicros: event.valueMicros,
|
|
195
|
+
currencyCode: event.currencyCode,
|
|
196
|
+
adUnitId: event.adUnitId,
|
|
197
|
+
precision: event.precision,
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
break;
|
|
201
|
+
default:
|
|
202
|
+
transformedEvent = {
|
|
203
|
+
type: eventType,
|
|
204
|
+
placementId: this.placementId,
|
|
205
|
+
format: 'interstitial',
|
|
206
|
+
timestamp: Date.now(),
|
|
207
|
+
...event,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
// Notify local listeners
|
|
211
|
+
const listeners = this.listeners.get(eventType);
|
|
212
|
+
if (listeners) {
|
|
213
|
+
listeners.forEach(listener => listener(transformedEvent));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
this.subscriptions.push(subscription);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// Export as default
|
|
222
|
+
export default BigCrunchInterstitial;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigCrunchRewarded - API for rewarded ads
|
|
3
|
+
*/
|
|
4
|
+
import type { RewardedAd, AdRequestOptions, AdEvent, AdEventListener, EventSubscription } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Static API for BigCrunch rewarded ads
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Load a rewarded ad
|
|
11
|
+
* await BigCrunchRewarded.load({ placementId: 'rewarded-extra-life' });
|
|
12
|
+
*
|
|
13
|
+
* // Set up reward listener
|
|
14
|
+
* BigCrunchRewarded.addEventListener(
|
|
15
|
+
* 'rewarded-extra-life',
|
|
16
|
+
* 'rewardEarned',
|
|
17
|
+
* (event) => {
|
|
18
|
+
* console.log(`User earned ${event.rewardAmount} ${event.rewardType}`);
|
|
19
|
+
* }
|
|
20
|
+
* );
|
|
21
|
+
*
|
|
22
|
+
* // Show when ready
|
|
23
|
+
* if (await BigCrunchRewarded.isLoaded('rewarded-extra-life')) {
|
|
24
|
+
* await BigCrunchRewarded.show('rewarded-extra-life');
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class BigCrunchRewarded {
|
|
29
|
+
private static instances;
|
|
30
|
+
/**
|
|
31
|
+
* Load a rewarded ad
|
|
32
|
+
*
|
|
33
|
+
* @param options - Ad request options including placementId
|
|
34
|
+
*/
|
|
35
|
+
static load(options: AdRequestOptions): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Show a loaded rewarded ad
|
|
38
|
+
*
|
|
39
|
+
* @param placementId - The placement ID of the ad to show
|
|
40
|
+
*/
|
|
41
|
+
static show(placementId: string): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a rewarded ad is loaded and ready to show
|
|
44
|
+
*
|
|
45
|
+
* @param placementId - The placement ID to check
|
|
46
|
+
*/
|
|
47
|
+
static isLoaded(placementId: string): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Destroy a rewarded ad instance
|
|
50
|
+
*
|
|
51
|
+
* @param placementId - The placement ID of the ad to destroy
|
|
52
|
+
*/
|
|
53
|
+
static destroy(placementId: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Destroy all rewarded ad instances
|
|
56
|
+
*/
|
|
57
|
+
static destroyAll(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Create a rewarded ad instance
|
|
60
|
+
* Alternative to static methods for more control
|
|
61
|
+
*
|
|
62
|
+
* @param placementId - The placement ID for this ad
|
|
63
|
+
*/
|
|
64
|
+
static createAd(placementId: string): RewardedAd;
|
|
65
|
+
/**
|
|
66
|
+
* Add event listener for a specific placement
|
|
67
|
+
*
|
|
68
|
+
* @param placementId - The placement ID to listen to
|
|
69
|
+
* @param eventType - The event type to listen for
|
|
70
|
+
* @param listener - The callback function
|
|
71
|
+
*/
|
|
72
|
+
static addEventListener<T extends AdEvent>(placementId: string, eventType: T['type'], listener: AdEventListener<T>): EventSubscription;
|
|
73
|
+
/**
|
|
74
|
+
* Convenience method to listen for reward earned events
|
|
75
|
+
*
|
|
76
|
+
* @param placementId - The placement ID to listen to
|
|
77
|
+
* @param listener - Callback when user earns reward
|
|
78
|
+
*/
|
|
79
|
+
static onRewardEarned(placementId: string, listener: (reward: {
|
|
80
|
+
rewardType: string;
|
|
81
|
+
rewardAmount: number;
|
|
82
|
+
}) => void): EventSubscription;
|
|
83
|
+
}
|
|
84
|
+
export default BigCrunchRewarded;
|
|
85
|
+
//# sourceMappingURL=BigCrunchRewarded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BigCrunchRewarded.d.ts","sourceRoot":"","sources":["../src/BigCrunchRewarded.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,OAAO,EACP,eAAe,EACf,iBAAiB,EAIlB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAyC;IAEjE;;;;OAIG;WACU,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAa3D;;;;OAIG;WACU,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrD;;;;OAIG;WACU,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ5D;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAQzC;;OAEG;IACH,MAAM,CAAC,UAAU,IAAI,IAAI;IAKzB;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU;IAShD;;;;;;OAMG;IACH,MAAM,CAAC,gBAAgB,CAAC,CAAC,SAAS,OAAO,EACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EACpB,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,GAC3B,iBAAiB;IAUpB;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CACnB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,GACvE,iBAAiB;CASrB;AAiJD,eAAe,iBAAiB,CAAC"}
|