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/RewardedAd.ts CHANGED
@@ -42,24 +42,36 @@ const NATIVE_EVENT_BY_TYPE: Record<AdEventType | RewardedAdEventType, string> =
42
42
  };
43
43
 
44
44
  export class RewardedAd {
45
+ private static _nextRequestId = 1;
46
+ private static _legacyRequestIds = new Map<string, number>();
47
+ private static _legacyRequestIdSet = new Set<number>();
48
+
45
49
  private readonly eventEmitter = new AdEventEmitter();
46
50
 
47
- private constructor(private readonly adUnitId: string) {}
51
+ private constructor(
52
+ private readonly requestId: number,
53
+ private readonly adUnitId: string
54
+ ) {}
48
55
 
49
56
  static createForAdRequest(adUnitId: string): RewardedAd {
50
- return new RewardedAd(adUnitId);
57
+ const requestId = RewardedAd._nextRequestId++;
58
+ return new RewardedAd(requestId, adUnitId);
51
59
  }
52
60
 
53
61
  isAdReady(): Promise<boolean> {
54
- return DaroMModule.isRewardedAdReady(this.adUnitId);
62
+ return DaroMModule.isRewardedAdReady(this.requestId, this.adUnitId);
55
63
  }
56
64
 
57
65
  load(): void {
58
- DaroMModule.loadRewardedAd(this.adUnitId);
66
+ DaroMModule.loadRewardedAd(this.requestId, this.adUnitId);
59
67
  }
60
68
 
61
69
  show(customData?: string | null): void {
62
- DaroMModule.showRewardedAd(this.adUnitId, customData ?? null);
70
+ DaroMModule.showRewardedAd(
71
+ this.requestId,
72
+ this.adUnitId,
73
+ customData ?? null
74
+ );
63
75
  }
64
76
 
65
77
  addAdEventListener<T extends AdEventType | RewardedAdEventType>(
@@ -67,9 +79,9 @@ export class RewardedAd {
67
79
  listener: (info: RewardedAdEventPayloadMap[T]) => void
68
80
  ): () => void {
69
81
  const nativeEvent = NATIVE_EVENT_BY_TYPE[type];
70
- const adUnitId = this.adUnitId;
82
+ const requestId = this.requestId;
71
83
  return this.eventEmitter.addEventListener(nativeEvent, (payload: any) => {
72
- if (payload?.adUnitId !== undefined && payload.adUnitId !== adUnitId) {
84
+ if (payload?.requestId !== requestId) {
73
85
  return;
74
86
  }
75
87
  listener(payload);
@@ -82,24 +94,49 @@ export class RewardedAd {
82
94
 
83
95
  // ---- Deprecated static API (backward compatibility) ----
84
96
 
97
+ private static _getLegacyRequestId(adUnitId: string): number {
98
+ let requestId = RewardedAd._legacyRequestIds.get(adUnitId);
99
+ if (requestId === undefined) {
100
+ requestId = RewardedAd._nextRequestId++;
101
+ RewardedAd._legacyRequestIds.set(adUnitId, requestId);
102
+ RewardedAd._legacyRequestIdSet.add(requestId);
103
+ }
104
+ return requestId;
105
+ }
106
+
107
+ private static _addLegacyEventListener<T>(
108
+ event: string,
109
+ listener: (info: T) => void
110
+ ): void {
111
+ addEventListener(event, (payload: any) => {
112
+ if (!RewardedAd._legacyRequestIdSet.has(payload?.requestId)) {
113
+ return;
114
+ }
115
+ listener(payload);
116
+ });
117
+ }
118
+
85
119
  /** @deprecated `RewardedAd.createForAdRequest(adUnitId)` 인스턴스의 `isAdReady()`를 사용하세요. */
86
120
  static isAdReady(adUnitId: string): Promise<boolean> {
87
- return DaroMModule.isRewardedAdReady(adUnitId);
121
+ const requestId = RewardedAd._getLegacyRequestId(adUnitId);
122
+ return DaroMModule.isRewardedAdReady(requestId, adUnitId);
88
123
  }
89
124
 
90
125
  /** @deprecated `RewardedAd.createForAdRequest(adUnitId)` 인스턴스의 `load()`를 사용하세요. */
91
126
  static loadAd(adUnitId: string): void {
92
- DaroMModule.loadRewardedAd(adUnitId);
127
+ const requestId = RewardedAd._getLegacyRequestId(adUnitId);
128
+ DaroMModule.loadRewardedAd(requestId, adUnitId);
93
129
  }
94
130
 
95
131
  /** @deprecated `RewardedAd.createForAdRequest(adUnitId)` 인스턴스의 `show()`를 사용하세요. */
96
132
  static showAd(adUnitId: string, customData?: string | null): void {
97
- DaroMModule.showRewardedAd(adUnitId, customData ?? null);
133
+ const requestId = RewardedAd._getLegacyRequestId(adUnitId);
134
+ DaroMModule.showRewardedAd(requestId, adUnitId, customData ?? null);
98
135
  }
99
136
 
100
137
  /** @deprecated `addAdEventListener(AdEventType.LOADED, ...)`를 인스턴스에서 사용하세요. */
101
138
  static addAdLoadedEventListener(listener: (adInfo: AdInfo) => void): void {
102
- addEventListener(ON_REWARDED_AD_LOADED_EVENT, listener);
139
+ RewardedAd._addLegacyEventListener(ON_REWARDED_AD_LOADED_EVENT, listener);
103
140
  }
104
141
 
105
142
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -111,7 +148,10 @@ export class RewardedAd {
111
148
  static addAdLoadFailedEventListener(
112
149
  listener: (errorInfo: AdLoadFailedInfo) => void
113
150
  ): void {
114
- addEventListener(ON_REWARDED_AD_LOAD_FAILED_EVENT, listener);
151
+ RewardedAd._addLegacyEventListener(
152
+ ON_REWARDED_AD_LOAD_FAILED_EVENT,
153
+ listener
154
+ );
115
155
  }
116
156
 
117
157
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -121,7 +161,7 @@ export class RewardedAd {
121
161
 
122
162
  /** @deprecated `addAdEventListener(AdEventType.CLICKED, ...)`를 인스턴스에서 사용하세요. */
123
163
  static addAdClickedEventListener(listener: (adInfo: AdInfo) => void): void {
124
- addEventListener(ON_REWARDED_AD_CLICKED_EVENT, listener);
164
+ RewardedAd._addLegacyEventListener(ON_REWARDED_AD_CLICKED_EVENT, listener);
125
165
  }
126
166
 
127
167
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -131,7 +171,10 @@ export class RewardedAd {
131
171
 
132
172
  /** @deprecated `addAdEventListener(AdEventType.DISPLAYED, ...)`를 인스턴스에서 사용하세요. */
133
173
  static addAdDisplayedEventListener(listener: (adInfo: AdInfo) => void): void {
134
- addEventListener(ON_REWARDED_AD_DISPLAYED_EVENT, listener);
174
+ RewardedAd._addLegacyEventListener(
175
+ ON_REWARDED_AD_DISPLAYED_EVENT,
176
+ listener
177
+ );
135
178
  }
136
179
 
137
180
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -143,7 +186,10 @@ export class RewardedAd {
143
186
  static addAdFailedToDisplayEventListener(
144
187
  listener: (errorInfo: AdDisplayFailedInfo) => void
145
188
  ): void {
146
- addEventListener(ON_REWARDED_AD_FAILED_TO_DISPLAY_EVENT, listener);
189
+ RewardedAd._addLegacyEventListener(
190
+ ON_REWARDED_AD_FAILED_TO_DISPLAY_EVENT,
191
+ listener
192
+ );
147
193
  }
148
194
 
149
195
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -153,7 +199,7 @@ export class RewardedAd {
153
199
 
154
200
  /** @deprecated `addAdEventListener(AdEventType.HIDDEN, ...)`를 인스턴스에서 사용하세요. */
155
201
  static addAdHiddenEventListener(listener: (adInfo: AdInfo) => void): void {
156
- addEventListener(ON_REWARDED_AD_HIDDEN_EVENT, listener);
202
+ RewardedAd._addLegacyEventListener(ON_REWARDED_AD_HIDDEN_EVENT, listener);
157
203
  }
158
204
 
159
205
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -165,7 +211,10 @@ export class RewardedAd {
165
211
  static addAdImpressionRecordedListener(
166
212
  listener: (adInfo: AdInfo) => void
167
213
  ): void {
168
- addEventListener(ON_REWARDED_AD_IMPRESSION_RECORDED, listener);
214
+ RewardedAd._addLegacyEventListener(
215
+ ON_REWARDED_AD_IMPRESSION_RECORDED,
216
+ listener
217
+ );
169
218
  }
170
219
 
171
220
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
@@ -177,7 +226,10 @@ export class RewardedAd {
177
226
  static addAdReceivedRewardEventListener(
178
227
  listener: (adInfo: AdRewardInfo) => void
179
228
  ): void {
180
- addEventListener(ON_REWARDED_AD_RECEIVED_REWARD_EVENT, listener);
229
+ RewardedAd._addLegacyEventListener(
230
+ ON_REWARDED_AD_RECEIVED_REWARD_EVENT,
231
+ listener
232
+ );
181
233
  }
182
234
 
183
235
  /** @deprecated 인스턴스의 `addAdEventListener` disposer를 사용하세요. */
package/src/index.tsx CHANGED
@@ -16,7 +16,7 @@ export {
16
16
  } from './nativeAd/NativeAdViewComponents';
17
17
 
18
18
  const LINKING_ERROR =
19
- `The package 'react-native-daro-m' doesn't seem to be linked. Make sure: \n\n` +
19
+ `The native module 'DaroMModule' doesn't seem to be linked. Make sure: \n\n` +
20
20
  Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
21
21
  '- You rebuilt the app after installing the package\n' +
22
22
  '- You are not using Expo Go\n';
@@ -1,9 +1,32 @@
1
- import { forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useRef, useState } from 'react';
2
- import { findNodeHandle, NativeModules, requireNativeComponent, UIManager, View, type ViewProps } from 'react-native';
1
+ import {
2
+ forwardRef,
3
+ useCallback,
4
+ useContext,
5
+ useEffect,
6
+ useImperativeHandle,
7
+ useRef,
8
+ useState,
9
+ } from 'react';
10
+ import {
11
+ findNodeHandle,
12
+ NativeModules,
13
+ requireNativeComponent,
14
+ UIManager,
15
+ View,
16
+ type ViewProps,
17
+ } from 'react-native';
3
18
  import type { AdNativeEvent } from '../types/AdEvent';
4
19
  import type { AdInfo, AdLoadFailedInfo } from '../types/AdInfo';
5
- import type { NativeAdViewHandler, NativeAdViewProps } from '../types/NativeAdViewProps';
6
- import { NativeAdViewContext, NativeAdViewProvider, type NativeAdViewContextType, type NativeAdViewType } from './NativeAdViewProvider';
20
+ import type {
21
+ NativeAdViewHandler,
22
+ NativeAdViewProps,
23
+ } from '../types/NativeAdViewProps';
24
+ import {
25
+ NativeAdViewContext,
26
+ NativeAdViewProvider,
27
+ type NativeAdViewContextType,
28
+ type NativeAdViewType,
29
+ } from './NativeAdViewProvider';
7
30
 
8
31
  const { DaroMModule } = NativeModules;
9
32
 
@@ -15,9 +38,14 @@ type NativeAdViewNativeEvents = {
15
38
  };
16
39
 
17
40
  const ComponentName = 'DaroMNativeAdView';
18
- const NativeAdViewComponent = requireNativeComponent<NativeAdViewProps & ViewProps & NativeAdViewNativeEvents>(ComponentName);
19
-
20
- export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(function NativeAdView(props, ref) {
41
+ const NativeAdViewComponent = requireNativeComponent<
42
+ NativeAdViewProps & ViewProps & NativeAdViewNativeEvents
43
+ >(ComponentName);
44
+
45
+ export const NativeAdView = forwardRef<
46
+ NativeAdViewHandler,
47
+ NativeAdViewProps & ViewProps
48
+ >(function NativeAdView(props, ref) {
21
49
  const [isInitialized, setIsInitialized] = useState<boolean>(false);
22
50
 
23
51
  useEffect(() => {
@@ -25,7 +53,9 @@ export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps &
25
53
  const result = await DaroMModule.isInitialized();
26
54
  setIsInitialized(result);
27
55
  if (!result) {
28
- console.warn('NativeAdView is mounted before the initialization of the DaroM React Native module.');
56
+ console.warn(
57
+ 'NativeAdView is mounted before the initialization of the DaroM React Native module.'
58
+ );
29
59
  }
30
60
  };
31
61
 
@@ -41,26 +71,47 @@ export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps &
41
71
  <NativeAdViewProvider>
42
72
  <NativeAdViewImpl {...props} ref={ref} />
43
73
  </NativeAdViewProvider>
44
- );
74
+ );
45
75
  });
46
76
 
47
- const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(function NativeAdViewImpl(
48
- { adUnitId, onAdLoaded, onAdLoadFailed, onAdClicked, onAdImpressionRecorded, children, style, loadOnMount = true, ...otherProps },
77
+ const NativeAdViewImpl = forwardRef<
78
+ NativeAdViewHandler,
79
+ NativeAdViewProps & ViewProps
80
+ >(function NativeAdViewImpl(
81
+ {
82
+ adUnitId,
83
+ onAdLoaded,
84
+ onAdLoadFailed,
85
+ onAdClicked,
86
+ onAdImpressionRecorded,
87
+ children,
88
+ style,
89
+ loadOnMount = true,
90
+ ...otherProps
91
+ },
49
92
  ref
50
93
  ) {
51
94
  // Context provides functions to manage native ad and native ad view state
52
- const { setNativeAdView } = useContext(NativeAdViewContext) as NativeAdViewContextType;
95
+ const { setNativeAdView } = useContext(
96
+ NativeAdViewContext
97
+ ) as NativeAdViewContextType;
53
98
 
54
99
  const nativeAdViewRef = useRef<NativeAdViewType | null>(null);
55
100
 
56
101
  // Load a new ad
57
102
  const loadAd = useCallback(() => {
58
103
  if (nativeAdViewRef.current) {
104
+ const nodeHandle = findNodeHandle(nativeAdViewRef.current);
105
+
106
+ if (typeof nodeHandle !== 'number') {
107
+ return;
108
+ }
109
+
59
110
  UIManager.dispatchViewManagerCommand(
60
- findNodeHandle(nativeAdViewRef.current),
111
+ nodeHandle,
61
112
  // @ts-ignore: Issue in RN ts defs
62
113
  UIManager.getViewManagerConfig(ComponentName).Commands.loadAd,
63
- [],
114
+ []
64
115
  );
65
116
  }
66
117
  }, []);
@@ -1,6 +1,20 @@
1
1
  import * as React from 'react';
2
- import { useCallback, useContext, useEffect, useMemo, useRef } from 'react';
3
- import type { ImageProps, StyleProp, TextProps, TextStyle, ImageStyle, ViewProps } from 'react-native';
2
+ import {
3
+ type ComponentRef,
4
+ useCallback,
5
+ useContext,
6
+ useEffect,
7
+ useMemo,
8
+ useRef,
9
+ } from 'react';
10
+ import type {
11
+ ImageProps,
12
+ StyleProp,
13
+ TextProps,
14
+ TextStyle,
15
+ ImageStyle,
16
+ ViewProps,
17
+ } from 'react-native';
4
18
  import { findNodeHandle, Image, Platform, Text, View } from 'react-native';
5
19
  import { NativeAdViewContext } from './NativeAdViewProvider';
6
20
 
@@ -62,32 +76,37 @@ const useStyleProps = (style: StyleProp<TextStyle>): StyleProps => {
62
76
  fontWeight: styleObj.fontWeight as string,
63
77
  fontFamily: styleObj.fontFamily as string,
64
78
  color: styleObj.color as string,
65
-
79
+
66
80
  // 2. 배경색
67
81
  backgroundColor: styleObj.backgroundColor as string,
68
-
82
+
69
83
  // 3. 정렬
70
- textAlign: styleObj.textAlign as 'auto' | 'left' | 'right' | 'center' | 'justify',
71
-
84
+ textAlign: styleObj.textAlign as
85
+ | 'auto'
86
+ | 'left'
87
+ | 'right'
88
+ | 'center'
89
+ | 'justify',
90
+
72
91
  // 6. 투명도
73
92
  opacity: styleObj.opacity as number,
74
-
93
+
75
94
  // 7. 숨김
76
95
  display: styleObj.display as 'none' | 'flex',
77
-
96
+
78
97
  // 10. 모서리 둥글게
79
98
  borderRadius: styleObj.borderRadius as number,
80
-
99
+
81
100
  // 11. 테두리
82
101
  borderWidth: styleObj.borderWidth as number,
83
102
  borderColor: styleObj.borderColor as string,
84
-
103
+
85
104
  // 12. 그림자
86
105
  shadowColor: styleObj.shadowColor as string,
87
106
  shadowOffset: styleObj.shadowOffset as { width: number; height: number },
88
107
  shadowOpacity: styleObj.shadowOpacity as number,
89
108
  shadowRadius: styleObj.shadowRadius as number,
90
-
109
+
91
110
  // 13. 여백
92
111
  padding: styleObj.padding as number,
93
112
  margin: styleObj.margin as number,
@@ -99,21 +118,21 @@ const useStyleProps = (style: StyleProp<TextStyle>): StyleProps => {
99
118
  marginRight: styleObj.marginRight as number,
100
119
  marginBottom: styleObj.marginBottom as number,
101
120
  marginLeft: styleObj.marginLeft as number,
102
-
121
+
103
122
  // 14. 위치
104
123
  position: styleObj.position as 'absolute' | 'relative',
105
124
  top: styleObj.top as number,
106
125
  right: styleObj.right as number,
107
126
  bottom: styleObj.bottom as number,
108
127
  left: styleObj.left as number,
109
-
128
+
110
129
  // 15. 크기
111
130
  width: styleObj.width as number,
112
131
  height: styleObj.height as number,
113
-
132
+
114
133
  // 16. 변환
115
134
  transform: styleObj.transform as any[],
116
-
135
+
117
136
  // 17. 기타
118
137
  zIndex: styleObj.zIndex as number,
119
138
  overflow: styleObj.overflow as 'visible' | 'hidden' | 'scroll',
@@ -155,7 +174,12 @@ const useImageStyleProps = (style: StyleProp<ImageStyle>): ImageStyleProps => {
155
174
  height: styleObj.height as number,
156
175
 
157
176
  // Image 전용 스타일 속성
158
- resizeMode: styleObj.resizeMode as 'cover' | 'contain' | 'stretch' | 'repeat' | 'center',
177
+ resizeMode: styleObj.resizeMode as
178
+ | 'cover'
179
+ | 'contain'
180
+ | 'stretch'
181
+ | 'repeat'
182
+ | 'center',
159
183
  tintColor: styleObj.tintColor as string,
160
184
  overlayColor: styleObj.overlayColor as string,
161
185
  aspectRatio: styleObj.aspectRatio as number,
@@ -164,7 +188,11 @@ const useImageStyleProps = (style: StyleProp<ImageStyle>): ImageStyleProps => {
164
188
  };
165
189
 
166
190
  // 네이티브 뷰 속성 설정 커스텀 훅
167
- const useNativeAdViewProps = (ref: React.RefObject<any>, nativePropKey: string, styleProps?: StyleProps) => {
191
+ const useNativeAdViewProps = (
192
+ ref: React.RefObject<any>,
193
+ nativePropKey: string,
194
+ styleProps?: StyleProps
195
+ ) => {
168
196
  const { nativeAdView } = useContext(NativeAdViewContext);
169
197
 
170
198
  const setNativeProps = useCallback(() => {
@@ -172,11 +200,11 @@ const useNativeAdViewProps = (ref: React.RefObject<any>, nativePropKey: string,
172
200
  const props: any = {
173
201
  [nativePropKey]: findNodeHandle(ref.current),
174
202
  };
175
-
203
+
176
204
  if (styleProps) {
177
205
  props[`${nativePropKey}StyleProps`] = styleProps;
178
206
  }
179
-
207
+
180
208
  nativeAdView?.setNativeProps(props);
181
209
  }, [nativeAdView, ref, nativePropKey, styleProps]);
182
210
 
@@ -188,9 +216,9 @@ const useNativeAdViewProps = (ref: React.RefObject<any>, nativePropKey: string,
188
216
  // 공통 Text 컴포넌트
189
217
  const AdTextView = (props: TextProps & { nativePropKey: string }) => {
190
218
  const { nativePropKey, ...restProps } = props;
191
- const textRef = useRef<Text | null>(null);
219
+ const textRef = useRef<ComponentRef<typeof Text> | null>(null);
192
220
  const styleProps = useStyleProps(props.style);
193
-
221
+
194
222
  useNativeAdViewProps(textRef, nativePropKey, styleProps);
195
223
 
196
224
  return <Text {...restProps} ref={textRef} />;
@@ -205,11 +233,11 @@ export const BodyView = (props: TextProps) => {
205
233
  };
206
234
 
207
235
  export const CallToActionView = (props: TextProps) => {
208
- const callToActionRef = useRef<Text | null>(null);
236
+ const callToActionRef = useRef<ComponentRef<typeof Text> | null>(null);
209
237
  const styleProps = useStyleProps(props.style);
210
-
238
+
211
239
  useNativeAdViewProps(callToActionRef, 'callToActionView', styleProps);
212
-
240
+
213
241
  // TouchableOpacity disables clicking on certain Android devices.
214
242
  if (Platform.OS === 'android') {
215
243
  return <Text {...props} ref={callToActionRef} />;
@@ -223,7 +251,7 @@ export const CallToActionView = (props: TextProps) => {
223
251
  };
224
252
 
225
253
  export const IconView = (props: Omit<ImageProps, 'source'>) => {
226
- const imageRef = useRef<Image | null>(null);
254
+ const imageRef = useRef<ComponentRef<typeof Image> | null>(null);
227
255
  const iconViewStyleProps = useImageStyleProps(props.style);
228
256
  useNativeAdViewProps(imageRef, 'iconView', iconViewStyleProps);
229
257
 
@@ -231,9 +259,8 @@ export const IconView = (props: Omit<ImageProps, 'source'>) => {
231
259
  };
232
260
 
233
261
  export const MediaView = (props: ViewProps) => {
234
- const viewRef = useRef<View | null>(null);
262
+ const viewRef = useRef<ComponentRef<typeof View> | null>(null);
235
263
  useNativeAdViewProps(viewRef, 'mediaView');
236
264
 
237
265
  return <View {...props} ref={viewRef} />;
238
266
  };
239
-
@@ -4,21 +4,27 @@ import { createContext, useState } from 'react';
4
4
  import type { NativeMethods } from 'react-native';
5
5
  import type { NativeAdViewProps } from '../types/NativeAdViewProps';
6
6
 
7
- export type NativeAdViewType = React.Component<NativeAdViewProps> & NativeMethods;
7
+ export type NativeAdViewType = React.Component<NativeAdViewProps> &
8
+ NativeMethods;
8
9
 
9
10
  export type NativeAdViewContextType = {
10
11
  nativeAdView: NativeAdViewType | null;
11
- setNativeAdView: React.Dispatch<React.SetStateAction<NativeAdViewType | null>>;
12
+ setNativeAdView: React.Dispatch<
13
+ React.SetStateAction<NativeAdViewType | null>
14
+ >;
12
15
  };
13
16
 
14
-
15
17
  export const NativeAdViewContext = createContext<NativeAdViewContextType>({
16
18
  nativeAdView: null,
17
- setNativeAdView: () => { },
19
+ setNativeAdView: () => {},
18
20
  });
19
21
 
20
- export const NativeAdViewProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
21
- const [nativeAdView, setNativeAdView] = useState<NativeAdViewType | null>(null);
22
+ export const NativeAdViewProvider: React.FC<{ children: ReactNode }> = ({
23
+ children,
24
+ }) => {
25
+ const [nativeAdView, setNativeAdView] = useState<NativeAdViewType | null>(
26
+ null
27
+ );
22
28
 
23
29
  const providerValue = React.useMemo(
24
30
  () => ({
@@ -28,5 +34,9 @@ export const NativeAdViewProvider: React.FC<{ children: ReactNode }> = ({ childr
28
34
  [nativeAdView]
29
35
  );
30
36
 
31
- return <NativeAdViewContext.Provider value={providerValue}>{children}</NativeAdViewContext.Provider>;
37
+ return (
38
+ <NativeAdViewContext.Provider value={providerValue}>
39
+ {children}
40
+ </NativeAdViewContext.Provider>
41
+ );
32
42
  };
@@ -1,16 +1,16 @@
1
- import type { AdFormat } from "../AdBannerView";
2
- import type { AdProps } from "./AdProps";
1
+ import type { AdFormat } from '../AdBannerView';
2
+ import type { AdProps } from './AdProps';
3
3
 
4
4
  export type AdBannerViewHandler = {
5
- /**
6
- * If the {@link loadOnMount} attribute is set to false, you can call this API to start loading ads in this AdView.
7
- */
8
- loadAd(): void;
5
+ /**
6
+ * If the {@link loadOnMount} attribute is set to false, you can call this API to start loading ads in this AdView.
7
+ */
8
+ loadAd(): void;
9
9
  };
10
10
 
11
11
  export type AdBannerViewProps = AdProps & {
12
- color?: string;
13
- adFormat: AdFormat;
14
- loadOnMount?: boolean;
15
- isVisible?: boolean;
16
- }
12
+ color?: string;
13
+ adFormat: AdFormat;
14
+ loadOnMount?: boolean;
15
+ isVisible?: boolean;
16
+ };
@@ -2,36 +2,36 @@ import type { ErrorCode } from '../ErrorCode';
2
2
 
3
3
  // Represents an ad
4
4
  export type AdInfo = {
5
- // The ad unit ID for which this ad was loaded.
6
- adUnitId: string;
7
- // The total latency in milliseconds for this waterfall to finish processing.
8
- latencyMillis: number;
5
+ // The ad unit ID for which this ad was loaded.
6
+ adUnitId: string;
7
+ // The total latency in milliseconds for this waterfall to finish processing.
8
+ latencyMillis: number;
9
9
  };
10
10
 
11
11
  // Encapsulates various data for MAX load errors.
12
12
  export type AdLoadFailedInfo = {
13
- // The ad unit ID for which this ad was loaded.
14
- adUnitId: string;
13
+ // The ad unit ID for which this ad was loaded.
14
+ adUnitId: string;
15
15
 
16
- // The error code for the error.
17
- code: ErrorCode;
16
+ // The error code for the error.
17
+ code: ErrorCode;
18
18
 
19
- message: string;
19
+ message: string;
20
20
 
21
- // The total latency in milliseconds for this waterfall to finish processing.
22
- latencyMillis: number;
21
+ // The total latency in milliseconds for this waterfall to finish processing.
22
+ latencyMillis: number;
23
23
  };
24
24
 
25
25
  // Encapsulates various data for MAX display errors.
26
26
  export type AdDisplayFailedInfo = {
27
- message: string | null;
27
+ message: string | null;
28
28
  };
29
29
 
30
30
  // Represents a reward given to the user.
31
31
  export type AdRewardInfo = {
32
- // The reward label.
33
- rewardLabel?: string | null;
32
+ // The reward label.
33
+ rewardLabel?: string | null;
34
34
 
35
- // The rewarded amount.
36
- rewardAmount: string;
37
- };
35
+ // The rewarded amount.
36
+ rewardAmount: string;
37
+ };
@@ -1,18 +1,17 @@
1
- import type { AdLoadFailedInfo } from "./AdInfo";
1
+ import type { AdLoadFailedInfo } from './AdInfo';
2
2
 
3
- import type { AdInfo } from "./AdInfo";
3
+ import type { AdInfo } from './AdInfo';
4
4
 
5
5
  export type AdProps = {
6
+ adUnitId: string;
6
7
 
7
- adUnitId: string;
8
+ placement?: string | null;
8
9
 
9
- placement?: string | null;
10
+ onAdLoaded?: (adInfo: AdInfo) => void;
10
11
 
11
- onAdLoaded?: (adInfo: AdInfo) => void;
12
+ onAdLoadFailed?: (error: AdLoadFailedInfo) => void;
12
13
 
13
- onAdLoadFailed?: (error: AdLoadFailedInfo) => void;
14
+ onAdClicked?: (adInfo: AdInfo) => void;
14
15
 
15
- onAdClicked?: (adInfo: AdInfo) => void;
16
-
17
- onAdImpressionRecorded?: (adInfo: AdInfo) => void;
16
+ onAdImpressionRecorded?: (adInfo: AdInfo) => void;
18
17
  };
@@ -1,8 +1,5 @@
1
-
2
1
  export type DaroMMobileAds = {
3
-
4
- isInitialized: () => Promise<boolean>;
5
- initialize: (sdkKey: string) => Promise<void>;
6
- setUserId: (userId: String) => Promise<void>;
7
-
2
+ isInitialized: () => Promise<boolean>;
3
+ initialize: (sdkKey: string) => Promise<void>;
4
+ setUserId: (userId: String) => Promise<void>;
8
5
  };