react-native-daro 1.0.12 → 1.0.15

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 (222) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +30 -30
  3. package/android/build.gradle +42 -59
  4. package/android/src/admob/java/com/daro/reactnative/DaroSdkBridge.kt +23 -0
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/java/com/{darom → daro/reactnative}/DaroMAdBannerViewManager.kt +4 -4
  7. package/android/src/main/java/com/{darom → daro/reactnative}/DaroMAdNativeViewManager.kt +4 -4
  8. package/android/src/main/java/com/{darom → daro/reactnative}/DaroMModule.kt +44 -45
  9. package/android/src/main/java/com/{darom → daro/reactnative}/DaroMPackage.kt +1 -1
  10. package/android/src/main/java/com/{darom → daro/reactnative}/constants/InternalDaroMBannerSize.kt +1 -1
  11. package/android/src/main/java/com/{darom → daro/reactnative}/event/DaroMEvent.kt +1 -1
  12. package/android/src/main/java/com/{darom → daro/reactnative}/impl/DaroMBannerViewModuleImpl.kt +2 -2
  13. package/android/src/main/java/com/{darom → daro/reactnative}/impl/DaroMInterstitialModuleImpl.kt +26 -26
  14. package/android/src/main/java/com/{darom → daro/reactnative}/impl/DaroMLightPopupModuleImpl.kt +30 -29
  15. package/android/src/main/java/com/{darom → daro/reactnative}/impl/DaroMRewardedAdModuleImpl.kt +33 -27
  16. package/android/src/main/java/com/{darom → daro/reactnative}/util/AdInfoUtil.kt +25 -1
  17. package/android/src/main/java/com/{darom → daro/reactnative}/util/EventEmitterUtil.kt +2 -2
  18. package/android/src/main/java/com/daro/reactnative/view/DaroMAdBannerViewContainer.kt +417 -0
  19. package/android/src/main/java/com/{darom → daro/reactnative}/view/DaroMAdNativeViewContainer.kt +4 -4
  20. package/app.plugin.js +1 -0
  21. package/ios/DaroMAdBannerViewManager.swift +5 -1
  22. package/ios/DaroMModule+AppOpen.swift +34 -31
  23. package/ios/DaroMModule+Interstitial.swift +29 -26
  24. package/ios/DaroMModule+LightPopup.swift +40 -33
  25. package/ios/DaroMModule+Rewarded.swift +35 -27
  26. package/ios/DaroMModule.mm +13 -13
  27. package/ios/DaroMModule.swift +20 -13
  28. package/ios/DaroMNativeAdViewManager.swift +1 -1
  29. package/ios/mediation/admob/DaroMediationDebugger.swift +11 -0
  30. package/ios/mediation/admob/DaroMediationTypes.swift +22 -0
  31. package/lib/commonjs/AdBannerView.js +6 -1
  32. package/lib/commonjs/AdBannerView.js.map +1 -1
  33. package/lib/commonjs/AppOpenAd.js +155 -70
  34. package/lib/commonjs/AppOpenAd.js.map +1 -1
  35. package/lib/commonjs/ErrorCode.js.map +1 -1
  36. package/lib/commonjs/EventEmitter.js +39 -11
  37. package/lib/commonjs/EventEmitter.js.map +1 -1
  38. package/lib/commonjs/InterstitialAd.js +157 -70
  39. package/lib/commonjs/InterstitialAd.js.map +1 -1
  40. package/lib/commonjs/LightPopupAd.js +181 -99
  41. package/lib/commonjs/LightPopupAd.js.map +1 -1
  42. package/lib/commonjs/RewardedAd.js +164 -80
  43. package/lib/commonjs/RewardedAd.js.map +1 -1
  44. package/lib/commonjs/index.js +1 -2
  45. package/lib/commonjs/index.js.map +1 -1
  46. package/lib/commonjs/nativeAd/NativeAdView.js +5 -1
  47. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  48. package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
  49. package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
  50. package/lib/commonjs/package.json +1 -0
  51. package/lib/commonjs/types/AdEvent.js +17 -0
  52. package/lib/commonjs/types/AdEvent.js.map +1 -1
  53. package/lib/module/AdBannerView.js +6 -1
  54. package/lib/module/AdBannerView.js.map +1 -1
  55. package/lib/module/AppOpenAd.js +155 -71
  56. package/lib/module/AppOpenAd.js.map +1 -1
  57. package/lib/module/ErrorCode.js.map +1 -1
  58. package/lib/module/EventEmitter.js +37 -10
  59. package/lib/module/EventEmitter.js.map +1 -1
  60. package/lib/module/InterstitialAd.js +158 -72
  61. package/lib/module/InterstitialAd.js.map +1 -1
  62. package/lib/module/LightPopupAd.js +182 -100
  63. package/lib/module/LightPopupAd.js.map +1 -1
  64. package/lib/module/RewardedAd.js +165 -82
  65. package/lib/module/RewardedAd.js.map +1 -1
  66. package/lib/module/index.js +1 -2
  67. package/lib/module/index.js.map +1 -1
  68. package/lib/module/nativeAd/NativeAdView.js +5 -1
  69. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  70. package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
  71. package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
  72. package/lib/module/package.json +1 -0
  73. package/lib/module/types/AdEvent.js +18 -1
  74. package/lib/module/types/AdEvent.js.map +1 -1
  75. package/lib/typescript/commonjs/plugin/src/index.d.ts +19 -0
  76. package/lib/typescript/commonjs/plugin/src/index.d.ts.map +1 -0
  77. package/lib/typescript/commonjs/plugin/src/skAdNetworkIds.d.ts +6 -0
  78. package/lib/typescript/commonjs/plugin/src/skAdNetworkIds.d.ts.map +1 -0
  79. package/lib/typescript/commonjs/plugin/src/withAndroid.d.ts +8 -0
  80. package/lib/typescript/commonjs/plugin/src/withAndroid.d.ts.map +1 -0
  81. package/lib/typescript/commonjs/plugin/src/withIos.d.ts +8 -0
  82. package/lib/typescript/commonjs/plugin/src/withIos.d.ts.map +1 -0
  83. package/lib/typescript/commonjs/src/AdBannerView.d.ts +124 -2
  84. package/lib/typescript/commonjs/src/AdBannerView.d.ts.map +1 -1
  85. package/lib/typescript/commonjs/src/AppOpenAd.d.ts +53 -2
  86. package/lib/typescript/commonjs/src/AppOpenAd.d.ts.map +1 -1
  87. package/lib/typescript/commonjs/src/ErrorCode.d.ts.map +1 -1
  88. package/lib/typescript/commonjs/src/EventEmitter.d.ts +9 -1
  89. package/lib/typescript/commonjs/src/EventEmitter.d.ts.map +1 -1
  90. package/lib/typescript/commonjs/src/InterstitialAd.d.ts +53 -2
  91. package/lib/typescript/commonjs/src/InterstitialAd.d.ts.map +1 -1
  92. package/lib/typescript/commonjs/src/LightPopupAd.d.ts +57 -2
  93. package/lib/typescript/commonjs/src/LightPopupAd.d.ts.map +1 -1
  94. package/lib/typescript/commonjs/src/RewardedAd.d.ts +57 -2
  95. package/lib/typescript/commonjs/src/RewardedAd.d.ts.map +1 -1
  96. package/lib/typescript/commonjs/src/index.d.ts +1 -1
  97. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  98. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts +124 -2
  99. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts.map +1 -1
  100. package/lib/typescript/commonjs/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  101. package/lib/typescript/commonjs/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  102. package/lib/typescript/commonjs/src/types/AdBannerViewProps.d.ts +2 -2
  103. package/lib/typescript/commonjs/src/types/AdBannerViewProps.d.ts.map +1 -1
  104. package/lib/typescript/commonjs/src/types/AdEvent.d.ts +24 -0
  105. package/lib/typescript/commonjs/src/types/AdEvent.d.ts.map +1 -1
  106. package/lib/typescript/commonjs/src/types/AdInfo.d.ts.map +1 -1
  107. package/lib/typescript/commonjs/src/types/AdProps.d.ts +2 -2
  108. package/lib/typescript/commonjs/src/types/AdProps.d.ts.map +1 -1
  109. package/lib/typescript/commonjs/src/types/DaroMMobileAds.d.ts.map +1 -1
  110. package/lib/typescript/commonjs/src/types/LightPopupAd.d.ts +1 -5
  111. package/lib/typescript/commonjs/src/types/LightPopupAd.d.ts.map +1 -1
  112. package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts.map +1 -1
  113. package/lib/typescript/module/plugin/src/index.d.ts +19 -0
  114. package/lib/typescript/module/plugin/src/index.d.ts.map +1 -0
  115. package/lib/typescript/module/plugin/src/skAdNetworkIds.d.ts +6 -0
  116. package/lib/typescript/module/plugin/src/skAdNetworkIds.d.ts.map +1 -0
  117. package/lib/typescript/module/plugin/src/withAndroid.d.ts +8 -0
  118. package/lib/typescript/module/plugin/src/withAndroid.d.ts.map +1 -0
  119. package/lib/typescript/module/plugin/src/withIos.d.ts +8 -0
  120. package/lib/typescript/module/plugin/src/withIos.d.ts.map +1 -0
  121. package/lib/typescript/module/src/AdBannerView.d.ts +124 -2
  122. package/lib/typescript/module/src/AdBannerView.d.ts.map +1 -1
  123. package/lib/typescript/module/src/AppOpenAd.d.ts +53 -2
  124. package/lib/typescript/module/src/AppOpenAd.d.ts.map +1 -1
  125. package/lib/typescript/module/src/ErrorCode.d.ts.map +1 -1
  126. package/lib/typescript/module/src/EventEmitter.d.ts +9 -1
  127. package/lib/typescript/module/src/EventEmitter.d.ts.map +1 -1
  128. package/lib/typescript/module/src/InterstitialAd.d.ts +53 -2
  129. package/lib/typescript/module/src/InterstitialAd.d.ts.map +1 -1
  130. package/lib/typescript/module/src/LightPopupAd.d.ts +57 -2
  131. package/lib/typescript/module/src/LightPopupAd.d.ts.map +1 -1
  132. package/lib/typescript/module/src/RewardedAd.d.ts +57 -2
  133. package/lib/typescript/module/src/RewardedAd.d.ts.map +1 -1
  134. package/lib/typescript/module/src/index.d.ts +1 -1
  135. package/lib/typescript/module/src/index.d.ts.map +1 -1
  136. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts +124 -2
  137. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts.map +1 -1
  138. package/lib/typescript/module/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  139. package/lib/typescript/module/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  140. package/lib/typescript/module/src/types/AdBannerViewProps.d.ts +2 -2
  141. package/lib/typescript/module/src/types/AdBannerViewProps.d.ts.map +1 -1
  142. package/lib/typescript/module/src/types/AdEvent.d.ts +24 -0
  143. package/lib/typescript/module/src/types/AdEvent.d.ts.map +1 -1
  144. package/lib/typescript/module/src/types/AdInfo.d.ts.map +1 -1
  145. package/lib/typescript/module/src/types/AdProps.d.ts +2 -2
  146. package/lib/typescript/module/src/types/AdProps.d.ts.map +1 -1
  147. package/lib/typescript/module/src/types/DaroMMobileAds.d.ts.map +1 -1
  148. package/lib/typescript/module/src/types/LightPopupAd.d.ts +1 -5
  149. package/lib/typescript/module/src/types/LightPopupAd.d.ts.map +1 -1
  150. package/lib/typescript/module/src/types/NativeAdViewProps.d.ts.map +1 -1
  151. package/package.json +88 -101
  152. package/plugin/build/index.d.ts +18 -0
  153. package/plugin/build/index.js +71 -0
  154. package/plugin/build/skAdNetworkIds.d.ts +5 -0
  155. package/plugin/build/skAdNetworkIds.js +205 -0
  156. package/plugin/build/withAndroid.d.ts +7 -0
  157. package/plugin/build/withAndroid.js +140 -0
  158. package/plugin/build/withIos.d.ts +7 -0
  159. package/plugin/build/withIos.js +83 -0
  160. package/react-native-daro.podspec +25 -0
  161. package/src/AdBannerView.tsx +54 -17
  162. package/src/AppOpenAd.ts +216 -104
  163. package/src/ErrorCode.ts +1 -2
  164. package/src/EventEmitter.ts +63 -14
  165. package/src/InterstitialAd.ts +216 -104
  166. package/src/LightPopupAd.ts +240 -114
  167. package/src/RewardedAd.ts +233 -122
  168. package/src/index.tsx +20 -12
  169. package/src/nativeAd/NativeAdView.tsx +65 -14
  170. package/src/nativeAd/NativeAdViewComponents.tsx +54 -27
  171. package/src/nativeAd/NativeAdViewProvider.tsx +17 -7
  172. package/src/types/AdBannerViewProps.ts +11 -11
  173. package/src/types/AdEvent.ts +39 -2
  174. package/src/types/AdInfo.ts +17 -17
  175. package/src/types/AdProps.ts +8 -9
  176. package/src/types/DaroMMobileAds.ts +3 -6
  177. package/src/types/LightPopupAd.ts +2 -7
  178. package/src/types/NativeAdViewProps.ts +5 -5
  179. package/src/types/index.ts +1 -1
  180. package/android/gradle.properties +0 -5
  181. package/android/src/main/AndroidManifestNew.xml +0 -7
  182. package/android/src/main/java/com/darom/view/DaroMAdBannerViewContainer.kt +0 -163
  183. package/android/src/main/res/layout/layout_activity_transparent.xml +0 -7
  184. package/android/src/main/res/values/styles.xml +0 -11
  185. package/ios/DaroM-Bridging-Header.h +0 -6
  186. package/lib/commonjs/types/AppOpenAd.js +0 -6
  187. package/lib/commonjs/types/AppOpenAd.js.map +0 -1
  188. package/lib/commonjs/types/FullScreenAd.js +0 -6
  189. package/lib/commonjs/types/FullScreenAd.js.map +0 -1
  190. package/lib/commonjs/types/InterstitialAd.js +0 -6
  191. package/lib/commonjs/types/InterstitialAd.js.map +0 -1
  192. package/lib/commonjs/types/RewardedAd.js +0 -6
  193. package/lib/commonjs/types/RewardedAd.js.map +0 -1
  194. package/lib/module/types/AppOpenAd.js +0 -4
  195. package/lib/module/types/AppOpenAd.js.map +0 -1
  196. package/lib/module/types/FullScreenAd.js +0 -4
  197. package/lib/module/types/FullScreenAd.js.map +0 -1
  198. package/lib/module/types/InterstitialAd.js +0 -4
  199. package/lib/module/types/InterstitialAd.js.map +0 -1
  200. package/lib/module/types/RewardedAd.js +0 -4
  201. package/lib/module/types/RewardedAd.js.map +0 -1
  202. package/lib/typescript/commonjs/src/types/AppOpenAd.d.ts +0 -3
  203. package/lib/typescript/commonjs/src/types/AppOpenAd.d.ts.map +0 -1
  204. package/lib/typescript/commonjs/src/types/FullScreenAd.d.ts +0 -21
  205. package/lib/typescript/commonjs/src/types/FullScreenAd.d.ts.map +0 -1
  206. package/lib/typescript/commonjs/src/types/InterstitialAd.d.ts +0 -3
  207. package/lib/typescript/commonjs/src/types/InterstitialAd.d.ts.map +0 -1
  208. package/lib/typescript/commonjs/src/types/RewardedAd.d.ts +0 -9
  209. package/lib/typescript/commonjs/src/types/RewardedAd.d.ts.map +0 -1
  210. package/lib/typescript/module/src/types/AppOpenAd.d.ts +0 -3
  211. package/lib/typescript/module/src/types/AppOpenAd.d.ts.map +0 -1
  212. package/lib/typescript/module/src/types/FullScreenAd.d.ts +0 -21
  213. package/lib/typescript/module/src/types/FullScreenAd.d.ts.map +0 -1
  214. package/lib/typescript/module/src/types/InterstitialAd.d.ts +0 -3
  215. package/lib/typescript/module/src/types/InterstitialAd.d.ts.map +0 -1
  216. package/lib/typescript/module/src/types/RewardedAd.d.ts +0 -9
  217. package/lib/typescript/module/src/types/RewardedAd.d.ts.map +0 -1
  218. package/react-native-daro-m.podspec +0 -44
  219. package/src/types/AppOpenAd.ts +0 -3
  220. package/src/types/FullScreenAd.ts +0 -28
  221. package/src/types/InterstitialAd.ts +0 -3
  222. package/src/types/RewardedAd.ts +0 -15
@@ -1,8 +1,16 @@
1
- import { NativeModules } from "react-native";
2
- import { addEventListener, removeEventListener } from "./EventEmitter";
3
- import type { AdDisplayFailedInfo, AdInfo, AdLoadFailedInfo } from "./types/AdInfo";
4
- import type { LightPopupAdConfiguration, LightPopupAdType } from "./types/LightPopupAd";
5
- import tinycolor from "tinycolor2";
1
+ import { NativeModules, processColor, type ColorValue } from 'react-native';
2
+ import {
3
+ addEventListener,
4
+ removeEventListener,
5
+ AdEventEmitter,
6
+ } from './EventEmitter';
7
+ import type {
8
+ AdDisplayFailedInfo,
9
+ AdInfo,
10
+ AdLoadFailedInfo,
11
+ } from './types/AdInfo';
12
+ import type { LightPopupAdConfiguration } from './types/LightPopupAd';
13
+ import { AdEventType, type AdEventPayloadMap } from './types/AdEvent';
6
14
 
7
15
  const { DaroMModule } = NativeModules;
8
16
 
@@ -16,146 +24,264 @@ const {
16
24
  ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED,
17
25
  } = DaroMModule.getConstants();
18
26
 
19
- const isAdReady = (adUnitId: string): Promise<boolean> => {
20
- return DaroMModule.isLightPopupReady(adUnitId);
27
+ const NATIVE_EVENT_BY_TYPE: Record<AdEventType, string> = {
28
+ [AdEventType.LOADED]: ON_LIGHTPOPUP_LOADED_EVENT,
29
+ [AdEventType.LOAD_FAILED]: ON_LIGHTPOPUP_LOAD_FAILED_EVENT,
30
+ [AdEventType.CLICKED]: ON_LIGHTPOPUP_CLICKED_EVENT,
31
+ [AdEventType.DISPLAYED]: ON_LIGHTPOPUP_DISPLAYED_EVENT,
32
+ [AdEventType.FAILED_TO_DISPLAY]: ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT,
33
+ [AdEventType.HIDDEN]: ON_LIGHTPOPUP_HIDDEN_EVENT,
34
+ [AdEventType.IMPRESSION_RECORDED]: ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED,
21
35
  };
22
36
 
23
- const loadAd = (adUnitId: string): void => {
24
- DaroMModule.loadLightPopup(adUnitId);
25
- };
37
+ const colorToHex = (color: ColorValue | undefined): string | undefined => {
38
+ if (color === undefined || color === null) {
39
+ return undefined;
40
+ }
26
41
 
27
- const showAd = (adUnitId: string): void => {
28
- DaroMModule.showLightPopup(adUnitId);
29
- };
42
+ const processedColor = processColor(color);
43
+ if (typeof processedColor !== 'number') {
44
+ return undefined;
45
+ }
30
46
 
31
- function colorToHex(color: any): string | undefined {
32
- if (typeof color === "number") {
33
- // react-native에서 number로 오는 경우 (ex: processColor)
34
- // #AARRGGBB로 변환
35
- return `#${color.toString(16).padStart(8, "0")}`.toUpperCase();
36
- }
37
- if (typeof color === "string") {
38
- const tc = tinycolor(color);
39
- if (tc.isValid()) {
40
- // alpha가 1이면 #RRGGBB, 아니면 #AARRGGBB
41
- const hex = tc.toHexString().toUpperCase();
42
- const alpha = Math.round(tc.getAlpha() * 255);
43
- if (alpha === 255) {
44
- return hex;
45
- } else {
46
- // #AARRGGBB
47
- return (
48
- "#" +
49
- alpha.toString(16).padStart(2, "0").toUpperCase() +
50
- tc.toHex().toUpperCase()
51
- );
52
- }
53
- }
47
+ const argb = processedColor >>> 0;
48
+ const alpha = (argb >>> 24) & 0xff;
49
+ if (alpha === 0xff) {
50
+ return `#${(argb & 0x00ffffff).toString(16).padStart(6, '0')}`.toUpperCase();
54
51
  }
55
- return undefined;
56
- }
57
52
 
58
- const setLightPopupAdConfiguration = (adUnitId: string, configuration: LightPopupAdConfiguration): void => {
53
+ return `#${argb.toString(16).padStart(8, '0')}`.toUpperCase();
54
+ };
55
+
56
+ const normalizeConfiguration = (
57
+ configuration: LightPopupAdConfiguration
58
+ ): LightPopupAdConfiguration => {
59
59
  const config = { ...configuration };
60
60
 
61
- // color 관련 필드만 hex string으로 변환
62
- if (config.backgroundColor) config.backgroundColor = colorToHex(config.backgroundColor);
63
- if (config.cardViewBackgroundColor) config.cardViewBackgroundColor = colorToHex(config.cardViewBackgroundColor);
64
- if (config.adMarkLabelTextColor) config.adMarkLabelTextColor = colorToHex(config.adMarkLabelTextColor);
65
- if (config.adMarkLabelBackgroundColor) config.adMarkLabelBackgroundColor = colorToHex(config.adMarkLabelBackgroundColor);
61
+ if (config.backgroundColor)
62
+ config.backgroundColor = colorToHex(config.backgroundColor);
63
+ if (config.cardViewBackgroundColor)
64
+ config.cardViewBackgroundColor = colorToHex(config.cardViewBackgroundColor);
65
+ if (config.adMarkLabelTextColor)
66
+ config.adMarkLabelTextColor = colorToHex(config.adMarkLabelTextColor);
67
+ if (config.adMarkLabelBackgroundColor)
68
+ config.adMarkLabelBackgroundColor = colorToHex(
69
+ config.adMarkLabelBackgroundColor
70
+ );
66
71
  if (config.closeButtonText) config.closeButtonText = config.closeButtonText;
67
- if (config.closeButtonTextColor) config.closeButtonTextColor = colorToHex(config.closeButtonTextColor);
68
- if (config.titleTextColor) config.titleTextColor = colorToHex(config.titleTextColor);
69
- if (config.bodyTextColor) config.bodyTextColor = colorToHex(config.bodyTextColor);
70
- if (config.ctaButtonTextColor) config.ctaButtonTextColor = colorToHex(config.ctaButtonTextColor);
71
- if (config.ctaButtonBackgroundColor) config.ctaButtonBackgroundColor = colorToHex(config.ctaButtonBackgroundColor);
72
-
73
- DaroMModule.setLightPopupAdConfiguration(adUnitId, config);
72
+ if (config.closeButtonTextColor)
73
+ config.closeButtonTextColor = colorToHex(config.closeButtonTextColor);
74
+ if (config.titleTextColor)
75
+ config.titleTextColor = colorToHex(config.titleTextColor);
76
+ if (config.bodyTextColor)
77
+ config.bodyTextColor = colorToHex(config.bodyTextColor);
78
+ if (config.ctaButtonTextColor)
79
+ config.ctaButtonTextColor = colorToHex(config.ctaButtonTextColor);
80
+ if (config.ctaButtonBackgroundColor)
81
+ config.ctaButtonBackgroundColor = colorToHex(
82
+ config.ctaButtonBackgroundColor
83
+ );
84
+
85
+ return config;
74
86
  };
75
87
 
76
- const addAdLoadedEventListener = (listener: (adInfo: AdInfo) => void): void => {
77
- addEventListener(ON_LIGHTPOPUP_LOADED_EVENT, listener);
78
- };
88
+ export class LightPopupAd {
89
+ private static _nextRequestId = 1;
90
+ private static _legacyRequestIds = new Map<string, number>();
91
+ private static _legacyRequestIdSet = new Set<number>();
79
92
 
80
- const removeAdLoadedEventListener = (): void => {
81
- removeEventListener(ON_LIGHTPOPUP_LOADED_EVENT);
82
- };
93
+ private readonly eventEmitter = new AdEventEmitter();
83
94
 
84
- const addAdLoadFailedEventListener = (listener: (errorInfo: AdLoadFailedInfo) => void): void => {
85
- addEventListener(ON_LIGHTPOPUP_LOAD_FAILED_EVENT, listener);
86
- };
95
+ private constructor(
96
+ private readonly requestId: number,
97
+ private readonly adUnitId: string
98
+ ) {}
87
99
 
88
- const removeAdLoadFailedEventListener = (): void => {
89
- removeEventListener(ON_LIGHTPOPUP_LOAD_FAILED_EVENT);
90
- };
100
+ static createForAdRequest(adUnitId: string): LightPopupAd {
101
+ const requestId = LightPopupAd._nextRequestId++;
102
+ return new LightPopupAd(requestId, adUnitId);
103
+ }
91
104
 
92
- const addAdClickedEventListener = (listener: (adInfo: AdInfo) => void): void => {
93
- addEventListener(ON_LIGHTPOPUP_CLICKED_EVENT, listener);
94
- };
105
+ isAdReady(): Promise<boolean> {
106
+ return DaroMModule.isLightPopupReady(this.requestId, this.adUnitId);
107
+ }
95
108
 
96
- const removeAdClickedEventListener = (): void => {
97
- removeEventListener(ON_LIGHTPOPUP_CLICKED_EVENT);
98
- };
109
+ load(): void {
110
+ DaroMModule.loadLightPopup(this.requestId, this.adUnitId);
111
+ }
99
112
 
100
- const addAdDisplayedEventListener = (listener: (adInfo: AdInfo) => void): void => {
101
- addEventListener(ON_LIGHTPOPUP_DISPLAYED_EVENT, listener);
102
- };
113
+ show(): void {
114
+ DaroMModule.showLightPopup(this.requestId, this.adUnitId);
115
+ }
103
116
 
104
- const removeAdDisplayedEventListener = (): void => {
105
- removeEventListener(ON_LIGHTPOPUP_DISPLAYED_EVENT);
106
- };
117
+ setConfiguration(configuration: LightPopupAdConfiguration): void {
118
+ DaroMModule.setLightPopupAdConfiguration(
119
+ this.requestId,
120
+ this.adUnitId,
121
+ normalizeConfiguration(configuration)
122
+ );
123
+ }
107
124
 
108
- const addAdFailedToDisplayEventListener = (listener: (errorInfo: AdDisplayFailedInfo) => void): void => {
109
- addEventListener(ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT, listener);
110
- };
125
+ addAdEventListener<T extends AdEventType>(
126
+ type: T,
127
+ listener: (info: AdEventPayloadMap[T]) => void
128
+ ): () => void {
129
+ const nativeEvent = NATIVE_EVENT_BY_TYPE[type];
130
+ const requestId = this.requestId;
131
+ return this.eventEmitter.addEventListener(nativeEvent, (payload: any) => {
132
+ if (payload?.requestId !== requestId) {
133
+ return;
134
+ }
135
+ listener(payload);
136
+ });
137
+ }
111
138
 
112
- const removeAdFailedToDisplayEventListener = (): void => {
113
- removeEventListener(ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT);
114
- };
139
+ removeAllListeners(): void {
140
+ this.eventEmitter.removeAllListeners();
141
+ }
115
142
 
116
- const addAdHiddenEventListener = (listener: (adInfo: AdInfo) => void): void => {
117
- addEventListener(ON_LIGHTPOPUP_HIDDEN_EVENT, listener);
118
- };
143
+ // ---- Deprecated static API (backward compatibility) ----
119
144
 
120
- const removeAdHiddenEventListener = (): void => {
121
- removeEventListener(ON_LIGHTPOPUP_HIDDEN_EVENT);
122
- };
145
+ private static _getLegacyRequestId(adUnitId: string): number {
146
+ let requestId = LightPopupAd._legacyRequestIds.get(adUnitId);
147
+ if (requestId === undefined) {
148
+ requestId = LightPopupAd._nextRequestId++;
149
+ LightPopupAd._legacyRequestIds.set(adUnitId, requestId);
150
+ LightPopupAd._legacyRequestIdSet.add(requestId);
151
+ }
152
+ return requestId;
153
+ }
123
154
 
124
- const addAdImpressionRecordedListener = (listener: (adInfo: AdInfo) => void): void => {
125
- addEventListener(ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED, listener);
126
- };
155
+ private static _addLegacyEventListener<T>(
156
+ event: string,
157
+ listener: (info: T) => void
158
+ ): void {
159
+ addEventListener(event, (payload: any) => {
160
+ if (!LightPopupAd._legacyRequestIdSet.has(payload?.requestId)) {
161
+ return;
162
+ }
163
+ listener(payload);
164
+ });
165
+ }
127
166
 
128
- const removeAdImpressionRecordedListener = (): void => {
129
- removeEventListener(ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED);
130
- };
167
+ /** @deprecated `LightPopupAd.createForAdRequest(adUnitId)` 인스턴스의 `isAdReady()`를 사용하세요. */
168
+ static isAdReady(adUnitId: string): Promise<boolean> {
169
+ const requestId = LightPopupAd._getLegacyRequestId(adUnitId);
170
+ return DaroMModule.isLightPopupReady(requestId, adUnitId);
171
+ }
172
+
173
+ /** @deprecated `LightPopupAd.createForAdRequest(adUnitId)` 인스턴스의 `load()`를 사용하세요. */
174
+ static loadAd(adUnitId: string): void {
175
+ const requestId = LightPopupAd._getLegacyRequestId(adUnitId);
176
+ DaroMModule.loadLightPopup(requestId, adUnitId);
177
+ }
131
178
 
132
- export const LightPopupAd: LightPopupAdType = {
133
- isAdReady,
134
- loadAd,
135
- showAd,
179
+ /** @deprecated `LightPopupAd.createForAdRequest(adUnitId)` 인스턴스의 `show()`를 사용하세요. */
180
+ static showAd(adUnitId: string): void {
181
+ const requestId = LightPopupAd._getLegacyRequestId(adUnitId);
182
+ DaroMModule.showLightPopup(requestId, adUnitId);
183
+ }
136
184
 
137
- addAdLoadedEventListener,
138
- removeAdLoadedEventListener,
185
+ /** @deprecated 인스턴스의 `setConfiguration()`을 사용하세요. */
186
+ static setLightPopupAdConfiguration(
187
+ adUnitId: string,
188
+ configuration: LightPopupAdConfiguration
189
+ ): void {
190
+ const requestId = LightPopupAd._getLegacyRequestId(adUnitId);
191
+ DaroMModule.setLightPopupAdConfiguration(
192
+ requestId,
193
+ adUnitId,
194
+ normalizeConfiguration(configuration)
195
+ );
196
+ }
139
197
 
140
- addAdLoadFailedEventListener,
141
- removeAdLoadFailedEventListener,
198
+ /** @deprecated `addAdEventListener(AdEventType.LOADED, ...)`를 인스턴스에서 사용하세요. */
199
+ static addAdLoadedEventListener(listener: (adInfo: AdInfo) => void): void {
200
+ LightPopupAd._addLegacyEventListener(ON_LIGHTPOPUP_LOADED_EVENT, listener);
201
+ }
142
202
 
143
- addAdClickedEventListener,
144
- removeAdClickedEventListener,
203
+ /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
204
+ static removeAdLoadedEventListener(): void {
205
+ removeEventListener(ON_LIGHTPOPUP_LOADED_EVENT);
206
+ }
145
207
 
146
- addAdDisplayedEventListener,
147
- removeAdDisplayedEventListener,
208
+ /** @deprecated `addAdEventListener(AdEventType.LOAD_FAILED, ...)`를 인스턴스에서 사용하세요. */
209
+ static addAdLoadFailedEventListener(
210
+ listener: (errorInfo: AdLoadFailedInfo) => void
211
+ ): void {
212
+ LightPopupAd._addLegacyEventListener(
213
+ ON_LIGHTPOPUP_LOAD_FAILED_EVENT,
214
+ listener
215
+ );
216
+ }
148
217
 
149
- addAdFailedToDisplayEventListener,
150
- removeAdFailedToDisplayEventListener,
218
+ /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
219
+ static removeAdLoadFailedEventListener(): void {
220
+ removeEventListener(ON_LIGHTPOPUP_LOAD_FAILED_EVENT);
221
+ }
151
222
 
152
- addAdHiddenEventListener,
153
- removeAdHiddenEventListener,
223
+ /** @deprecated `addAdEventListener(AdEventType.CLICKED, ...)`를 인스턴스에서 사용하세요. */
224
+ static addAdClickedEventListener(listener: (adInfo: AdInfo) => void): void {
225
+ LightPopupAd._addLegacyEventListener(ON_LIGHTPOPUP_CLICKED_EVENT, listener);
226
+ }
154
227
 
155
- addAdImpressionRecordedListener,
156
- removeAdImpressionRecordedListener,
228
+ /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
229
+ static removeAdClickedEventListener(): void {
230
+ removeEventListener(ON_LIGHTPOPUP_CLICKED_EVENT);
231
+ }
157
232
 
158
- setLightPopupAdConfiguration,
159
- };
233
+ /** @deprecated `addAdEventListener(AdEventType.DISPLAYED, ...)`를 인스턴스에서 사용하세요. */
234
+ static addAdDisplayedEventListener(listener: (adInfo: AdInfo) => void): void {
235
+ LightPopupAd._addLegacyEventListener(
236
+ ON_LIGHTPOPUP_DISPLAYED_EVENT,
237
+ listener
238
+ );
239
+ }
240
+
241
+ /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
242
+ static removeAdDisplayedEventListener(): void {
243
+ removeEventListener(ON_LIGHTPOPUP_DISPLAYED_EVENT);
244
+ }
245
+
246
+ /** @deprecated `addAdEventListener(AdEventType.FAILED_TO_DISPLAY, ...)`를 인스턴스에서 사용하세요. */
247
+ static addAdFailedToDisplayEventListener(
248
+ listener: (errorInfo: AdDisplayFailedInfo) => void
249
+ ): void {
250
+ LightPopupAd._addLegacyEventListener(
251
+ ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT,
252
+ listener
253
+ );
254
+ }
255
+
256
+ /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
257
+ static removeAdFailedToDisplayEventListener(): void {
258
+ removeEventListener(ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT);
259
+ }
260
+
261
+ /** @deprecated `addAdEventListener(AdEventType.HIDDEN, ...)`를 인스턴스에서 사용하세요. */
262
+ static addAdHiddenEventListener(listener: (adInfo: AdInfo) => void): void {
263
+ LightPopupAd._addLegacyEventListener(ON_LIGHTPOPUP_HIDDEN_EVENT, listener);
264
+ }
265
+
266
+ /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
267
+ static removeAdHiddenEventListener(): void {
268
+ removeEventListener(ON_LIGHTPOPUP_HIDDEN_EVENT);
269
+ }
270
+
271
+ /** @deprecated `addAdEventListener(AdEventType.IMPRESSION_RECORDED, ...)`를 인스턴스에서 사용하세요. */
272
+ static addAdImpressionRecordedListener(
273
+ listener: (adInfo: AdInfo) => void
274
+ ): void {
275
+ LightPopupAd._addLegacyEventListener(
276
+ ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED,
277
+ listener
278
+ );
279
+ }
280
+
281
+ /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
282
+ static removeAdImpressionRecordedListener(): void {
283
+ removeEventListener(ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED);
284
+ }
285
+ }
160
286
 
161
- export default LightPopupAd;
287
+ export default LightPopupAd;