cloudx-react-native 2.0.0-beta.1

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.
Files changed (171) hide show
  1. package/LICENSE +57 -0
  2. package/README.md +1258 -0
  3. package/android/build.gradle +78 -0
  4. package/android/gradle.properties +7 -0
  5. package/android/src/main/AndroidManifest.xml +7 -0
  6. package/android/src/main/java/com/cloudxreactnative/CloudXAdViewEvent.kt +15 -0
  7. package/android/src/main/java/com/cloudxreactnative/CloudXBannerViewManagerImpl.kt +472 -0
  8. package/android/src/main/java/com/cloudxreactnative/CloudXReactNativeModuleImpl.kt +861 -0
  9. package/android/src/newarch/com/cloudxreactnative/CloudXBannerViewManager.kt +90 -0
  10. package/android/src/newarch/com/cloudxreactnative/CloudXReactNativeModule.kt +73 -0
  11. package/android/src/newarch/com/cloudxreactnative/CloudXReactNativePackage.kt +37 -0
  12. package/android/src/oldarch/com/cloudxreactnative/CloudXBannerViewManager.kt +76 -0
  13. package/android/src/oldarch/com/cloudxreactnative/CloudXReactNativeModule.kt +73 -0
  14. package/android/src/oldarch/com/cloudxreactnative/CloudXReactNativePackage.kt +16 -0
  15. package/cloudx-react-native.podspec +46 -0
  16. package/ios/AppTrackingTransparency.h +13 -0
  17. package/ios/AppTrackingTransparency.mm +59 -0
  18. package/ios/RNCloudXBannerView.h +51 -0
  19. package/ios/RNCloudXBannerView.mm +633 -0
  20. package/ios/RNCloudXBannerViewManager.h +11 -0
  21. package/ios/RNCloudXBannerViewManager.mm +60 -0
  22. package/ios/RNCloudXModule.h +30 -0
  23. package/ios/RNCloudXModule.mm +1088 -0
  24. package/lib/commonjs/AdView.js +151 -0
  25. package/lib/commonjs/AdView.js.map +1 -0
  26. package/lib/commonjs/AppTrackingTransparency.js +62 -0
  27. package/lib/commonjs/AppTrackingTransparency.js.map +1 -0
  28. package/lib/commonjs/BannerAd.js +117 -0
  29. package/lib/commonjs/BannerAd.js.map +1 -0
  30. package/lib/commonjs/CloudX.js +49 -0
  31. package/lib/commonjs/CloudX.js.map +1 -0
  32. package/lib/commonjs/ErrorCode.js +116 -0
  33. package/lib/commonjs/ErrorCode.js.map +1 -0
  34. package/lib/commonjs/EventEmitter.js +44 -0
  35. package/lib/commonjs/EventEmitter.js.map +1 -0
  36. package/lib/commonjs/InterstitialAd.js +94 -0
  37. package/lib/commonjs/InterstitialAd.js.map +1 -0
  38. package/lib/commonjs/MRecAd.js +117 -0
  39. package/lib/commonjs/MRecAd.js.map +1 -0
  40. package/lib/commonjs/RewardedAd.js +103 -0
  41. package/lib/commonjs/RewardedAd.js.map +1 -0
  42. package/lib/commonjs/hooks.js +239 -0
  43. package/lib/commonjs/hooks.js.map +1 -0
  44. package/lib/commonjs/index.js +144 -0
  45. package/lib/commonjs/index.js.map +1 -0
  46. package/lib/commonjs/specs/CloudXAdViewNativeComponent.js +26 -0
  47. package/lib/commonjs/specs/CloudXAdViewNativeComponent.js.map +1 -0
  48. package/lib/commonjs/specs/NativeCloudXModule.js +18 -0
  49. package/lib/commonjs/specs/NativeCloudXModule.js.map +1 -0
  50. package/lib/commonjs/types/AdEvent.js +6 -0
  51. package/lib/commonjs/types/AdEvent.js.map +1 -0
  52. package/lib/commonjs/types/AdInfo.js +6 -0
  53. package/lib/commonjs/types/AdInfo.js.map +1 -0
  54. package/lib/commonjs/types/BannerAd.js +6 -0
  55. package/lib/commonjs/types/BannerAd.js.map +1 -0
  56. package/lib/commonjs/types/CloudX.js +6 -0
  57. package/lib/commonjs/types/CloudX.js.map +1 -0
  58. package/lib/commonjs/types/Configuration.js +2 -0
  59. package/lib/commonjs/types/Configuration.js.map +1 -0
  60. package/lib/commonjs/types/FullscreenAd.js +6 -0
  61. package/lib/commonjs/types/FullscreenAd.js.map +1 -0
  62. package/lib/commonjs/types/RewardedAd.js +6 -0
  63. package/lib/commonjs/types/RewardedAd.js.map +1 -0
  64. package/lib/commonjs/types/index.js +2 -0
  65. package/lib/commonjs/types/index.js.map +1 -0
  66. package/lib/module/AdView.js +144 -0
  67. package/lib/module/AdView.js.map +1 -0
  68. package/lib/module/AppTrackingTransparency.js +55 -0
  69. package/lib/module/AppTrackingTransparency.js.map +1 -0
  70. package/lib/module/BannerAd.js +110 -0
  71. package/lib/module/BannerAd.js.map +1 -0
  72. package/lib/module/CloudX.js +42 -0
  73. package/lib/module/CloudX.js.map +1 -0
  74. package/lib/module/ErrorCode.js +110 -0
  75. package/lib/module/ErrorCode.js.map +1 -0
  76. package/lib/module/EventEmitter.js +35 -0
  77. package/lib/module/EventEmitter.js.map +1 -0
  78. package/lib/module/InterstitialAd.js +87 -0
  79. package/lib/module/InterstitialAd.js.map +1 -0
  80. package/lib/module/MRecAd.js +110 -0
  81. package/lib/module/MRecAd.js.map +1 -0
  82. package/lib/module/RewardedAd.js +96 -0
  83. package/lib/module/RewardedAd.js.map +1 -0
  84. package/lib/module/hooks.js +230 -0
  85. package/lib/module/hooks.js.map +1 -0
  86. package/lib/module/index.js +33 -0
  87. package/lib/module/index.js.map +1 -0
  88. package/lib/module/specs/CloudXAdViewNativeComponent.js +20 -0
  89. package/lib/module/specs/CloudXAdViewNativeComponent.js.map +1 -0
  90. package/lib/module/specs/NativeCloudXModule.js +14 -0
  91. package/lib/module/specs/NativeCloudXModule.js.map +1 -0
  92. package/lib/module/types/AdEvent.js +2 -0
  93. package/lib/module/types/AdEvent.js.map +1 -0
  94. package/lib/module/types/AdInfo.js +2 -0
  95. package/lib/module/types/AdInfo.js.map +1 -0
  96. package/lib/module/types/BannerAd.js +2 -0
  97. package/lib/module/types/BannerAd.js.map +1 -0
  98. package/lib/module/types/CloudX.js +2 -0
  99. package/lib/module/types/CloudX.js.map +1 -0
  100. package/lib/module/types/Configuration.js +2 -0
  101. package/lib/module/types/Configuration.js.map +1 -0
  102. package/lib/module/types/FullscreenAd.js +2 -0
  103. package/lib/module/types/FullscreenAd.js.map +1 -0
  104. package/lib/module/types/RewardedAd.js +2 -0
  105. package/lib/module/types/RewardedAd.js.map +1 -0
  106. package/lib/module/types/index.js +2 -0
  107. package/lib/module/types/index.js.map +1 -0
  108. package/lib/typescript/src/AdView.d.ts +69 -0
  109. package/lib/typescript/src/AdView.d.ts.map +1 -0
  110. package/lib/typescript/src/AppTrackingTransparency.d.ts +28 -0
  111. package/lib/typescript/src/AppTrackingTransparency.d.ts.map +1 -0
  112. package/lib/typescript/src/BannerAd.d.ts +4 -0
  113. package/lib/typescript/src/BannerAd.d.ts.map +1 -0
  114. package/lib/typescript/src/CloudX.d.ts +4 -0
  115. package/lib/typescript/src/CloudX.d.ts.map +1 -0
  116. package/lib/typescript/src/ErrorCode.d.ts +102 -0
  117. package/lib/typescript/src/ErrorCode.d.ts.map +1 -0
  118. package/lib/typescript/src/EventEmitter.d.ts +16 -0
  119. package/lib/typescript/src/EventEmitter.d.ts.map +1 -0
  120. package/lib/typescript/src/InterstitialAd.d.ts +4 -0
  121. package/lib/typescript/src/InterstitialAd.d.ts.map +1 -0
  122. package/lib/typescript/src/MRecAd.d.ts +4 -0
  123. package/lib/typescript/src/MRecAd.d.ts.map +1 -0
  124. package/lib/typescript/src/RewardedAd.d.ts +4 -0
  125. package/lib/typescript/src/RewardedAd.d.ts.map +1 -0
  126. package/lib/typescript/src/hooks.d.ts +50 -0
  127. package/lib/typescript/src/hooks.d.ts.map +1 -0
  128. package/lib/typescript/src/index.d.ts +23 -0
  129. package/lib/typescript/src/index.d.ts.map +1 -0
  130. package/lib/typescript/src/specs/CloudXAdViewNativeComponent.d.ts +61 -0
  131. package/lib/typescript/src/specs/CloudXAdViewNativeComponent.d.ts.map +1 -0
  132. package/lib/typescript/src/specs/NativeCloudXModule.d.ts +106 -0
  133. package/lib/typescript/src/specs/NativeCloudXModule.d.ts.map +1 -0
  134. package/lib/typescript/src/types/AdEvent.d.ts +10 -0
  135. package/lib/typescript/src/types/AdEvent.d.ts.map +1 -0
  136. package/lib/typescript/src/types/AdInfo.d.ts +48 -0
  137. package/lib/typescript/src/types/AdInfo.d.ts.map +1 -0
  138. package/lib/typescript/src/types/BannerAd.d.ts +39 -0
  139. package/lib/typescript/src/types/BannerAd.d.ts.map +1 -0
  140. package/lib/typescript/src/types/CloudX.d.ts +25 -0
  141. package/lib/typescript/src/types/CloudX.d.ts.map +1 -0
  142. package/lib/typescript/src/types/Configuration.d.ts +10 -0
  143. package/lib/typescript/src/types/Configuration.d.ts.map +1 -0
  144. package/lib/typescript/src/types/FullscreenAd.d.ts +29 -0
  145. package/lib/typescript/src/types/FullscreenAd.d.ts.map +1 -0
  146. package/lib/typescript/src/types/RewardedAd.d.ts +10 -0
  147. package/lib/typescript/src/types/RewardedAd.d.ts.map +1 -0
  148. package/lib/typescript/src/types/index.d.ts +8 -0
  149. package/lib/typescript/src/types/index.d.ts.map +1 -0
  150. package/package.json +78 -0
  151. package/src/AdView.tsx +213 -0
  152. package/src/AppTrackingTransparency.ts +56 -0
  153. package/src/BannerAd.ts +133 -0
  154. package/src/CloudX.ts +55 -0
  155. package/src/ErrorCode.ts +157 -0
  156. package/src/EventEmitter.ts +38 -0
  157. package/src/InterstitialAd.ts +103 -0
  158. package/src/MRecAd.ts +133 -0
  159. package/src/RewardedAd.ts +113 -0
  160. package/src/hooks.ts +292 -0
  161. package/src/index.ts +50 -0
  162. package/src/specs/CloudXAdViewNativeComponent.ts +82 -0
  163. package/src/specs/NativeCloudXModule.ts +162 -0
  164. package/src/types/AdEvent.ts +11 -0
  165. package/src/types/AdInfo.ts +60 -0
  166. package/src/types/BannerAd.ts +59 -0
  167. package/src/types/CloudX.ts +33 -0
  168. package/src/types/Configuration.ts +10 -0
  169. package/src/types/FullscreenAd.ts +39 -0
  170. package/src/types/RewardedAd.ts +10 -0
  171. package/src/types/index.ts +7 -0
package/src/AdView.tsx ADDED
@@ -0,0 +1,213 @@
1
+ import React, { useRef, useState, useEffect, useCallback, useImperativeHandle, forwardRef } from 'react';
2
+ import type { NativeSyntheticEvent, ViewProps } from 'react-native';
3
+ import { View } from 'react-native';
4
+ import NativeAdView, { Commands } from './specs/CloudXAdViewNativeComponent';
5
+ import type { AdInfoEvent, AdErrorEvent } from './specs/CloudXAdViewNativeComponent';
6
+ import NativeCloudXModule from './specs/NativeCloudXModule';
7
+ import type { AdInfo, AdLoadFailedInfo } from './types/AdInfo';
8
+
9
+ /**
10
+ * Ad format for the AdView component.
11
+ */
12
+ export enum AdFormat {
13
+ BANNER = 'BANNER',
14
+ MREC = 'MREC',
15
+ }
16
+
17
+ /**
18
+ * Position constants for programmatic ad placement.
19
+ */
20
+ export enum AdViewPosition {
21
+ TOP_LEFT = 'top_left',
22
+ TOP_CENTER = 'top_center',
23
+ TOP_RIGHT = 'top_right',
24
+ CENTER_LEFT = 'center_left',
25
+ CENTERED = 'centered',
26
+ CENTER_RIGHT = 'center_right',
27
+ BOTTOM_LEFT = 'bottom_left',
28
+ BOTTOM_CENTER = 'bottom_center',
29
+ BOTTOM_RIGHT = 'bottom_right',
30
+ }
31
+
32
+ type SizeRecord = { width: number; height: number };
33
+
34
+ const ADVIEW_SIZE = {
35
+ banner: { width: 320, height: 50 },
36
+ leader: { width: 728, height: 90 },
37
+ mrec: { width: 300, height: 250 },
38
+ };
39
+
40
+ /**
41
+ * Props for the AdView component.
42
+ */
43
+ export type AdViewProps = {
44
+ /** The ad unit ID. */
45
+ adUnitId: string;
46
+
47
+ /** The ad format: BANNER or MREC. */
48
+ adFormat: AdFormat;
49
+
50
+ /** Placement name for reporting. */
51
+ placement?: string | null;
52
+
53
+ /** Custom data string. */
54
+ customData?: string | null;
55
+
56
+ /** Whether to automatically refresh. Defaults to true. */
57
+ autoRefresh?: boolean;
58
+
59
+ /** Whether to load the ad on mount. Defaults to true. */
60
+ loadOnMount?: boolean;
61
+
62
+ /** Position for programmatic window-level placement. When set, the banner
63
+ * is removed from React layout and added to the app window at the given position. */
64
+ adPosition?: AdViewPosition | null;
65
+
66
+ /** Callbacks */
67
+ onAdLoaded?: (adInfo: AdInfo) => void;
68
+ onAdLoadFailed?: (errorInfo: AdLoadFailedInfo) => void;
69
+ onAdClicked?: (adInfo: AdInfo) => void;
70
+ onAdExpanded?: (adInfo: AdInfo) => void;
71
+ onAdCollapsed?: (adInfo: AdInfo) => void;
72
+ onAdRevenuePaid?: (adInfo: AdInfo) => void;
73
+ };
74
+
75
+ /**
76
+ * Imperative handle exposed via ref for AdView control.
77
+ */
78
+ export type AdViewHandler = {
79
+ loadAd: () => void;
80
+ destroy: () => void;
81
+ };
82
+
83
+ const handleAdViewEvent = <T extends AdInfoEvent | AdErrorEvent>(
84
+ event: NativeSyntheticEvent<T>,
85
+ callback?: (data: T) => void,
86
+ ) => {
87
+ if (callback) callback(event.nativeEvent);
88
+ };
89
+
90
+ /**
91
+ * React component for displaying CloudX banner or MREC ads.
92
+ *
93
+ * - **Banners**: 320×50 on phones, 728×90 on tablets.
94
+ * - **MRECs**: Fixed 300×250 on all devices.
95
+ *
96
+ * Supports both programmatic control via ref and declarative props.
97
+ */
98
+ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(function AdView(
99
+ {
100
+ adUnitId,
101
+ adFormat,
102
+ placement,
103
+ customData,
104
+ autoRefresh = true,
105
+ loadOnMount = true,
106
+ adPosition,
107
+ onAdLoaded,
108
+ onAdLoadFailed,
109
+ onAdClicked,
110
+ onAdExpanded,
111
+ onAdCollapsed,
112
+ onAdRevenuePaid,
113
+ style,
114
+ ...otherProps
115
+ },
116
+ ref,
117
+ ) {
118
+ const nativeRef = useRef<React.ElementRef<typeof NativeAdView>>(null);
119
+ const [adFormatSize, setAdFormatSize] = useState<SizeRecord>(
120
+ adFormat === AdFormat.MREC ? ADVIEW_SIZE.mrec : ADVIEW_SIZE.banner,
121
+ );
122
+ const [isReady, setIsReady] = useState(false);
123
+
124
+ const loadAd = useCallback(() => {
125
+ nativeRef.current && Commands.loadAd(nativeRef.current);
126
+ }, []);
127
+
128
+ const destroy = useCallback(() => {
129
+ nativeRef.current && Commands.destroy(nativeRef.current);
130
+ }, []);
131
+
132
+ useImperativeHandle(ref, () => ({ loadAd, destroy }), [loadAd, destroy]);
133
+
134
+ useEffect(() => {
135
+ (async () => {
136
+ try {
137
+ const isTablet = adFormat === AdFormat.BANNER ? await NativeCloudXModule.isTablet() : false;
138
+ setAdFormatSize(
139
+ adFormat === AdFormat.MREC
140
+ ? ADVIEW_SIZE.mrec
141
+ : isTablet
142
+ ? ADVIEW_SIZE.leader
143
+ : ADVIEW_SIZE.banner,
144
+ );
145
+ } catch {
146
+ console.warn('AdView: isTablet() check failed, defaulting to phone size.');
147
+ }
148
+
149
+ try {
150
+ const initialized = await NativeCloudXModule.isInitialized();
151
+ if (!initialized) {
152
+ console.warn('AdView was mounted before the CloudX SDK was initialized.');
153
+ }
154
+ } catch {
155
+ console.warn('AdView: isInitialized() check failed.');
156
+ }
157
+
158
+ setIsReady(true);
159
+ })();
160
+ }, [adFormat]);
161
+
162
+ const onAdLoadedHandler = useCallback(
163
+ (event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdLoaded),
164
+ [onAdLoaded],
165
+ );
166
+ const onAdLoadFailedHandler = useCallback(
167
+ (event: NativeSyntheticEvent<AdErrorEvent>) => handleAdViewEvent(event, onAdLoadFailed),
168
+ [onAdLoadFailed],
169
+ );
170
+ const onAdClickedHandler = useCallback(
171
+ (event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdClicked),
172
+ [onAdClicked],
173
+ );
174
+ const onAdExpandedHandler = useCallback(
175
+ (event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdExpanded),
176
+ [onAdExpanded],
177
+ );
178
+ const onAdCollapsedHandler = useCallback(
179
+ (event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdCollapsed),
180
+ [onAdCollapsed],
181
+ );
182
+ const onAdRevenuePaidHandler = useCallback(
183
+ (event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdRevenuePaid),
184
+ [onAdRevenuePaid],
185
+ );
186
+
187
+ if (!isReady) {
188
+ return <View style={style} {...otherProps} />;
189
+ }
190
+
191
+ return (
192
+ <NativeAdView
193
+ ref={nativeRef}
194
+ adUnitId={adUnitId}
195
+ adFormat={adFormat}
196
+ placement={placement}
197
+ customData={customData}
198
+ autoRefresh={autoRefresh}
199
+ loadOnMount={loadOnMount}
200
+ adPosition={adPosition}
201
+ style={[adFormatSize, style]}
202
+ onAdLoaded={onAdLoadedHandler}
203
+ onAdLoadFailed={onAdLoadFailedHandler}
204
+ onAdClicked={onAdClickedHandler}
205
+ onAdExpanded={onAdExpandedHandler}
206
+ onAdCollapsed={onAdCollapsedHandler}
207
+ onAdRevenuePaid={onAdRevenuePaidHandler}
208
+ {...otherProps}
209
+ />
210
+ );
211
+ });
212
+
213
+ export default AdView;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * App Tracking Transparency (ATT) module for iOS 14+.
3
+ *
4
+ * Provides methods to request and check tracking authorization status.
5
+ * On Android or iOS < 14, these methods return safe defaults.
6
+ */
7
+
8
+ import { NativeModules, Platform } from 'react-native';
9
+
10
+ const ATTModule = NativeModules.AppTrackingTransparency;
11
+
12
+ /**
13
+ * ATT authorization status values.
14
+ */
15
+ export enum ATTStatus {
16
+ AUTHORIZED = 'authorized',
17
+ DENIED = 'denied',
18
+ RESTRICTED = 'restricted',
19
+ NOT_DETERMINED = 'not_determined',
20
+ NOT_REQUIRED = 'not_required',
21
+ }
22
+
23
+ /**
24
+ * Requests App Tracking Transparency permission (iOS 14+).
25
+ *
26
+ * On iOS 14+, this shows the system ATT permission dialog.
27
+ * On iOS < 14 or Android, returns ATTStatus.NOT_REQUIRED.
28
+ */
29
+ export async function requestTrackingAuthorization(): Promise<ATTStatus> {
30
+ if (Platform.OS !== 'ios' || !ATTModule) {
31
+ return ATTStatus.NOT_REQUIRED;
32
+ }
33
+
34
+ try {
35
+ const status: string = await ATTModule.requestTrackingAuthorization();
36
+ return status as ATTStatus;
37
+ } catch (_error) {
38
+ return ATTStatus.NOT_DETERMINED;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Gets the current tracking authorization status without showing a dialog.
44
+ */
45
+ export async function getTrackingAuthorizationStatus(): Promise<ATTStatus> {
46
+ if (Platform.OS !== 'ios' || !ATTModule) {
47
+ return ATTStatus.NOT_REQUIRED;
48
+ }
49
+
50
+ try {
51
+ const status: string = await ATTModule.getTrackingAuthorizationStatus();
52
+ return status as ATTStatus;
53
+ } catch (_error) {
54
+ return ATTStatus.NOT_DETERMINED;
55
+ }
56
+ }
@@ -0,0 +1,133 @@
1
+ import { addEventListener, removeEventListener } from './EventEmitter';
2
+ import type { AdInfo, AdLoadFailedInfo } from './types/AdInfo';
3
+ import type { BannerAdType, AdViewPositionType } from './types/BannerAd';
4
+ import NativeCloudXModule from './specs/NativeCloudXModule';
5
+
6
+ const {
7
+ ON_BANNER_AD_LOADED_EVENT,
8
+ ON_BANNER_AD_LOAD_FAILED_EVENT,
9
+ ON_BANNER_AD_CLICKED_EVENT,
10
+ ON_BANNER_AD_EXPANDED_EVENT,
11
+ ON_BANNER_AD_COLLAPSED_EVENT,
12
+ ON_BANNER_AD_REVENUE_PAID,
13
+ } = NativeCloudXModule.getConstants();
14
+
15
+ const createAd = (adUnitId: string, position: AdViewPositionType): void => {
16
+ NativeCloudXModule.createBanner(adUnitId, position);
17
+ };
18
+
19
+ const createAdWithOffsets = (adUnitId: string, position: AdViewPositionType, xOffset: number, yOffset: number): void => {
20
+ NativeCloudXModule.createBannerWithOffsets(adUnitId, position, xOffset, yOffset);
21
+ };
22
+
23
+ const destroyAd = (adUnitId: string): void => {
24
+ NativeCloudXModule.destroyBanner(adUnitId);
25
+ };
26
+
27
+ const showAd = (adUnitId: string): void => {
28
+ NativeCloudXModule.showBanner(adUnitId);
29
+ };
30
+
31
+ const hideAd = (adUnitId: string): void => {
32
+ NativeCloudXModule.hideBanner(adUnitId);
33
+ };
34
+
35
+ const setPlacement = (adUnitId: string, placement: string | null): void => {
36
+ NativeCloudXModule.setBannerPlacement(adUnitId, placement);
37
+ };
38
+
39
+ const setCustomData = (adUnitId: string, customData: string | null): void => {
40
+ NativeCloudXModule.setBannerCustomData(adUnitId, customData);
41
+ };
42
+
43
+ const startAutoRefresh = (adUnitId: string): void => {
44
+ NativeCloudXModule.startBannerAutoRefresh(adUnitId);
45
+ };
46
+
47
+ const stopAutoRefresh = (adUnitId: string): void => {
48
+ NativeCloudXModule.stopBannerAutoRefresh(adUnitId);
49
+ };
50
+
51
+ const updatePosition = (adUnitId: string, position: AdViewPositionType): void => {
52
+ NativeCloudXModule.updateBannerPosition(adUnitId, position);
53
+ };
54
+
55
+ const updateOffsets = (adUnitId: string, xOffset: number, yOffset: number): void => {
56
+ NativeCloudXModule.updateBannerOffsets(adUnitId, xOffset, yOffset);
57
+ };
58
+
59
+ const setBackgroundColor = (adUnitId: string, hexColorString: string): void => {
60
+ NativeCloudXModule.setBannerBackgroundColor(adUnitId, hexColorString);
61
+ };
62
+
63
+ const addAdLoadedEventListener = (listener: (adInfo: AdInfo) => void): void => {
64
+ addEventListener(ON_BANNER_AD_LOADED_EVENT, listener);
65
+ };
66
+ const removeAdLoadedEventListener = (): void => {
67
+ removeEventListener(ON_BANNER_AD_LOADED_EVENT);
68
+ };
69
+
70
+ const addAdLoadFailedEventListener = (listener: (errorInfo: AdLoadFailedInfo) => void): void => {
71
+ addEventListener(ON_BANNER_AD_LOAD_FAILED_EVENT, listener);
72
+ };
73
+ const removeAdLoadFailedEventListener = (): void => {
74
+ removeEventListener(ON_BANNER_AD_LOAD_FAILED_EVENT);
75
+ };
76
+
77
+ const addAdClickedEventListener = (listener: (adInfo: AdInfo) => void): void => {
78
+ addEventListener(ON_BANNER_AD_CLICKED_EVENT, listener);
79
+ };
80
+ const removeAdClickedEventListener = (): void => {
81
+ removeEventListener(ON_BANNER_AD_CLICKED_EVENT);
82
+ };
83
+
84
+ const addAdExpandedEventListener = (listener: (adInfo: AdInfo) => void): void => {
85
+ addEventListener(ON_BANNER_AD_EXPANDED_EVENT, listener);
86
+ };
87
+ const removeAdExpandedEventListener = (): void => {
88
+ removeEventListener(ON_BANNER_AD_EXPANDED_EVENT);
89
+ };
90
+
91
+ const addAdCollapsedEventListener = (listener: (adInfo: AdInfo) => void): void => {
92
+ addEventListener(ON_BANNER_AD_COLLAPSED_EVENT, listener);
93
+ };
94
+ const removeAdCollapsedEventListener = (): void => {
95
+ removeEventListener(ON_BANNER_AD_COLLAPSED_EVENT);
96
+ };
97
+
98
+ const addAdRevenuePaidListener = (listener: (adInfo: AdInfo) => void): void => {
99
+ addEventListener(ON_BANNER_AD_REVENUE_PAID, listener);
100
+ };
101
+ const removeAdRevenuePaidListener = (): void => {
102
+ removeEventListener(ON_BANNER_AD_REVENUE_PAID);
103
+ };
104
+
105
+ export const BannerAd: BannerAdType = {
106
+ createAd,
107
+ createAdWithOffsets,
108
+ destroyAd,
109
+ showAd,
110
+ hideAd,
111
+ updatePosition,
112
+ updateOffsets,
113
+ setBackgroundColor,
114
+ setPlacement,
115
+ setCustomData,
116
+ startAutoRefresh,
117
+ stopAutoRefresh,
118
+
119
+ addAdLoadedEventListener,
120
+ removeAdLoadedEventListener,
121
+ addAdLoadFailedEventListener,
122
+ removeAdLoadFailedEventListener,
123
+ addAdClickedEventListener,
124
+ removeAdClickedEventListener,
125
+ addAdExpandedEventListener,
126
+ removeAdExpandedEventListener,
127
+ addAdCollapsedEventListener,
128
+ removeAdCollapsedEventListener,
129
+ addAdRevenuePaidListener,
130
+ removeAdRevenuePaidListener,
131
+ };
132
+
133
+ export default BannerAd;
package/src/CloudX.ts ADDED
@@ -0,0 +1,55 @@
1
+ import type { CloudXType } from './types/CloudX';
2
+ import type { Configuration } from './types/Configuration';
3
+ import NativeCloudXModule from './specs/NativeCloudXModule';
4
+
5
+ const VERSION = '2.0.0';
6
+
7
+ const initialize = (appKey: string): Promise<Configuration> => {
8
+ return NativeCloudXModule.initialize(VERSION, appKey) as Promise<Configuration>;
9
+ };
10
+
11
+ const isInitialized = (): Promise<boolean> => {
12
+ return NativeCloudXModule.isInitialized();
13
+ };
14
+
15
+ const getVersion = (): Promise<string> => {
16
+ return NativeCloudXModule.getVersion();
17
+ };
18
+
19
+ const setMinLogLevel = (level: string): void => {
20
+ NativeCloudXModule.setMinLogLevel(level);
21
+ };
22
+
23
+ const setHashedUserID = (hashedUserID: string): void => {
24
+ NativeCloudXModule.setHashedUserID(hashedUserID);
25
+ };
26
+
27
+ const setUserKeyValue = (key: string, value: string): void => {
28
+ NativeCloudXModule.setUserKeyValue(key, value);
29
+ };
30
+
31
+ const setAppKeyValue = (key: string, value: string): void => {
32
+ NativeCloudXModule.setAppKeyValue(key, value);
33
+ };
34
+
35
+ const clearAllKeyValues = (): void => {
36
+ NativeCloudXModule.clearAllKeyValues();
37
+ };
38
+
39
+ const setVisualDebuggingEnabled = (enabled: boolean): void => {
40
+ NativeCloudXModule.setVisualDebuggingEnabled(enabled);
41
+ };
42
+
43
+ export const CloudX: CloudXType = {
44
+ initialize,
45
+ isInitialized,
46
+ getVersion,
47
+ setMinLogLevel,
48
+ setHashedUserID,
49
+ setUserKeyValue,
50
+ setAppKeyValue,
51
+ clearAllKeyValues,
52
+ setVisualDebuggingEnabled,
53
+ };
54
+
55
+ export default CloudX;
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Error codes for CloudX SDK — values match the native CLXErrorCode (iOS)
3
+ * and CloudXErrorCode (Android) enumerations exactly.
4
+ *
5
+ * Code ranges:
6
+ * 0-99 General errors
7
+ * 100-199 Network and connectivity errors
8
+ * 200-299 SDK initialization errors
9
+ * 300-399 Ad request / loading errors
10
+ * 400-499 Ad display / presentation errors
11
+ * 500-599 Configuration / setup errors
12
+ * 600-699 Adapter-level errors
13
+ */
14
+ export enum ErrorCode {
15
+ // GENERAL (0-99)
16
+
17
+ /** An internal error occurred. */
18
+ INTERNAL_ERROR = 0,
19
+
20
+ // NETWORK (100-199)
21
+
22
+ /** General network error. */
23
+ NETWORK_ERROR = 100,
24
+
25
+ /** Network request timed out. */
26
+ NETWORK_TIMEOUT = 101,
27
+
28
+ /** Server error (5xx). */
29
+ SERVER_ERROR = 102,
30
+
31
+ /** Client error (4xx). */
32
+ CLIENT_ERROR = 103,
33
+
34
+ /** Rate limited (429). */
35
+ TOO_MANY_REQUESTS = 104,
36
+
37
+ /** Invalid or unparseable server response. */
38
+ INVALID_RESPONSE = 105,
39
+
40
+ /** No network connectivity. */
41
+ NO_CONNECTION = 106,
42
+
43
+ // INITIALIZATION (200-299)
44
+
45
+ /** SDK is not initialized. Call CloudX.initialize() first. */
46
+ NOT_INITIALIZED = 200,
47
+
48
+ /** No ad adapters/networks found. */
49
+ NO_ADAPTERS_FOUND = 201,
50
+
51
+ /** No ad networks configured for this app. */
52
+ NO_NETWORKS_CONFIGURED = 202,
53
+
54
+ /** Invalid app key provided. */
55
+ INVALID_APP_KEY = 203,
56
+
57
+ /** SDK disabled by server configuration. */
58
+ SDK_DISABLED = 204,
59
+
60
+ // AD REQUEST / LOADING (300-399)
61
+
62
+ /** Invalid ad unit ID. */
63
+ INVALID_AD_UNIT = 300,
64
+
65
+ /** Ads disabled for this ad unit. */
66
+ ADS_DISABLED = 301,
67
+
68
+ /** No ad available (no fill). */
69
+ NO_FILL = 302,
70
+
71
+ /** Ad failed to load. */
72
+ LOAD_FAILED = 304,
73
+
74
+ // AD DISPLAY / SHOW (400-499)
75
+
76
+ /** Ad is not ready to be shown. */
77
+ AD_NOT_READY = 400,
78
+
79
+ /** Another fullscreen ad is already showing. */
80
+ AD_ALREADY_SHOWING = 401,
81
+
82
+ /** Android "Don't keep activities" setting is enabled (Android only). */
83
+ DONT_KEEP_ACTIVITIES_ENABLED = 402,
84
+
85
+ // CONFIGURATION (500-599)
86
+
87
+ /** Native view is nil or invalid. */
88
+ INVALID_NATIVE_VIEW = 500,
89
+
90
+ // ADAPTER (600-699)
91
+
92
+ /** Internal error in an ad network adapter. */
93
+ ADAPTER_INTERNAL_ERROR = 600,
94
+
95
+ /** Adapter returned no fill. */
96
+ ADAPTER_NO_FILL = 601,
97
+
98
+ /** Adapter reported an invalid load state. */
99
+ ADAPTER_INVALID_LOAD_STATE = 602,
100
+
101
+ /** Adapter has an invalid configuration. */
102
+ ADAPTER_INVALID_CONFIGURATION = 603,
103
+
104
+ /** Adapter received invalid server extras. */
105
+ ADAPTER_INVALID_SERVER_EXTRAS = 604,
106
+
107
+ /** Adapter rejected the ad request. */
108
+ ADAPTER_BAD_REQUEST = 605,
109
+
110
+ /** Adapter is not initialized. */
111
+ ADAPTER_NOT_INITIALIZED = 606,
112
+
113
+ /** Adapter failed to initialize. */
114
+ ADAPTER_INITIALIZATION_ERROR = 607,
115
+
116
+ /** Adapter ad is not ready. */
117
+ ADAPTER_AD_NOT_READY = 608,
118
+
119
+ /** Adapter load timed out. */
120
+ ADAPTER_LOAD_TIMEOUT = 609,
121
+
122
+ /** Adapter operation timed out. */
123
+ ADAPTER_TIMEOUT = 610,
124
+
125
+ /** Adapter has no network connection. */
126
+ ADAPTER_NO_CONNECTION = 611,
127
+
128
+ /** Adapter server error. */
129
+ ADAPTER_SERVER_ERROR = 612,
130
+
131
+ /** Adapter bid token request timed out. */
132
+ ADAPTER_BID_TOKEN_TIMEOUT = 613,
133
+
134
+ /** Adapter does not support bid tokens. */
135
+ ADAPTER_BID_TOKEN_NOT_SUPPORTED = 614,
136
+
137
+ /** Adapter encountered a WebView error. */
138
+ ADAPTER_WEBVIEW_ERROR = 615,
139
+
140
+ /** Adapter ad has expired. */
141
+ ADAPTER_AD_EXPIRED = 616,
142
+
143
+ /** Adapter ad is frequency capped. */
144
+ ADAPTER_AD_FREQUENCY_CAPPED = 617,
145
+
146
+ /** Adapter reward error. */
147
+ ADAPTER_REWARD_ERROR = 618,
148
+
149
+ /** Adapter is missing native ad assets. */
150
+ ADAPTER_MISSING_NATIVE_AD_ASSETS = 619,
151
+
152
+ /** Adapter is missing the required activity (Android) or view controller (iOS). */
153
+ ADAPTER_MISSING_VIEW_CONTROLLER = 620,
154
+
155
+ /** Adapter failed to display the ad. */
156
+ ADAPTER_DISPLAY_FAILED = 621,
157
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Manages CloudX ad event listeners using a shared NativeEventEmitter.
3
+ * Ensures only one active subscription per event type at any given time,
4
+ * following the singleton listener pattern.
5
+ */
6
+
7
+ import { NativeEventEmitter } from 'react-native';
8
+ import type { EventSubscription } from 'react-native';
9
+ import type { AdEventObject, AdEventListener } from './types/AdEvent';
10
+ import NativeCloudXModule from './specs/NativeCloudXModule';
11
+
12
+ const emitter = new NativeEventEmitter(NativeCloudXModule);
13
+
14
+ const subscriptions: Record<string, EventSubscription> = {};
15
+
16
+ /**
17
+ * Subscribes to a specific ad event.
18
+ * If a listener already exists for the event, it will be replaced.
19
+ */
20
+ export const addEventListener = <T extends AdEventObject>(event: string, handler: AdEventListener<T>): void => {
21
+ const subscription = emitter.addListener(event, handler);
22
+ const currentSubscription = subscriptions[event];
23
+ if (currentSubscription) {
24
+ currentSubscription.remove();
25
+ }
26
+ subscriptions[event] = subscription;
27
+ };
28
+
29
+ /**
30
+ * Unsubscribes from a specific ad event, if a listener exists.
31
+ */
32
+ export const removeEventListener = (event: string): void => {
33
+ const currentSubscription = subscriptions[event];
34
+ if (currentSubscription) {
35
+ currentSubscription.remove();
36
+ delete subscriptions[event];
37
+ }
38
+ };