react-native-daro 1.0.13 → 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 (164) 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 +27 -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 +1 -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 +43 -17
  34. package/lib/commonjs/AppOpenAd.js.map +1 -1
  35. package/lib/commonjs/ErrorCode.js.map +1 -1
  36. package/lib/commonjs/EventEmitter.js.map +1 -1
  37. package/lib/commonjs/InterstitialAd.js +45 -17
  38. package/lib/commonjs/InterstitialAd.js.map +1 -1
  39. package/lib/commonjs/LightPopupAd.js +62 -43
  40. package/lib/commonjs/LightPopupAd.js.map +1 -1
  41. package/lib/commonjs/RewardedAd.js +44 -18
  42. package/lib/commonjs/RewardedAd.js.map +1 -1
  43. package/lib/commonjs/index.js +1 -1
  44. package/lib/commonjs/index.js.map +1 -1
  45. package/lib/commonjs/nativeAd/NativeAdView.js +5 -1
  46. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  47. package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
  48. package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
  49. package/lib/commonjs/package.json +1 -0
  50. package/lib/module/AdBannerView.js +6 -1
  51. package/lib/module/AdBannerView.js.map +1 -1
  52. package/lib/module/AppOpenAd.js +43 -17
  53. package/lib/module/AppOpenAd.js.map +1 -1
  54. package/lib/module/ErrorCode.js.map +1 -1
  55. package/lib/module/EventEmitter.js.map +1 -1
  56. package/lib/module/InterstitialAd.js +45 -17
  57. package/lib/module/InterstitialAd.js.map +1 -1
  58. package/lib/module/LightPopupAd.js +63 -43
  59. package/lib/module/LightPopupAd.js.map +1 -1
  60. package/lib/module/RewardedAd.js +44 -18
  61. package/lib/module/RewardedAd.js.map +1 -1
  62. package/lib/module/index.js +1 -1
  63. package/lib/module/index.js.map +1 -1
  64. package/lib/module/nativeAd/NativeAdView.js +5 -1
  65. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  66. package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
  67. package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
  68. package/lib/module/package.json +1 -0
  69. package/lib/typescript/commonjs/plugin/src/index.d.ts +19 -0
  70. package/lib/typescript/commonjs/plugin/src/index.d.ts.map +1 -0
  71. package/lib/typescript/commonjs/plugin/src/skAdNetworkIds.d.ts +6 -0
  72. package/lib/typescript/commonjs/plugin/src/skAdNetworkIds.d.ts.map +1 -0
  73. package/lib/typescript/commonjs/plugin/src/withAndroid.d.ts +8 -0
  74. package/lib/typescript/commonjs/plugin/src/withAndroid.d.ts.map +1 -0
  75. package/lib/typescript/commonjs/plugin/src/withIos.d.ts +8 -0
  76. package/lib/typescript/commonjs/plugin/src/withIos.d.ts.map +1 -0
  77. package/lib/typescript/commonjs/src/AdBannerView.d.ts +124 -2
  78. package/lib/typescript/commonjs/src/AdBannerView.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/src/AppOpenAd.d.ts +6 -0
  80. package/lib/typescript/commonjs/src/AppOpenAd.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/src/ErrorCode.d.ts.map +1 -1
  82. package/lib/typescript/commonjs/src/EventEmitter.d.ts.map +1 -1
  83. package/lib/typescript/commonjs/src/InterstitialAd.d.ts +6 -0
  84. package/lib/typescript/commonjs/src/InterstitialAd.d.ts.map +1 -1
  85. package/lib/typescript/commonjs/src/LightPopupAd.d.ts +6 -0
  86. package/lib/typescript/commonjs/src/LightPopupAd.d.ts.map +1 -1
  87. package/lib/typescript/commonjs/src/RewardedAd.d.ts +6 -0
  88. package/lib/typescript/commonjs/src/RewardedAd.d.ts.map +1 -1
  89. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts +124 -2
  90. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts.map +1 -1
  91. package/lib/typescript/commonjs/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  92. package/lib/typescript/commonjs/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  93. package/lib/typescript/commonjs/src/types/AdBannerViewProps.d.ts +2 -2
  94. package/lib/typescript/commonjs/src/types/AdBannerViewProps.d.ts.map +1 -1
  95. package/lib/typescript/commonjs/src/types/AdInfo.d.ts.map +1 -1
  96. package/lib/typescript/commonjs/src/types/AdProps.d.ts +2 -2
  97. package/lib/typescript/commonjs/src/types/AdProps.d.ts.map +1 -1
  98. package/lib/typescript/commonjs/src/types/DaroMMobileAds.d.ts.map +1 -1
  99. package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts.map +1 -1
  100. package/lib/typescript/module/plugin/src/index.d.ts +19 -0
  101. package/lib/typescript/module/plugin/src/index.d.ts.map +1 -0
  102. package/lib/typescript/module/plugin/src/skAdNetworkIds.d.ts +6 -0
  103. package/lib/typescript/module/plugin/src/skAdNetworkIds.d.ts.map +1 -0
  104. package/lib/typescript/module/plugin/src/withAndroid.d.ts +8 -0
  105. package/lib/typescript/module/plugin/src/withAndroid.d.ts.map +1 -0
  106. package/lib/typescript/module/plugin/src/withIos.d.ts +8 -0
  107. package/lib/typescript/module/plugin/src/withIos.d.ts.map +1 -0
  108. package/lib/typescript/module/src/AdBannerView.d.ts +124 -2
  109. package/lib/typescript/module/src/AdBannerView.d.ts.map +1 -1
  110. package/lib/typescript/module/src/AppOpenAd.d.ts +6 -0
  111. package/lib/typescript/module/src/AppOpenAd.d.ts.map +1 -1
  112. package/lib/typescript/module/src/ErrorCode.d.ts.map +1 -1
  113. package/lib/typescript/module/src/EventEmitter.d.ts.map +1 -1
  114. package/lib/typescript/module/src/InterstitialAd.d.ts +6 -0
  115. package/lib/typescript/module/src/InterstitialAd.d.ts.map +1 -1
  116. package/lib/typescript/module/src/LightPopupAd.d.ts +6 -0
  117. package/lib/typescript/module/src/LightPopupAd.d.ts.map +1 -1
  118. package/lib/typescript/module/src/RewardedAd.d.ts +6 -0
  119. package/lib/typescript/module/src/RewardedAd.d.ts.map +1 -1
  120. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts +124 -2
  121. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts.map +1 -1
  122. package/lib/typescript/module/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  123. package/lib/typescript/module/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  124. package/lib/typescript/module/src/types/AdBannerViewProps.d.ts +2 -2
  125. package/lib/typescript/module/src/types/AdBannerViewProps.d.ts.map +1 -1
  126. package/lib/typescript/module/src/types/AdInfo.d.ts.map +1 -1
  127. package/lib/typescript/module/src/types/AdProps.d.ts +2 -2
  128. package/lib/typescript/module/src/types/AdProps.d.ts.map +1 -1
  129. package/lib/typescript/module/src/types/DaroMMobileAds.d.ts.map +1 -1
  130. package/lib/typescript/module/src/types/NativeAdViewProps.d.ts.map +1 -1
  131. package/package.json +88 -105
  132. package/plugin/build/index.d.ts +18 -0
  133. package/plugin/build/index.js +71 -0
  134. package/plugin/build/skAdNetworkIds.d.ts +5 -0
  135. package/plugin/build/skAdNetworkIds.js +205 -0
  136. package/plugin/build/withAndroid.d.ts +7 -0
  137. package/plugin/build/withAndroid.js +140 -0
  138. package/plugin/build/withIos.d.ts +7 -0
  139. package/plugin/build/withIos.js +83 -0
  140. package/react-native-daro.podspec +25 -0
  141. package/src/AdBannerView.tsx +54 -17
  142. package/src/AppOpenAd.ts +59 -15
  143. package/src/ErrorCode.ts +1 -2
  144. package/src/EventEmitter.ts +5 -2
  145. package/src/InterstitialAd.ts +73 -17
  146. package/src/LightPopupAd.ts +86 -46
  147. package/src/RewardedAd.ts +70 -18
  148. package/src/index.tsx +1 -1
  149. package/src/nativeAd/NativeAdView.tsx +65 -14
  150. package/src/nativeAd/NativeAdViewComponents.tsx +54 -27
  151. package/src/nativeAd/NativeAdViewProvider.tsx +17 -7
  152. package/src/types/AdBannerViewProps.ts +11 -11
  153. package/src/types/AdInfo.ts +17 -17
  154. package/src/types/AdProps.ts +8 -9
  155. package/src/types/DaroMMobileAds.ts +3 -6
  156. package/src/types/NativeAdViewProps.ts +5 -5
  157. package/src/types/index.ts +1 -1
  158. package/android/gradle.properties +0 -5
  159. package/android/src/main/AndroidManifestNew.xml +0 -7
  160. package/android/src/main/java/com/darom/view/DaroMAdBannerViewContainer.kt +0 -163
  161. package/android/src/main/res/layout/layout_activity_transparent.xml +0 -7
  162. package/android/src/main/res/values/styles.xml +0 -11
  163. package/ios/DaroM-Bridging-Header.h +0 -6
  164. package/react-native-daro-m.podspec +0 -44
package/src/AppOpenAd.ts CHANGED
@@ -34,24 +34,33 @@ const NATIVE_EVENT_BY_TYPE: Record<AdEventType, string> = {
34
34
  };
35
35
 
36
36
  export class AppOpenAd {
37
+ private static _nextRequestId = 1;
38
+ private static _legacyRequestIds = new Map<string, number>();
39
+ private static _legacyRequestIdSet = new Set<number>();
40
+
37
41
  private readonly eventEmitter = new AdEventEmitter();
38
42
 
39
- private constructor(private readonly adUnitId: string) {}
43
+ private constructor(
44
+ private readonly requestId: number,
45
+ private readonly adUnitId: string
46
+ ) {}
40
47
 
41
48
  static createForAdRequest(adUnitId: string): AppOpenAd {
42
- return new AppOpenAd(adUnitId);
49
+ const requestId = AppOpenAd._nextRequestId++;
50
+ return new AppOpenAd(requestId, adUnitId);
43
51
  }
44
52
 
45
53
  isAdReady(): Promise<boolean> {
46
- return DaroMModule.isAppOpenAdReady(this.adUnitId);
54
+ return DaroMModule.isAppOpenAdReady(this.requestId, this.adUnitId);
47
55
  }
48
56
 
49
57
  load(): void {
50
- DaroMModule.loadAppOpenAd(this.adUnitId);
58
+ DaroMModule.loadAppOpenAd(this.requestId, this.adUnitId);
51
59
  }
52
60
 
53
61
  show(placement?: string | null, customData?: string | null): void {
54
62
  DaroMModule.showAppOpenAd(
63
+ this.requestId,
55
64
  this.adUnitId,
56
65
  placement ?? undefined,
57
66
  customData ?? undefined
@@ -63,9 +72,9 @@ export class AppOpenAd {
63
72
  listener: (info: AdEventPayloadMap[T]) => void
64
73
  ): () => void {
65
74
  const nativeEvent = NATIVE_EVENT_BY_TYPE[type];
66
- const adUnitId = this.adUnitId;
75
+ const requestId = this.requestId;
67
76
  return this.eventEmitter.addEventListener(nativeEvent, (payload: any) => {
68
- if (payload?.adUnitId !== undefined && payload.adUnitId !== adUnitId) {
77
+ if (payload?.requestId !== requestId) {
69
78
  return;
70
79
  }
71
80
  listener(payload);
@@ -78,14 +87,38 @@ export class AppOpenAd {
78
87
 
79
88
  // ---- Deprecated static API (backward compatibility) ----
80
89
 
90
+ private static _getLegacyRequestId(adUnitId: string): number {
91
+ let requestId = AppOpenAd._legacyRequestIds.get(adUnitId);
92
+ if (requestId === undefined) {
93
+ requestId = AppOpenAd._nextRequestId++;
94
+ AppOpenAd._legacyRequestIds.set(adUnitId, requestId);
95
+ AppOpenAd._legacyRequestIdSet.add(requestId);
96
+ }
97
+ return requestId;
98
+ }
99
+
100
+ private static _addLegacyEventListener<T>(
101
+ event: string,
102
+ listener: (info: T) => void
103
+ ): void {
104
+ addEventListener(event, (payload: any) => {
105
+ if (!AppOpenAd._legacyRequestIdSet.has(payload?.requestId)) {
106
+ return;
107
+ }
108
+ listener(payload);
109
+ });
110
+ }
111
+
81
112
  /** @deprecated `AppOpenAd.createForAdRequest(adUnitId)` 인스턴스의 `isAdReady()`를 사용하세요. */
82
113
  static isAdReady(adUnitId: string): Promise<boolean> {
83
- return DaroMModule.isAppOpenAdReady(adUnitId);
114
+ const requestId = AppOpenAd._getLegacyRequestId(adUnitId);
115
+ return DaroMModule.isAppOpenAdReady(requestId, adUnitId);
84
116
  }
85
117
 
86
118
  /** @deprecated `AppOpenAd.createForAdRequest(adUnitId)` 인스턴스의 `load()`를 사용하세요. */
87
119
  static loadAd(adUnitId: string): void {
88
- DaroMModule.loadAppOpenAd(adUnitId);
120
+ const requestId = AppOpenAd._getLegacyRequestId(adUnitId);
121
+ DaroMModule.loadAppOpenAd(requestId, adUnitId);
89
122
  }
90
123
 
91
124
  /** @deprecated `AppOpenAd.createForAdRequest(adUnitId)` 인스턴스의 `show()`를 사용하세요. */
@@ -94,7 +127,9 @@ export class AppOpenAd {
94
127
  placement?: string | null,
95
128
  customData?: string | null
96
129
  ): void {
130
+ const requestId = AppOpenAd._getLegacyRequestId(adUnitId);
97
131
  DaroMModule.showAppOpenAd(
132
+ requestId,
98
133
  adUnitId,
99
134
  placement ?? undefined,
100
135
  customData ?? undefined
@@ -103,7 +138,7 @@ export class AppOpenAd {
103
138
 
104
139
  /** @deprecated `addAdEventListener(AdEventType.LOADED, ...)`를 인스턴스에서 사용하세요. */
105
140
  static addAdLoadedEventListener(listener: (adInfo: AdInfo) => void): void {
106
- addEventListener(ON_APPOPEN_AD_LOADED_EVENT, listener);
141
+ AppOpenAd._addLegacyEventListener(ON_APPOPEN_AD_LOADED_EVENT, listener);
107
142
  }
108
143
 
109
144
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -115,7 +150,10 @@ export class AppOpenAd {
115
150
  static addAdLoadFailedEventListener(
116
151
  listener: (errorInfo: AdLoadFailedInfo) => void
117
152
  ): void {
118
- addEventListener(ON_APPOPEN_AD_LOAD_FAILED_EVENT, listener);
153
+ AppOpenAd._addLegacyEventListener(
154
+ ON_APPOPEN_AD_LOAD_FAILED_EVENT,
155
+ listener
156
+ );
119
157
  }
120
158
 
121
159
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -125,7 +163,7 @@ export class AppOpenAd {
125
163
 
126
164
  /** @deprecated `addAdEventListener(AdEventType.CLICKED, ...)`를 인스턴스에서 사용하세요. */
127
165
  static addAdClickedEventListener(listener: (adInfo: AdInfo) => void): void {
128
- addEventListener(ON_APPOPEN_AD_CLICKED_EVENT, listener);
166
+ AppOpenAd._addLegacyEventListener(ON_APPOPEN_AD_CLICKED_EVENT, listener);
129
167
  }
130
168
 
131
169
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -135,7 +173,7 @@ export class AppOpenAd {
135
173
 
136
174
  /** @deprecated `addAdEventListener(AdEventType.DISPLAYED, ...)`를 인스턴스에서 사용하세요. */
137
175
  static addAdDisplayedEventListener(listener: (adInfo: AdInfo) => void): void {
138
- addEventListener(ON_APPOPEN_AD_DISPLAYED_EVENT, listener);
176
+ AppOpenAd._addLegacyEventListener(ON_APPOPEN_AD_DISPLAYED_EVENT, listener);
139
177
  }
140
178
 
141
179
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -147,7 +185,10 @@ export class AppOpenAd {
147
185
  static addAdFailedToDisplayEventListener(
148
186
  listener: (errorInfo: AdDisplayFailedInfo) => void
149
187
  ): void {
150
- addEventListener(ON_APPOPEN_AD_FAILED_TO_DISPLAY_EVENT, listener);
188
+ AppOpenAd._addLegacyEventListener(
189
+ ON_APPOPEN_AD_FAILED_TO_DISPLAY_EVENT,
190
+ listener
191
+ );
151
192
  }
152
193
 
153
194
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -157,7 +198,7 @@ export class AppOpenAd {
157
198
 
158
199
  /** @deprecated `addAdEventListener(AdEventType.HIDDEN, ...)`를 인스턴스에서 사용하세요. */
159
200
  static addAdHiddenEventListener(listener: (adInfo: AdInfo) => void): void {
160
- addEventListener(ON_APPOPEN_AD_HIDDEN_EVENT, listener);
201
+ AppOpenAd._addLegacyEventListener(ON_APPOPEN_AD_HIDDEN_EVENT, listener);
161
202
  }
162
203
 
163
204
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -169,7 +210,10 @@ export class AppOpenAd {
169
210
  static addAdImpressionRecordedListener(
170
211
  listener: (adInfo: AdInfo) => void
171
212
  ): void {
172
- addEventListener(ON_APPOPEN_AD_IMPRESSION_RECORDED, listener);
213
+ AppOpenAd._addLegacyEventListener(
214
+ ON_APPOPEN_AD_IMPRESSION_RECORDED,
215
+ listener
216
+ );
173
217
  }
174
218
 
175
219
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
package/src/ErrorCode.ts CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  export enum ErrorCode {
3
- UNSPECIFIED = 0
2
+ UNSPECIFIED = 0,
4
3
  }
@@ -11,7 +11,10 @@ export const addEventListener = <T extends AdEventObject>(
11
11
  event: string,
12
12
  handler: AdEventListener<T>
13
13
  ): (() => void) => {
14
- const subscription: EventSubscription = emitter.addListener(event, handler);
14
+ const subscription: EventSubscription = emitter.addListener(
15
+ event,
16
+ handler as (...args: Object[]) => void
17
+ );
15
18
 
16
19
  if (!subscriptions.has(event)) {
17
20
  subscriptions.set(event, new Set());
@@ -43,7 +46,7 @@ export class AdEventEmitter {
43
46
  ): () => void {
44
47
  const subscription: EventSubscription = this.emitter.addListener(
45
48
  event,
46
- handler
49
+ handler as (...args: Object[]) => void
47
50
  );
48
51
 
49
52
  if (!this.subscriptions.has(event)) {
@@ -34,24 +34,32 @@ const NATIVE_EVENT_BY_TYPE: Record<AdEventType, string> = {
34
34
  };
35
35
 
36
36
  export class InterstitialAd {
37
+ private static _nextRequestId = 1;
38
+ private static _legacyRequestIds = new Map<string, number>();
39
+ private static _legacyRequestIdSet = new Set<number>();
40
+
37
41
  private readonly eventEmitter = new AdEventEmitter();
38
42
 
39
- private constructor(private readonly adUnitId: string) {}
43
+ private constructor(
44
+ private readonly requestId: number,
45
+ private readonly adUnitId: string
46
+ ) {}
40
47
 
41
48
  static createForAdRequest(adUnitId: string): InterstitialAd {
42
- return new InterstitialAd(adUnitId);
49
+ const requestId = InterstitialAd._nextRequestId++;
50
+ return new InterstitialAd(requestId, adUnitId);
43
51
  }
44
52
 
45
53
  isAdReady(): Promise<boolean> {
46
- return DaroMModule.isInterstitialReady(this.adUnitId);
54
+ return DaroMModule.isInterstitialReady(this.requestId, this.adUnitId);
47
55
  }
48
56
 
49
57
  load(): void {
50
- DaroMModule.loadInterstitial(this.adUnitId);
58
+ DaroMModule.loadInterstitial(this.requestId, this.adUnitId);
51
59
  }
52
60
 
53
61
  show(): void {
54
- DaroMModule.showInterstitial(this.adUnitId);
62
+ DaroMModule.showInterstitial(this.requestId, this.adUnitId);
55
63
  }
56
64
 
57
65
  addAdEventListener<T extends AdEventType>(
@@ -59,9 +67,9 @@ export class InterstitialAd {
59
67
  listener: (info: AdEventPayloadMap[T]) => void
60
68
  ): () => void {
61
69
  const nativeEvent = NATIVE_EVENT_BY_TYPE[type];
62
- const adUnitId = this.adUnitId;
70
+ const requestId = this.requestId;
63
71
  return this.eventEmitter.addEventListener(nativeEvent, (payload: any) => {
64
- if (payload?.adUnitId !== undefined && payload.adUnitId !== adUnitId) {
72
+ if (payload?.requestId !== requestId) {
65
73
  return;
66
74
  }
67
75
  listener(payload);
@@ -73,25 +81,55 @@ export class InterstitialAd {
73
81
  }
74
82
 
75
83
  // ---- Deprecated static API (backward compatibility) ----
84
+ // Static API allocates a stable requestId per adUnitId and reuses it.
85
+ // Multiple static calls for the same adUnitId share the same native slot.
86
+
87
+ private static _getLegacyRequestId(adUnitId: string): number {
88
+ let requestId = InterstitialAd._legacyRequestIds.get(adUnitId);
89
+ if (requestId === undefined) {
90
+ requestId = InterstitialAd._nextRequestId++;
91
+ InterstitialAd._legacyRequestIds.set(adUnitId, requestId);
92
+ InterstitialAd._legacyRequestIdSet.add(requestId);
93
+ }
94
+ return requestId;
95
+ }
96
+
97
+ private static _addLegacyEventListener<T>(
98
+ event: string,
99
+ listener: (info: T) => void
100
+ ): void {
101
+ addEventListener(event, (payload: any) => {
102
+ if (!InterstitialAd._legacyRequestIdSet.has(payload?.requestId)) {
103
+ return;
104
+ }
105
+ listener(payload);
106
+ });
107
+ }
76
108
 
77
109
  /** @deprecated `InterstitialAd.createForAdRequest(adUnitId)` 인스턴스의 `isAdReady()`를 사용하세요. */
78
110
  static isAdReady(adUnitId: string): Promise<boolean> {
79
- return DaroMModule.isInterstitialReady(adUnitId);
111
+ const requestId = InterstitialAd._getLegacyRequestId(adUnitId);
112
+ return DaroMModule.isInterstitialReady(requestId, adUnitId);
80
113
  }
81
114
 
82
115
  /** @deprecated `InterstitialAd.createForAdRequest(adUnitId)` 인스턴스의 `load()`를 사용하세요. */
83
116
  static loadAd(adUnitId: string): void {
84
- DaroMModule.loadInterstitial(adUnitId);
117
+ const requestId = InterstitialAd._getLegacyRequestId(adUnitId);
118
+ DaroMModule.loadInterstitial(requestId, adUnitId);
85
119
  }
86
120
 
87
121
  /** @deprecated `InterstitialAd.createForAdRequest(adUnitId)` 인스턴스의 `show()`를 사용하세요. */
88
122
  static showAd(adUnitId: string): void {
89
- DaroMModule.showInterstitial(adUnitId);
123
+ const requestId = InterstitialAd._getLegacyRequestId(adUnitId);
124
+ DaroMModule.showInterstitial(requestId, adUnitId);
90
125
  }
91
126
 
92
127
  /** @deprecated `addAdEventListener(AdEventType.LOADED, ...)`를 인스턴스에서 사용하세요. */
93
128
  static addAdLoadedEventListener(listener: (adInfo: AdInfo) => void): void {
94
- addEventListener(ON_INTERSTITIAL_LOADED_EVENT, listener);
129
+ InterstitialAd._addLegacyEventListener(
130
+ ON_INTERSTITIAL_LOADED_EVENT,
131
+ listener
132
+ );
95
133
  }
96
134
 
97
135
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -103,7 +141,10 @@ export class InterstitialAd {
103
141
  static addAdLoadFailedEventListener(
104
142
  listener: (errorInfo: AdLoadFailedInfo) => void
105
143
  ): void {
106
- addEventListener(ON_INTERSTITIAL_LOAD_FAILED_EVENT, listener);
144
+ InterstitialAd._addLegacyEventListener(
145
+ ON_INTERSTITIAL_LOAD_FAILED_EVENT,
146
+ listener
147
+ );
107
148
  }
108
149
 
109
150
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -113,7 +154,10 @@ export class InterstitialAd {
113
154
 
114
155
  /** @deprecated `addAdEventListener(AdEventType.CLICKED, ...)`를 인스턴스에서 사용하세요. */
115
156
  static addAdClickedEventListener(listener: (adInfo: AdInfo) => void): void {
116
- addEventListener(ON_INTERSTITIAL_CLICKED_EVENT, listener);
157
+ InterstitialAd._addLegacyEventListener(
158
+ ON_INTERSTITIAL_CLICKED_EVENT,
159
+ listener
160
+ );
117
161
  }
118
162
 
119
163
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -123,7 +167,10 @@ export class InterstitialAd {
123
167
 
124
168
  /** @deprecated `addAdEventListener(AdEventType.DISPLAYED, ...)`를 인스턴스에서 사용하세요. */
125
169
  static addAdDisplayedEventListener(listener: (adInfo: AdInfo) => void): void {
126
- addEventListener(ON_INTERSTITIAL_DISPLAYED_EVENT, listener);
170
+ InterstitialAd._addLegacyEventListener(
171
+ ON_INTERSTITIAL_DISPLAYED_EVENT,
172
+ listener
173
+ );
127
174
  }
128
175
 
129
176
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -135,7 +182,10 @@ export class InterstitialAd {
135
182
  static addAdFailedToDisplayEventListener(
136
183
  listener: (errorInfo: AdDisplayFailedInfo) => void
137
184
  ): void {
138
- addEventListener(ON_INTERSTITIAL_AD_FAILED_TO_DISPLAY_EVENT, listener);
185
+ InterstitialAd._addLegacyEventListener(
186
+ ON_INTERSTITIAL_AD_FAILED_TO_DISPLAY_EVENT,
187
+ listener
188
+ );
139
189
  }
140
190
 
141
191
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -145,7 +195,10 @@ export class InterstitialAd {
145
195
 
146
196
  /** @deprecated `addAdEventListener(AdEventType.HIDDEN, ...)`를 인스턴스에서 사용하세요. */
147
197
  static addAdHiddenEventListener(listener: (adInfo: AdInfo) => void): void {
148
- addEventListener(ON_INTERSTITIAL_HIDDEN_EVENT, listener);
198
+ InterstitialAd._addLegacyEventListener(
199
+ ON_INTERSTITIAL_HIDDEN_EVENT,
200
+ listener
201
+ );
149
202
  }
150
203
 
151
204
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -157,7 +210,10 @@ export class InterstitialAd {
157
210
  static addAdImpressionRecordedListener(
158
211
  listener: (adInfo: AdInfo) => void
159
212
  ): void {
160
- addEventListener(ON_INTERSTITIAL_AD_IMPRESSION_RECORDED, listener);
213
+ InterstitialAd._addLegacyEventListener(
214
+ ON_INTERSTITIAL_AD_IMPRESSION_RECORDED,
215
+ listener
216
+ );
161
217
  }
162
218
 
163
219
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -1,4 +1,4 @@
1
- import { NativeModules } from 'react-native';
1
+ import { NativeModules, processColor, type ColorValue } from 'react-native';
2
2
  import {
3
3
  addEventListener,
4
4
  removeEventListener,
@@ -11,7 +11,6 @@ import type {
11
11
  } from './types/AdInfo';
12
12
  import type { LightPopupAdConfiguration } from './types/LightPopupAd';
13
13
  import { AdEventType, type AdEventPayloadMap } from './types/AdEvent';
14
- import tinycolor from 'tinycolor2';
15
14
 
16
15
  const { DaroMModule } = NativeModules;
17
16
 
@@ -35,35 +34,28 @@ const NATIVE_EVENT_BY_TYPE: Record<AdEventType, string> = {
35
34
  [AdEventType.IMPRESSION_RECORDED]: ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED,
36
35
  };
37
36
 
38
- function colorToHex(color: any): string | undefined {
39
- if (typeof color === 'number') {
40
- // react-native에서 number로 오는 경우 (ex: processColor)
41
- // #AARRGGBB로 변환
42
- return `#${color.toString(16).padStart(8, '0')}`.toUpperCase();
43
- }
44
- if (typeof color === 'string') {
45
- const tc = tinycolor(color);
46
- if (tc.isValid()) {
47
- // alpha가 1이면 #RRGGBB, 아니면 #AARRGGBB
48
- const hex = tc.toHexString().toUpperCase();
49
- const alpha = Math.round(tc.getAlpha() * 255);
50
- if (alpha === 255) {
51
- return hex;
52
- } else {
53
- return (
54
- '#' +
55
- alpha.toString(16).padStart(2, '0').toUpperCase() +
56
- tc.toHex().toUpperCase()
57
- );
58
- }
59
- }
37
+ const colorToHex = (color: ColorValue | undefined): string | undefined => {
38
+ if (color === undefined || color === null) {
39
+ return undefined;
40
+ }
41
+
42
+ const processedColor = processColor(color);
43
+ if (typeof processedColor !== 'number') {
44
+ return undefined;
45
+ }
46
+
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();
60
51
  }
61
- return undefined;
62
- }
63
52
 
64
- function normalizeConfiguration(
53
+ return `#${argb.toString(16).padStart(8, '0')}`.toUpperCase();
54
+ };
55
+
56
+ const normalizeConfiguration = (
65
57
  configuration: LightPopupAdConfiguration
66
- ): LightPopupAdConfiguration {
58
+ ): LightPopupAdConfiguration => {
67
59
  const config = { ...configuration };
68
60
 
69
61
  if (config.backgroundColor)
@@ -91,31 +83,40 @@ function normalizeConfiguration(
91
83
  );
92
84
 
93
85
  return config;
94
- }
86
+ };
95
87
 
96
88
  export class LightPopupAd {
89
+ private static _nextRequestId = 1;
90
+ private static _legacyRequestIds = new Map<string, number>();
91
+ private static _legacyRequestIdSet = new Set<number>();
92
+
97
93
  private readonly eventEmitter = new AdEventEmitter();
98
94
 
99
- private constructor(private readonly adUnitId: string) {}
95
+ private constructor(
96
+ private readonly requestId: number,
97
+ private readonly adUnitId: string
98
+ ) {}
100
99
 
101
100
  static createForAdRequest(adUnitId: string): LightPopupAd {
102
- return new LightPopupAd(adUnitId);
101
+ const requestId = LightPopupAd._nextRequestId++;
102
+ return new LightPopupAd(requestId, adUnitId);
103
103
  }
104
104
 
105
105
  isAdReady(): Promise<boolean> {
106
- return DaroMModule.isLightPopupReady(this.adUnitId);
106
+ return DaroMModule.isLightPopupReady(this.requestId, this.adUnitId);
107
107
  }
108
108
 
109
109
  load(): void {
110
- DaroMModule.loadLightPopup(this.adUnitId);
110
+ DaroMModule.loadLightPopup(this.requestId, this.adUnitId);
111
111
  }
112
112
 
113
113
  show(): void {
114
- DaroMModule.showLightPopup(this.adUnitId);
114
+ DaroMModule.showLightPopup(this.requestId, this.adUnitId);
115
115
  }
116
116
 
117
117
  setConfiguration(configuration: LightPopupAdConfiguration): void {
118
118
  DaroMModule.setLightPopupAdConfiguration(
119
+ this.requestId,
119
120
  this.adUnitId,
120
121
  normalizeConfiguration(configuration)
121
122
  );
@@ -126,9 +127,9 @@ export class LightPopupAd {
126
127
  listener: (info: AdEventPayloadMap[T]) => void
127
128
  ): () => void {
128
129
  const nativeEvent = NATIVE_EVENT_BY_TYPE[type];
129
- const adUnitId = this.adUnitId;
130
+ const requestId = this.requestId;
130
131
  return this.eventEmitter.addEventListener(nativeEvent, (payload: any) => {
131
- if (payload?.adUnitId !== undefined && payload.adUnitId !== adUnitId) {
132
+ if (payload?.requestId !== requestId) {
132
133
  return;
133
134
  }
134
135
  listener(payload);
@@ -141,19 +142,44 @@ export class LightPopupAd {
141
142
 
142
143
  // ---- Deprecated static API (backward compatibility) ----
143
144
 
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
+ }
154
+
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
+ }
166
+
144
167
  /** @deprecated `LightPopupAd.createForAdRequest(adUnitId)` 인스턴스의 `isAdReady()`를 사용하세요. */
145
168
  static isAdReady(adUnitId: string): Promise<boolean> {
146
- return DaroMModule.isLightPopupReady(adUnitId);
169
+ const requestId = LightPopupAd._getLegacyRequestId(adUnitId);
170
+ return DaroMModule.isLightPopupReady(requestId, adUnitId);
147
171
  }
148
172
 
149
173
  /** @deprecated `LightPopupAd.createForAdRequest(adUnitId)` 인스턴스의 `load()`를 사용하세요. */
150
174
  static loadAd(adUnitId: string): void {
151
- DaroMModule.loadLightPopup(adUnitId);
175
+ const requestId = LightPopupAd._getLegacyRequestId(adUnitId);
176
+ DaroMModule.loadLightPopup(requestId, adUnitId);
152
177
  }
153
178
 
154
179
  /** @deprecated `LightPopupAd.createForAdRequest(adUnitId)` 인스턴스의 `show()`를 사용하세요. */
155
180
  static showAd(adUnitId: string): void {
156
- DaroMModule.showLightPopup(adUnitId);
181
+ const requestId = LightPopupAd._getLegacyRequestId(adUnitId);
182
+ DaroMModule.showLightPopup(requestId, adUnitId);
157
183
  }
158
184
 
159
185
  /** @deprecated 인스턴스의 `setConfiguration()`을 사용하세요. */
@@ -161,7 +187,9 @@ export class LightPopupAd {
161
187
  adUnitId: string,
162
188
  configuration: LightPopupAdConfiguration
163
189
  ): void {
190
+ const requestId = LightPopupAd._getLegacyRequestId(adUnitId);
164
191
  DaroMModule.setLightPopupAdConfiguration(
192
+ requestId,
165
193
  adUnitId,
166
194
  normalizeConfiguration(configuration)
167
195
  );
@@ -169,7 +197,7 @@ export class LightPopupAd {
169
197
 
170
198
  /** @deprecated `addAdEventListener(AdEventType.LOADED, ...)`를 인스턴스에서 사용하세요. */
171
199
  static addAdLoadedEventListener(listener: (adInfo: AdInfo) => void): void {
172
- addEventListener(ON_LIGHTPOPUP_LOADED_EVENT, listener);
200
+ LightPopupAd._addLegacyEventListener(ON_LIGHTPOPUP_LOADED_EVENT, listener);
173
201
  }
174
202
 
175
203
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -181,7 +209,10 @@ export class LightPopupAd {
181
209
  static addAdLoadFailedEventListener(
182
210
  listener: (errorInfo: AdLoadFailedInfo) => void
183
211
  ): void {
184
- addEventListener(ON_LIGHTPOPUP_LOAD_FAILED_EVENT, listener);
212
+ LightPopupAd._addLegacyEventListener(
213
+ ON_LIGHTPOPUP_LOAD_FAILED_EVENT,
214
+ listener
215
+ );
185
216
  }
186
217
 
187
218
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -191,7 +222,7 @@ export class LightPopupAd {
191
222
 
192
223
  /** @deprecated `addAdEventListener(AdEventType.CLICKED, ...)`를 인스턴스에서 사용하세요. */
193
224
  static addAdClickedEventListener(listener: (adInfo: AdInfo) => void): void {
194
- addEventListener(ON_LIGHTPOPUP_CLICKED_EVENT, listener);
225
+ LightPopupAd._addLegacyEventListener(ON_LIGHTPOPUP_CLICKED_EVENT, listener);
195
226
  }
196
227
 
197
228
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -201,7 +232,10 @@ export class LightPopupAd {
201
232
 
202
233
  /** @deprecated `addAdEventListener(AdEventType.DISPLAYED, ...)`를 인스턴스에서 사용하세요. */
203
234
  static addAdDisplayedEventListener(listener: (adInfo: AdInfo) => void): void {
204
- addEventListener(ON_LIGHTPOPUP_DISPLAYED_EVENT, listener);
235
+ LightPopupAd._addLegacyEventListener(
236
+ ON_LIGHTPOPUP_DISPLAYED_EVENT,
237
+ listener
238
+ );
205
239
  }
206
240
 
207
241
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -213,7 +247,10 @@ export class LightPopupAd {
213
247
  static addAdFailedToDisplayEventListener(
214
248
  listener: (errorInfo: AdDisplayFailedInfo) => void
215
249
  ): void {
216
- addEventListener(ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT, listener);
250
+ LightPopupAd._addLegacyEventListener(
251
+ ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT,
252
+ listener
253
+ );
217
254
  }
218
255
 
219
256
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -223,7 +260,7 @@ export class LightPopupAd {
223
260
 
224
261
  /** @deprecated `addAdEventListener(AdEventType.HIDDEN, ...)`를 인스턴스에서 사용하세요. */
225
262
  static addAdHiddenEventListener(listener: (adInfo: AdInfo) => void): void {
226
- addEventListener(ON_LIGHTPOPUP_HIDDEN_EVENT, listener);
263
+ LightPopupAd._addLegacyEventListener(ON_LIGHTPOPUP_HIDDEN_EVENT, listener);
227
264
  }
228
265
 
229
266
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -235,7 +272,10 @@ export class LightPopupAd {
235
272
  static addAdImpressionRecordedListener(
236
273
  listener: (adInfo: AdInfo) => void
237
274
  ): void {
238
- addEventListener(ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED, listener);
275
+ LightPopupAd._addLegacyEventListener(
276
+ ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED,
277
+ listener
278
+ );
239
279
  }
240
280
 
241
281
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */