react-native-daro 2.0.7 → 2.0.9-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +2 -2
  2. package/android/build.gradle +3 -1
  3. package/android/src/main/java/com/daro/reactnative/DaroRNAdBannerViewManager.kt +8 -3
  4. package/android/src/main/java/com/daro/reactnative/DaroRNAdNativeViewManager.kt +8 -3
  5. package/android/src/main/java/com/daro/reactnative/DaroRNModule.kt +76 -34
  6. package/android/src/main/java/com/daro/reactnative/event/DaroRNEvent.kt +8 -0
  7. package/android/src/main/java/com/daro/reactnative/impl/DaroRNInterstitialModuleImpl.kt +13 -13
  8. package/android/src/main/java/com/daro/reactnative/impl/DaroRNLightPopupModuleImpl.kt +12 -12
  9. package/android/src/main/java/com/daro/reactnative/impl/DaroRNPreloadModuleImpl.kt +77 -0
  10. package/android/src/main/java/com/daro/reactnative/impl/DaroRNRewardedAdModuleImpl.kt +14 -14
  11. package/android/src/main/java/com/daro/reactnative/preload/DaroRNPreloadRegistry.kt +57 -0
  12. package/android/src/main/java/com/daro/reactnative/util/AdInfoUtil.kt +27 -16
  13. package/android/src/main/java/com/daro/reactnative/view/DaroMediaView.kt +3 -0
  14. package/android/src/main/java/com/daro/reactnative/view/DaroRNAdBannerViewContainer.kt +36 -15
  15. package/android/src/main/java/com/daro/reactnative/view/DaroRNAdNativeViewContainer.kt +36 -15
  16. package/android/src/oldarch/java/com/daro/reactnative/DaroRNModuleSpec.kt +28 -14
  17. package/android/src/test/java/com/daro/reactnative/preload/DaroRNPreloadRegistryTest.kt +65 -0
  18. package/android/src/test/java/com/daro/reactnative/view/DaroMediaViewTest.kt +45 -0
  19. package/android/src/test/java/com/daro/reactnative/view/DaroRNPreloadFirstLoadTest.kt +160 -0
  20. package/ios/DaroRNModule+AppOpen.swift +9 -9
  21. package/ios/DaroRNModule+Interstitial.swift +9 -9
  22. package/ios/DaroRNModule+LightPopup.swift +13 -13
  23. package/ios/DaroRNModule+Preload.swift +122 -0
  24. package/ios/DaroRNModule+Rewarded.swift +14 -14
  25. package/ios/DaroRNModule.mm +20 -14
  26. package/ios/DaroRNModule.swift +6 -1
  27. package/ios/Fabric/DaroRNAdBannerComponentView.mm +12 -7
  28. package/ios/Fabric/DaroRNNativeAdComponentView.mm +12 -7
  29. package/ios/Paper/DaroRNAdBannerViewManager.m +2 -1
  30. package/ios/Paper/DaroRNNativeAdViewManager.m +2 -1
  31. package/ios/Shared/DaroRNBannerAdView.swift +23 -9
  32. package/ios/Shared/DaroRNNativeAdView.swift +77 -46
  33. package/ios/Shared/DaroRNPreloadRegistry.swift +54 -0
  34. package/lib/commonjs/AdBannerView.js +4 -2
  35. package/lib/commonjs/AdBannerView.js.map +1 -1
  36. package/lib/commonjs/AdPreload.js +105 -0
  37. package/lib/commonjs/AdPreload.js.map +1 -0
  38. package/lib/commonjs/AppOpenAd.js +22 -22
  39. package/lib/commonjs/AppOpenAd.js.map +1 -1
  40. package/lib/commonjs/DaroRNAdBannerViewNativeComponent.ts +5 -3
  41. package/lib/commonjs/DaroRNNativeAdViewNativeComponent.ts +5 -3
  42. package/lib/commonjs/InterstitialAd.js +24 -24
  43. package/lib/commonjs/InterstitialAd.js.map +1 -1
  44. package/lib/commonjs/LightPopupAd.js +27 -27
  45. package/lib/commonjs/LightPopupAd.js.map +1 -1
  46. package/lib/commonjs/NativeDaroModule.js.map +1 -1
  47. package/lib/commonjs/RewardedAd.js +22 -22
  48. package/lib/commonjs/RewardedAd.js.map +1 -1
  49. package/lib/commonjs/hooks/useAdPreload.js +61 -0
  50. package/lib/commonjs/hooks/useAdPreload.js.map +1 -0
  51. package/lib/commonjs/hooks/useInterstitialAd.js +6 -6
  52. package/lib/commonjs/hooks/useInterstitialAd.js.map +1 -1
  53. package/lib/commonjs/hooks/useLightPopupAd.js +5 -5
  54. package/lib/commonjs/hooks/useLightPopupAd.js.map +1 -1
  55. package/lib/commonjs/hooks/useRewardedAd.js +6 -6
  56. package/lib/commonjs/hooks/useRewardedAd.js.map +1 -1
  57. package/lib/commonjs/index.js +37 -0
  58. package/lib/commonjs/index.js.map +1 -1
  59. package/lib/commonjs/nativeAd/NativeAdView.js +4 -2
  60. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  61. package/lib/commonjs/types/NativeAdViewProps.js.map +1 -1
  62. package/lib/module/AdBannerView.js +4 -2
  63. package/lib/module/AdBannerView.js.map +1 -1
  64. package/lib/module/AdPreload.js +98 -0
  65. package/lib/module/AdPreload.js.map +1 -0
  66. package/lib/module/AppOpenAd.js +22 -22
  67. package/lib/module/AppOpenAd.js.map +1 -1
  68. package/lib/module/DaroRNAdBannerViewNativeComponent.ts +5 -3
  69. package/lib/module/DaroRNNativeAdViewNativeComponent.ts +5 -3
  70. package/lib/module/InterstitialAd.js +24 -24
  71. package/lib/module/InterstitialAd.js.map +1 -1
  72. package/lib/module/LightPopupAd.js +27 -27
  73. package/lib/module/LightPopupAd.js.map +1 -1
  74. package/lib/module/NativeDaroModule.js.map +1 -1
  75. package/lib/module/RewardedAd.js +22 -22
  76. package/lib/module/RewardedAd.js.map +1 -1
  77. package/lib/module/hooks/useAdPreload.js +56 -0
  78. package/lib/module/hooks/useAdPreload.js.map +1 -0
  79. package/lib/module/hooks/useInterstitialAd.js +6 -6
  80. package/lib/module/hooks/useInterstitialAd.js.map +1 -1
  81. package/lib/module/hooks/useLightPopupAd.js +5 -5
  82. package/lib/module/hooks/useLightPopupAd.js.map +1 -1
  83. package/lib/module/hooks/useRewardedAd.js +6 -6
  84. package/lib/module/hooks/useRewardedAd.js.map +1 -1
  85. package/lib/module/index.js +2 -0
  86. package/lib/module/index.js.map +1 -1
  87. package/lib/module/nativeAd/NativeAdView.js +4 -2
  88. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  89. package/lib/module/types/NativeAdViewProps.js.map +1 -1
  90. package/lib/typescript/commonjs/src/AdBannerView.d.ts +1 -0
  91. package/lib/typescript/commonjs/src/AdBannerView.d.ts.map +1 -1
  92. package/lib/typescript/commonjs/src/AdPreload.d.ts +62 -0
  93. package/lib/typescript/commonjs/src/AdPreload.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/src/AppOpenAd.d.ts +8 -8
  95. package/lib/typescript/commonjs/src/AppOpenAd.d.ts.map +1 -1
  96. package/lib/typescript/commonjs/src/DaroRNAdBannerViewNativeComponent.d.ts +4 -3
  97. package/lib/typescript/commonjs/src/DaroRNAdBannerViewNativeComponent.d.ts.map +1 -1
  98. package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts +4 -3
  99. package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
  100. package/lib/typescript/commonjs/src/InterstitialAd.d.ts +8 -8
  101. package/lib/typescript/commonjs/src/InterstitialAd.d.ts.map +1 -1
  102. package/lib/typescript/commonjs/src/LightPopupAd.d.ts +9 -9
  103. package/lib/typescript/commonjs/src/LightPopupAd.d.ts.map +1 -1
  104. package/lib/typescript/commonjs/src/NativeDaroModule.d.ts +19 -14
  105. package/lib/typescript/commonjs/src/NativeDaroModule.d.ts.map +1 -1
  106. package/lib/typescript/commonjs/src/RewardedAd.d.ts +8 -8
  107. package/lib/typescript/commonjs/src/RewardedAd.d.ts.map +1 -1
  108. package/lib/typescript/commonjs/src/hooks/useAdPreload.d.ts +19 -0
  109. package/lib/typescript/commonjs/src/hooks/useAdPreload.d.ts.map +1 -0
  110. package/lib/typescript/commonjs/src/hooks/useInterstitialAd.d.ts +1 -1
  111. package/lib/typescript/commonjs/src/hooks/useInterstitialAd.d.ts.map +1 -1
  112. package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts +1 -1
  113. package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts.map +1 -1
  114. package/lib/typescript/commonjs/src/hooks/useRewardedAd.d.ts +1 -1
  115. package/lib/typescript/commonjs/src/hooks/useRewardedAd.d.ts.map +1 -1
  116. package/lib/typescript/commonjs/src/index.d.ts +4 -0
  117. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  118. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts +1 -0
  119. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts.map +1 -1
  120. package/lib/typescript/commonjs/src/types/AdBannerViewProps.d.ts +6 -0
  121. package/lib/typescript/commonjs/src/types/AdBannerViewProps.d.ts.map +1 -1
  122. package/lib/typescript/commonjs/src/types/AdInfo.d.ts +2 -2
  123. package/lib/typescript/commonjs/src/types/AdInfo.d.ts.map +1 -1
  124. package/lib/typescript/commonjs/src/types/AdProps.d.ts +1 -1
  125. package/lib/typescript/commonjs/src/types/AdProps.d.ts.map +1 -1
  126. package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts +6 -0
  127. package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts.map +1 -1
  128. package/lib/typescript/module/src/AdBannerView.d.ts +1 -0
  129. package/lib/typescript/module/src/AdBannerView.d.ts.map +1 -1
  130. package/lib/typescript/module/src/AdPreload.d.ts +62 -0
  131. package/lib/typescript/module/src/AdPreload.d.ts.map +1 -0
  132. package/lib/typescript/module/src/AppOpenAd.d.ts +8 -8
  133. package/lib/typescript/module/src/AppOpenAd.d.ts.map +1 -1
  134. package/lib/typescript/module/src/DaroRNAdBannerViewNativeComponent.d.ts +4 -3
  135. package/lib/typescript/module/src/DaroRNAdBannerViewNativeComponent.d.ts.map +1 -1
  136. package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts +4 -3
  137. package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
  138. package/lib/typescript/module/src/InterstitialAd.d.ts +8 -8
  139. package/lib/typescript/module/src/InterstitialAd.d.ts.map +1 -1
  140. package/lib/typescript/module/src/LightPopupAd.d.ts +9 -9
  141. package/lib/typescript/module/src/LightPopupAd.d.ts.map +1 -1
  142. package/lib/typescript/module/src/NativeDaroModule.d.ts +19 -14
  143. package/lib/typescript/module/src/NativeDaroModule.d.ts.map +1 -1
  144. package/lib/typescript/module/src/RewardedAd.d.ts +8 -8
  145. package/lib/typescript/module/src/RewardedAd.d.ts.map +1 -1
  146. package/lib/typescript/module/src/hooks/useAdPreload.d.ts +19 -0
  147. package/lib/typescript/module/src/hooks/useAdPreload.d.ts.map +1 -0
  148. package/lib/typescript/module/src/hooks/useInterstitialAd.d.ts +1 -1
  149. package/lib/typescript/module/src/hooks/useInterstitialAd.d.ts.map +1 -1
  150. package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts +1 -1
  151. package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts.map +1 -1
  152. package/lib/typescript/module/src/hooks/useRewardedAd.d.ts +1 -1
  153. package/lib/typescript/module/src/hooks/useRewardedAd.d.ts.map +1 -1
  154. package/lib/typescript/module/src/index.d.ts +4 -0
  155. package/lib/typescript/module/src/index.d.ts.map +1 -1
  156. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts +1 -0
  157. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts.map +1 -1
  158. package/lib/typescript/module/src/types/AdBannerViewProps.d.ts +6 -0
  159. package/lib/typescript/module/src/types/AdBannerViewProps.d.ts.map +1 -1
  160. package/lib/typescript/module/src/types/AdInfo.d.ts +2 -2
  161. package/lib/typescript/module/src/types/AdInfo.d.ts.map +1 -1
  162. package/lib/typescript/module/src/types/AdProps.d.ts +1 -1
  163. package/lib/typescript/module/src/types/AdProps.d.ts.map +1 -1
  164. package/lib/typescript/module/src/types/NativeAdViewProps.d.ts +6 -0
  165. package/lib/typescript/module/src/types/NativeAdViewProps.d.ts.map +1 -1
  166. package/package.json +1 -1
  167. package/plugin/build/withAndroid.js +2 -2
  168. package/react-native-daro.podspec +1 -1
  169. package/src/AdBannerView.tsx +4 -2
  170. package/src/AdPreload.ts +141 -0
  171. package/src/AppOpenAd.ts +21 -21
  172. package/src/DaroRNAdBannerViewNativeComponent.ts +5 -3
  173. package/src/DaroRNNativeAdViewNativeComponent.ts +5 -3
  174. package/src/InterstitialAd.ts +23 -23
  175. package/src/LightPopupAd.ts +26 -26
  176. package/src/NativeDaroModule.ts +31 -14
  177. package/src/RewardedAd.ts +21 -21
  178. package/src/hooks/useAdPreload.ts +82 -0
  179. package/src/hooks/useInterstitialAd.ts +6 -6
  180. package/src/hooks/useLightPopupAd.ts +5 -5
  181. package/src/hooks/useRewardedAd.ts +6 -6
  182. package/src/index.tsx +16 -0
  183. package/src/nativeAd/NativeAdView.tsx +4 -2
  184. package/src/types/AdBannerViewProps.ts +6 -0
  185. package/src/types/AdInfo.ts +2 -2
  186. package/src/types/AdProps.ts +1 -1
  187. package/src/types/NativeAdViewProps.ts +6 -0
@@ -0,0 +1,65 @@
1
+ package com.daro.reactnative.preload
2
+
3
+ import org.junit.Assert.*
4
+ import org.junit.Test
5
+
6
+ class DaroRNPreloadRegistryTest {
7
+ private class Controller(var preloads: Int = 0, var destroyed: Int = 0)
8
+ private class Other
9
+
10
+ private val registry = DaroRNPreloadRegistry()
11
+
12
+ private fun entry(controller: Controller, unit: String = "unit", variant: String = "") =
13
+ DaroRNPreloadRegistry.Entry(unit, variant, controller, { it.preloads++ }, { it.destroyed++ })
14
+
15
+ @Test fun repeatedPreloadReusesTheStoredController() {
16
+ val controller = Controller()
17
+ var created = 0
18
+ repeat(2) { registry.preload("a") { created++; entry(controller) } }
19
+ assertEquals(1, created)
20
+ assertEquals(2, controller.preloads)
21
+ }
22
+
23
+ @Test fun takeHandsOverOnceAndLeavesCleanupToTheView() {
24
+ val controller = Controller()
25
+ registry.preload("a") { entry(controller) }
26
+ assertSame(controller, registry.take("a", "unit", "", Controller::class.java))
27
+ assertNull(registry.take("a", "unit", "", Controller::class.java))
28
+ registry.destroy("a")
29
+ registry.destroyAll()
30
+ assertEquals(0, controller.destroyed)
31
+ }
32
+
33
+ @Test fun mismatchedUnitVariantOrTypeIsDestroyedInsteadOfHandedOver() {
34
+ val unit = Controller()
35
+ val variant = Controller()
36
+ val type = Controller()
37
+ registry.preload("unit") { entry(unit) }
38
+ registry.preload("variant") { entry(variant, variant = "BANNER") }
39
+ registry.preload("type") { entry(type) }
40
+ assertNull(registry.take("unit", "other", "", Controller::class.java))
41
+ assertNull(registry.take("variant", "unit", "MREC", Controller::class.java))
42
+ assertNull(registry.take("type", "unit", "", Other::class.java))
43
+ assertEquals(listOf(1, 1, 1), listOf(unit.destroyed, variant.destroyed, type.destroyed))
44
+ }
45
+
46
+ @Test fun missingIdTakesNothing() {
47
+ assertNull(registry.take(null, "unit", "", Controller::class.java))
48
+ assertNull(registry.take("", "unit", "", Controller::class.java))
49
+ assertNull(registry.take("unknown", "unit", "", Controller::class.java))
50
+ }
51
+
52
+ @Test fun destroyReleasesUnusedEntriesOnceAndAllowsANewPreload() {
53
+ val first = Controller()
54
+ val second = Controller()
55
+ registry.preload("a") { entry(first) }
56
+ registry.destroy("a")
57
+ registry.destroy("a")
58
+ assertEquals(1, first.destroyed)
59
+ registry.preload("a") { entry(second) }
60
+ assertEquals(1, second.preloads)
61
+ registry.destroyAll()
62
+ registry.destroyAll()
63
+ assertEquals(1, second.destroyed)
64
+ }
65
+ }
@@ -0,0 +1,45 @@
1
+ package com.daro.reactnative.view
2
+
3
+ import android.app.Activity
4
+ import android.content.Context
5
+ import android.os.Looper
6
+ import android.view.View
7
+ import android.widget.FrameLayout
8
+ import org.junit.Assert.*
9
+ import org.junit.Test
10
+ import org.junit.runner.RunWith
11
+ import org.robolectric.Robolectric
12
+ import org.robolectric.RobolectricTestRunner
13
+ import org.robolectric.Shadows.shadowOf
14
+ import org.robolectric.annotation.Config
15
+
16
+ @RunWith(RobolectricTestRunner::class)
17
+ @Config(sdk = [28], manifest = Config.NONE)
18
+ class DaroMediaViewTest {
19
+ // ComposeView 처럼 window 없이 measure 하면 실패하는 미디어 자식.
20
+ private class WindowBoundView(context: Context) : View(context) {
21
+ var measures = 0
22
+
23
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
24
+ check(isAttachedToWindow) { "measured before attached to a window" }
25
+ measures++
26
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec)
27
+ }
28
+ }
29
+
30
+ @Test fun mediaChildAddedBeforeWindowAttachIsMeasuredOnlyAfterAttach() {
31
+ val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
32
+ val media = DaroMediaView(activity)
33
+ // RN 이 창에 붙기 전에 이미 크기를 준 상태 — 광고 SDK 는 이때 미디어 뷰를 넣는다.
34
+ media.layout(0, 0, 300, 200)
35
+ val child = WindowBoundView(activity)
36
+
37
+ media.addView(FrameLayout(activity).apply { addView(child) })
38
+ shadowOf(Looper.getMainLooper()).idle()
39
+ assertEquals(0, child.measures)
40
+
41
+ activity.setContentView(FrameLayout(activity).apply { addView(media, 300, 200) })
42
+ shadowOf(Looper.getMainLooper()).idle()
43
+ assertTrue(child.measures > 0)
44
+ }
45
+ }
@@ -0,0 +1,160 @@
1
+ package com.daro.reactnative.view
2
+
3
+ import android.app.Activity
4
+ import android.os.Looper
5
+ import android.view.View
6
+ import android.widget.FrameLayout
7
+ import com.daro.reactnative.preload.DaroRNPreloadRegistry
8
+ import com.facebook.react.bridge.BridgeReactContext
9
+ import com.facebook.react.views.text.ReactTextView
10
+ import droom.daro.core.model.DaroBannerSize
11
+ import droom.daro.view.DaroBannerAdController
12
+ import droom.daro.view.DaroBannerAdView
13
+ import droom.daro.view.DaroNativeAdController
14
+ import droom.daro.view.DaroNativeAdView
15
+ import org.junit.After
16
+ import org.junit.Test
17
+ import org.junit.runner.RunWith
18
+ import org.mockito.MockedConstruction
19
+ import org.mockito.Mockito.mock
20
+ import org.mockito.Mockito.mockConstruction
21
+ import org.mockito.Mockito.times
22
+ import org.mockito.Mockito.verify
23
+ import org.robolectric.Robolectric
24
+ import org.robolectric.RobolectricTestRunner
25
+ import org.robolectric.Shadows.shadowOf
26
+ import org.robolectric.annotation.Config
27
+
28
+ /**
29
+ * 받아 둔 광고를 넘겨받은 뷰의 첫 로드 ( DARO-2488 ).
30
+ *
31
+ * 컨트롤러를 가진 SDK 뷰는 화면에 붙을 때 스스로 `loadAd()` 를 불러 받아 둔 광고를 쓴다.
32
+ * 컨테이너가 그 뒤에 `loadAd()` 를 또 부르면, 그 처리가 끝난 뒤에는 새 요청이 되어 받아 둔
33
+ * 광고를 덮어쓴다. SDK 뷰는 생성자 mock 이라 스스로 로드하지 않는다 — 여기서 세는 것은
34
+ * 컨테이너가 부른 횟수다.
35
+ */
36
+ @RunWith(RobolectricTestRunner::class)
37
+ @Config(sdk = [28], manifest = Config.NONE)
38
+ class DaroRNPreloadFirstLoadTest {
39
+ private val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
40
+ private val reactContext = BridgeReactContext(activity).apply { onHostResume(activity) }
41
+ private val root = FrameLayout(activity).also {
42
+ activity.setContentView(it)
43
+ // Robolectric 은 창 가시성을 갱신하지 않아 GONE 으로 남는다. 배너는 창이 보일 때만 로드한다.
44
+ val attachInfo = View::class.java.getDeclaredField("mAttachInfo").apply { isAccessible = true }.get(it)
45
+ attachInfo.javaClass.getDeclaredField("mWindowVisibility").apply { isAccessible = true }.setInt(attachInfo, View.VISIBLE)
46
+ }
47
+
48
+ @After fun tearDown() = DaroRNPreloadRegistry.shared.destroyAll()
49
+
50
+ private fun idle() = shadowOf(Looper.getMainLooper()).idle()
51
+
52
+ private fun <T> MockedConstruction<T>.only(): T = constructed().single()
53
+
54
+ // ── 배너 ──────────────────────────────────────────────────────────────
55
+
56
+ private fun preloadBanner(id: String) {
57
+ val controller = mock(DaroBannerAdController::class.java)
58
+ DaroRNPreloadRegistry.shared.preload(id) {
59
+ DaroRNPreloadRegistry.Entry("unit", DaroBannerSize.Banner.name, controller, {}, {})
60
+ }
61
+ }
62
+
63
+ /** 화면에 붙어 있고 크기가 [width] × 50 인 배너 컨테이너. */
64
+ private fun banner(preloadId: String?, width: Int = 320) = DaroRNAdBannerViewContainer(reactContext).also {
65
+ it.adUnitKey = "unit"
66
+ it.adSize = DaroBannerSize.Banner
67
+ it.preloadId = preloadId
68
+ root.addView(it, width, 50)
69
+ it.layout(0, 0, width, 50)
70
+ idle()
71
+ }
72
+
73
+ @Test fun bannerThatTookAPreloadLeavesTheFirstLoadToTheSdk() {
74
+ mockConstruction(DaroBannerAdView::class.java).use { views ->
75
+ preloadBanner("p")
76
+ val container = banner("p")
77
+
78
+ container.loadAd(); idle()
79
+ verify(views.only(), times(0)).loadAd()
80
+
81
+ // 그 뒤의 loadAd 는 재로드다.
82
+ container.loadAd(); idle()
83
+ verify(views.only(), times(1)).loadAd()
84
+ }
85
+ }
86
+
87
+ @Test fun bannerThatTookAPreloadDoesNotLoadOnceItGetsASize() {
88
+ mockConstruction(DaroBannerAdView::class.java).use { views ->
89
+ preloadBanner("p")
90
+ val container = banner("p", width = 0)
91
+
92
+ container.loadAd(); idle()
93
+ // 크기가 준비되면 미뤄 둔 로드를 다시 시도하던 경로.
94
+ container.layout(0, 0, 320, 50); idle()
95
+
96
+ verify(views.only(), times(0)).loadAd()
97
+ }
98
+ }
99
+
100
+ @Test fun bannerWithoutAPreloadLoadsAsBefore() {
101
+ mockConstruction(DaroBannerAdView::class.java).use { views ->
102
+ val container = banner(null)
103
+
104
+ container.loadAd(); idle()
105
+ verify(views.only(), times(1)).loadAd()
106
+ }
107
+ }
108
+
109
+ @Test fun bannerWithoutAPreloadStillLoadsOnceItGetsASize() {
110
+ mockConstruction(DaroBannerAdView::class.java).use { views ->
111
+ val container = banner(null, width = 0)
112
+
113
+ container.loadAd(); idle()
114
+ verify(views.only(), times(0)).loadAd()
115
+
116
+ container.layout(0, 0, 320, 50); idle()
117
+ verify(views.only(), times(1)).loadAd()
118
+ }
119
+ }
120
+
121
+ // ── 네이티브 ──────────────────────────────────────────────────────────
122
+
123
+ /** 화면에 붙어 있고 제목 뷰 하나를 등록한 네이티브 컨테이너. */
124
+ private fun native(preloadId: String?) = DaroRNAdNativeViewContainer(reactContext).also {
125
+ it.adUnitKey = "unit"
126
+ it.loadOnMount = false
127
+ it.preloadId = preloadId
128
+ it.addReactSubview(ReactTextView(reactContext).apply { id = TITLE_ID }, 0)
129
+ it.setTitleView(TITLE_ID)
130
+ root.addView(it, 320, 100)
131
+ idle()
132
+ }
133
+
134
+ @Test fun nativeThatTookAPreloadLeavesTheFirstLoadToTheSdk() {
135
+ mockConstruction(DaroNativeAdView::class.java).use { views ->
136
+ val controller = mock(DaroNativeAdController::class.java)
137
+ DaroRNPreloadRegistry.shared.preload("p") { DaroRNPreloadRegistry.Entry("unit", "", controller, {}, {}) }
138
+ val container = native("p")
139
+
140
+ container.loadAd(); idle()
141
+ verify(views.only(), times(0)).loadAd()
142
+
143
+ container.loadAd(); idle()
144
+ verify(views.only(), times(1)).loadAd()
145
+ }
146
+ }
147
+
148
+ @Test fun nativeWithoutAPreloadLoadsAsBefore() {
149
+ mockConstruction(DaroNativeAdView::class.java).use { views ->
150
+ val container = native(null)
151
+
152
+ container.loadAd(); idle()
153
+ verify(views.only(), times(1)).loadAd()
154
+ }
155
+ }
156
+
157
+ private companion object {
158
+ const val TITLE_ID = 1001
159
+ }
160
+ }
@@ -4,10 +4,10 @@ import React
4
4
 
5
5
  extension DaroRNModule {
6
6
 
7
- @objc(isAppOpenAdReady:adUnitId:resolve:reject:)
7
+ @objc(isAppOpenAdReady:adUnitKey:resolve:reject:)
8
8
  func isAppOpenAdReady(
9
9
  requestId: Double,
10
- adUnitId: String,
10
+ adUnitKey: String,
11
11
  resolve: RCTPromiseResolveBlock,
12
12
  reject: RCTPromiseRejectBlock
13
13
  ) {
@@ -20,23 +20,23 @@ extension DaroRNModule {
20
20
  resolve(appOpenAds[requestId]?.loadedAd != nil)
21
21
  }
22
22
 
23
- @objc(loadAppOpenAd:adUnitId:resolve:reject:)
23
+ @objc(loadAppOpenAd:adUnitKey:resolve:reject:)
24
24
  func loadAppOpenAd(
25
25
  requestId: Double,
26
- adUnitId: String,
26
+ adUnitKey: String,
27
27
  resolve: RCTPromiseResolveBlock,
28
28
  reject: RCTPromiseRejectBlock
29
29
  ) {
30
30
  let requestId = Int(requestId)
31
- let appOpenAdLoader = retrieveAppOpenLoader(requestId: requestId, adUnitId: adUnitId)
31
+ let appOpenAdLoader = retrieveAppOpenLoader(requestId: requestId, adUnitKey: adUnitKey)
32
32
  appOpenAdLoader.loadAd()
33
33
  resolve(Void())
34
34
  }
35
35
 
36
- @objc(showAppOpenAd:adUnitId:customData:resolve:reject:)
36
+ @objc(showAppOpenAd:adUnitKey:customData:resolve:reject:)
37
37
  func showAppOpenAd(
38
38
  requestId: Double,
39
- adUnitId: String,
39
+ adUnitKey: String,
40
40
  customData: String?,
41
41
  resolve: @escaping RCTPromiseResolveBlock,
42
42
  reject: RCTPromiseRejectBlock
@@ -52,11 +52,11 @@ extension DaroRNModule {
52
52
  }
53
53
  }
54
54
 
55
- func retrieveAppOpenLoader(requestId: Int, adUnitId: String) -> DaroAppOpenAdLoader {
55
+ func retrieveAppOpenLoader(requestId: Int, adUnitKey: String) -> DaroAppOpenAdLoader {
56
56
  if let appOpenLoader = appOpenAds[requestId] {
57
57
  return appOpenLoader.loader
58
58
  } else {
59
- let appOpenLoader = DaroAppOpenAdLoader(unit: DaroAdUnit(unitId: adUnitId))
59
+ let appOpenLoader = DaroAppOpenAdLoader(unit: DaroAdUnit(adUnitKey: adUnitKey))
60
60
  appOpenLoader.listener.onAdClicked = { [weak self] adInfo in
61
61
  DaroRNModule.logger.debug("[DARO] Sample AppOpen Ad clicked")
62
62
  self?.sendEvent(with: .onAppOpenAdClickedEvent, body: adInfo?.toBody(requestId: requestId))
@@ -4,10 +4,10 @@ import React
4
4
 
5
5
  extension DaroRNModule {
6
6
 
7
- @objc(isInterstitialReady:adUnitId:resolve:reject:)
7
+ @objc(isInterstitialReady:adUnitKey:resolve:reject:)
8
8
  func isInterstitialReady(
9
9
  requestId: Double,
10
- adUnitId: String,
10
+ adUnitKey: String,
11
11
  resolve: RCTPromiseResolveBlock,
12
12
  reject: RCTPromiseRejectBlock
13
13
  ) {
@@ -20,23 +20,23 @@ extension DaroRNModule {
20
20
  resolve(interstitials[requestId]?.loadedAd != nil)
21
21
  }
22
22
 
23
- @objc(loadInterstitial:adUnitId:resolve:reject:)
23
+ @objc(loadInterstitial:adUnitKey:resolve:reject:)
24
24
  func loadInterstitial(
25
25
  requestId: Double,
26
- adUnitId: String,
26
+ adUnitKey: String,
27
27
  resolve: RCTPromiseResolveBlock,
28
28
  reject: RCTPromiseRejectBlock
29
29
  ) {
30
30
  let requestId = Int(requestId)
31
- let interstitialLoader = retrieveInterstitialLoader(requestId: requestId, adUnitId: adUnitId)
31
+ let interstitialLoader = retrieveInterstitialLoader(requestId: requestId, adUnitKey: adUnitKey)
32
32
  interstitialLoader.loadAd()
33
33
  resolve(Void())
34
34
  }
35
35
 
36
- @objc(showInterstitial:adUnitId:resolve:reject:)
36
+ @objc(showInterstitial:adUnitKey:resolve:reject:)
37
37
  func showInterstitial(
38
38
  requestId: Double,
39
- adUnitId: String,
39
+ adUnitKey: String,
40
40
  resolve: @escaping RCTPromiseResolveBlock,
41
41
  reject: @escaping RCTPromiseRejectBlock
42
42
  ) {
@@ -55,11 +55,11 @@ extension DaroRNModule {
55
55
  }
56
56
  }
57
57
 
58
- func retrieveInterstitialLoader(requestId: Int, adUnitId: String) -> DaroInterstitialAdLoader {
58
+ func retrieveInterstitialLoader(requestId: Int, adUnitKey: String) -> DaroInterstitialAdLoader {
59
59
  if let interstitialAd = interstitials[requestId] {
60
60
  return interstitialAd.loader
61
61
  } else {
62
- let interstitialLoader = DaroInterstitialAdLoader(unit: DaroAdUnit(unitId: adUnitId))
62
+ let interstitialLoader = DaroInterstitialAdLoader(unit: DaroAdUnit(adUnitKey: adUnitKey))
63
63
  interstitialLoader.listener.onAdClicked = { [weak self] adInfo in
64
64
  DaroRNModule.logger.debug("[DARO] Sample Interstitial Ad clicked")
65
65
  self?.sendEvent(with: .onInterstitialClickedEvent, body: adInfo?.toBody(requestId: requestId))
@@ -3,8 +3,8 @@ import UIKit
3
3
  // MARK: - LightPopup Ad
4
4
  extension DaroRNModule {
5
5
 
6
- @objc(destroyLightPopup:adUnitId:)
7
- func destroyLightPopup(requestId: Double, adUnitId: String) {
6
+ @objc(destroyLightPopup:adUnitKey:)
7
+ func destroyLightPopup(requestId: Double, adUnitKey: String) {
8
8
  performLightPopupOnMain { releaseLightPopup(requestId: Int(requestId)) }
9
9
  }
10
10
 
@@ -41,8 +41,8 @@ extension DaroRNModule {
41
41
  request.presentedController = nil
42
42
  }
43
43
 
44
- @objc(isLightPopupReady:adUnitId:resolve:reject:)
45
- func isLightPopupReady(requestId: Double, adUnitId: String,
44
+ @objc(isLightPopupReady:adUnitKey:resolve:reject:)
45
+ func isLightPopupReady(requestId: Double, adUnitKey: String,
46
46
  resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
47
47
  performLightPopupOnMain {
48
48
  let request = lightPopups[Int(requestId)]
@@ -50,8 +50,8 @@ extension DaroRNModule {
50
50
  }
51
51
  }
52
52
 
53
- @objc(loadLightPopup:adUnitId:resolve:reject:)
54
- func loadLightPopup(requestId: Double, adUnitId: String,
53
+ @objc(loadLightPopup:adUnitKey:resolve:reject:)
54
+ func loadLightPopup(requestId: Double, adUnitKey: String,
55
55
  resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
56
56
  performLightPopupOnMain {
57
57
  guard !lightPopupInvalidated else { resolve(Void()); return }
@@ -59,13 +59,13 @@ extension DaroRNModule {
59
59
  let configuration = lightPopupConfigurations[id]
60
60
  releaseLightPopup(requestId: id)
61
61
  lightPopupConfigurations[id] = configuration
62
- retrieveLightPopupLoader(requestId: id, adUnitId: adUnitId).loadAd()
62
+ retrieveLightPopupLoader(requestId: id, adUnitKey: adUnitKey).loadAd()
63
63
  resolve(Void())
64
64
  }
65
65
  }
66
66
 
67
- @objc(showLightPopup:adUnitId:resolve:reject:)
68
- func showLightPopup(requestId: Double, adUnitId: String,
67
+ @objc(showLightPopup:adUnitKey:resolve:reject:)
68
+ func showLightPopup(requestId: Double, adUnitKey: String,
69
69
  resolve: @escaping RCTPromiseResolveBlock,
70
70
  reject: @escaping RCTPromiseRejectBlock) {
71
71
  performLightPopupOnMain {
@@ -93,8 +93,8 @@ extension DaroRNModule {
93
93
  }
94
94
  }
95
95
 
96
- @objc(setLightPopupAdConfiguration:adUnitId:configuration:resolve:reject:)
97
- func setLightPopupAdConfiguration(requestId: Double, adUnitId: String,
96
+ @objc(setLightPopupAdConfiguration:adUnitKey:configuration:resolve:reject:)
97
+ func setLightPopupAdConfiguration(requestId: Double, adUnitKey: String,
98
98
  configuration: [String: Any],
99
99
  resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
100
100
  performLightPopupOnMain {
@@ -134,8 +134,8 @@ extension DaroRNModule {
134
134
  }
135
135
  }
136
136
 
137
- func retrieveLightPopupLoader(requestId: Int, adUnitId: String) -> DaroLightPopupAdLoader {
138
- let loader = DaroLightPopupAdLoader(unit: DaroAdUnit(unitId: adUnitId))
137
+ func retrieveLightPopupLoader(requestId: Int, adUnitKey: String) -> DaroLightPopupAdLoader {
138
+ let loader = DaroLightPopupAdLoader(unit: DaroAdUnit(adUnitKey: adUnitKey))
139
139
  let request = LightPopupAd(loader: loader)
140
140
  lightPopups[requestId] = request
141
141
  loader.listener.onAdClicked = { [weak self, weak request] adInfo in
@@ -0,0 +1,122 @@
1
+ import React
2
+ import UIKit
3
+
4
+ // MARK: - View Ad Preload
5
+
6
+ extension DaroRNModule {
7
+
8
+ @objc(preloadBannerAd:adUnitKey:adFormat:resolve:reject:)
9
+ func preloadBannerAd(
10
+ preloadId: String,
11
+ adUnitKey: String,
12
+ adFormat: String,
13
+ resolve: @escaping RCTPromiseResolveBlock,
14
+ reject: @escaping RCTPromiseRejectBlock
15
+ ) {
16
+ DispatchQueue.main.async { [weak self] in
17
+ DaroRNPreloadRegistry.shared.preload(preloadId) {
18
+ let bannerSize = adFormat == Constants.mrecAdFormatLabel.value ? DaroAdBannerSize.MREC : DaroAdBannerSize.banner
19
+ let view = DaroAdBannerView(unit: DaroAdUnit(adUnitKey: adUnitKey), bannerSize: bannerSize, preload: true)
20
+ view.listener.onPreloadSuccess = { [weak self] adInfo in
21
+ self?.sendPreloadSuccess(preloadId: preloadId, adUnitKey: adUnitKey, adInfo: adInfo)
22
+ }
23
+ view.listener.onPreloadFail = { [weak self] error in
24
+ self?.sendPreloadFail(preloadId: preloadId, adUnitKey: adUnitKey, error: error)
25
+ }
26
+ return DaroRNPreloadRegistry.Entry(
27
+ adUnitKey: adUnitKey,
28
+ variant: adFormat,
29
+ view: view,
30
+ preload: { [weak view] in view?.loadAd() },
31
+ destroy: { [weak view] in
32
+ view?.listener.onPreloadSuccess = nil
33
+ view?.listener.onPreloadFail = nil
34
+ }
35
+ )
36
+ }
37
+ resolve(nil)
38
+ }
39
+ }
40
+
41
+ @objc(preloadNativeAd:adUnitKey:adChoicesPosition:resolve:reject:)
42
+ func preloadNativeAd(
43
+ preloadId: String,
44
+ adUnitKey: String,
45
+ adChoicesPosition: String,
46
+ resolve: @escaping RCTPromiseResolveBlock,
47
+ reject: @escaping RCTPromiseRejectBlock
48
+ ) {
49
+ DispatchQueue.main.async { [weak self] in
50
+ DaroRNPreloadRegistry.shared.preload(preloadId) {
51
+ let view = DaroRNBridgeNativeAdView(
52
+ unit: DaroAdUnit(adUnitKey: adUnitKey),
53
+ preload: true,
54
+ preferredAdChoicesPosition: DaroAdChoicesPosition(reactValue: adChoicesPosition)
55
+ )
56
+ view.listener.onPreloadSuccess = { [weak self] adInfo in
57
+ self?.sendPreloadSuccess(preloadId: preloadId, adUnitKey: adUnitKey, adInfo: adInfo)
58
+ }
59
+ view.listener.onPreloadFail = { [weak self] error in
60
+ self?.sendPreloadFail(preloadId: preloadId, adUnitKey: adUnitKey, error: error)
61
+ }
62
+ return DaroRNPreloadRegistry.Entry(
63
+ adUnitKey: adUnitKey,
64
+ variant: "",
65
+ view: view,
66
+ preload: { [weak view] in view?.loadAd() },
67
+ destroy: { [weak view] in
68
+ view?.listener.onPreloadSuccess = nil
69
+ view?.listener.onPreloadFail = nil
70
+ view?.clearNativeAd()
71
+ }
72
+ )
73
+ }
74
+ resolve(nil)
75
+ }
76
+ }
77
+
78
+ @objc(destroyAdPreload:)
79
+ func destroyAdPreload(preloadId: String) {
80
+ DispatchQueue.main.async {
81
+ DaroRNPreloadRegistry.shared.destroy(preloadId)
82
+ }
83
+ }
84
+
85
+ func invalidatePreloads() {
86
+ DispatchQueue.main.async {
87
+ DaroRNPreloadRegistry.shared.destroyAll()
88
+ }
89
+ }
90
+
91
+ private func sendPreloadSuccess(preloadId: String, adUnitKey: String, adInfo: DaroAdInfo?) {
92
+ var body = adInfo?.toBody ?? ["adUnitKey": adUnitKey]
93
+ body["preloadId"] = preloadId
94
+ sendEvent(with: .onAdPreloadSuccessEvent, body: body)
95
+ }
96
+
97
+ // preload 실패는 SDK 의 공통 오류 ( DaroError ) 로 온다. 기존 로드 실패와 같은 모양으로 싣는다.
98
+ private func sendPreloadFail(preloadId: String, adUnitKey: String, error: DaroError) {
99
+ sendEvent(with: .onAdPreloadFailedEvent, body: [
100
+ "preloadId": preloadId,
101
+ "adUnitKey": adUnitKey,
102
+ "code": error.code.rawValue,
103
+ "message": error.message,
104
+ "latencyMillis": 0,
105
+ ])
106
+ }
107
+ }
108
+
109
+ extension DaroAdChoicesPosition {
110
+ init(reactValue: String?) {
111
+ switch reactValue {
112
+ case "topLeft":
113
+ self = .topLeft
114
+ case "topRight":
115
+ self = .topRight
116
+ case "bottomLeft":
117
+ self = .bottomLeft
118
+ default:
119
+ self = .bottomRight
120
+ }
121
+ }
122
+ }
@@ -1,10 +1,10 @@
1
1
  import React
2
2
 
3
3
  extension DaroRNModule {
4
- @objc(isRewardedAdReady:adUnitId:resolve:reject:)
4
+ @objc(isRewardedAdReady:adUnitKey:resolve:reject:)
5
5
  func isRewardedAdReady(
6
6
  requestId: Double,
7
- adUnitId: String,
7
+ adUnitKey: String,
8
8
  resolve: RCTPromiseResolveBlock,
9
9
  reject: RCTPromiseRejectBlock
10
10
  ) {
@@ -18,23 +18,23 @@ extension DaroRNModule {
18
18
  resolve(rewardedAds[requestId]?.loadedAd != nil)
19
19
  }
20
20
 
21
- @objc(loadRewardedAd:adUnitId:resolve:reject:)
21
+ @objc(loadRewardedAd:adUnitKey:resolve:reject:)
22
22
  func loadRewardedAd(
23
23
  requestId: Double,
24
- adUnitId: String,
24
+ adUnitKey: String,
25
25
  resolve: RCTPromiseResolveBlock,
26
26
  reject: RCTPromiseRejectBlock
27
27
  ) {
28
28
  let requestId = Int(requestId)
29
- let rewardedLoader = retrieveRewardedLoader(requestId: requestId, adUnitId: adUnitId)
29
+ let rewardedLoader = retrieveRewardedLoader(requestId: requestId, adUnitKey: adUnitKey)
30
30
  rewardedLoader.loadAd()
31
31
  resolve(Void())
32
32
  }
33
33
 
34
- @objc(showRewardedAd:adUnitId:customData:resolve:reject:)
34
+ @objc(showRewardedAd:adUnitKey:customData:resolve:reject:)
35
35
  func showRewardedAd(
36
36
  requestId: Double,
37
- adUnitId: String,
37
+ adUnitKey: String,
38
38
  customData: String?,
39
39
  resolve: @escaping RCTPromiseResolveBlock,
40
40
  reject: @escaping RCTPromiseRejectBlock
@@ -57,11 +57,11 @@ extension DaroRNModule {
57
57
  }
58
58
  }
59
59
 
60
- func retrieveRewardedLoader(requestId: Int, adUnitId: String) -> DaroRewardedAdLoader {
60
+ func retrieveRewardedLoader(requestId: Int, adUnitKey: String) -> DaroRewardedAdLoader {
61
61
  if let rewardedAd = rewardedAds[requestId] {
62
62
  return rewardedAd.loader
63
63
  } else {
64
- let rewardedAdLoader = DaroRewardedAdLoader(unit: DaroAdUnit(unitId: adUnitId))
64
+ let rewardedAdLoader = DaroRewardedAdLoader(unit: DaroAdUnit(adUnitKey: adUnitKey))
65
65
  rewardedAdLoader.listener.onAdClicked = { [weak self] adInfo in
66
66
  DaroRNModule.logger.debug("[DARO] Sample Rewarded Ad clicked")
67
67
  self?.sendEvent(with: .onRewardedAdClickedEvent, body: adInfo?.toBody(requestId: requestId))
@@ -107,22 +107,22 @@ extension DaroRNModule {
107
107
 
108
108
  ad.rewardedAdListener.onEarnedReward = { [weak self] adInfo, rewardItem in
109
109
  DaroRNModule.logger.debug("[DARO] Sample Rewarded Ad received reward")
110
- self?.sendEvent(with: .onRewardedAdReceivedRewardEvent, body: rewardItem?.toBody(requestId: requestId, unitId: adInfo?.adUnitId ?? ""))
110
+ self?.sendEvent(with: .onRewardedAdReceivedRewardEvent, body: rewardItem?.toBody(requestId: requestId, adUnitKey: adInfo?.adUnitKey ?? ""))
111
111
  }
112
112
  }
113
113
  }
114
114
 
115
115
  private extension DaroRewardedItem {
116
- func toBody(unitId: String) -> [String: Any] {
116
+ func toBody(adUnitKey: String) -> [String: Any] {
117
117
  return [
118
- "adUnitId": unitId,
118
+ "adUnitKey": adUnitKey,
119
119
  "rewardLabel": self.rewardType,
120
120
  "rewardAmount": self.amount,
121
121
  ]
122
122
  }
123
123
 
124
- func toBody(requestId: Int, unitId: String) -> [String: Any] {
125
- var body = self.toBody(unitId: unitId)
124
+ func toBody(requestId: Int, adUnitKey: String) -> [String: Any] {
125
+ var body = self.toBody(adUnitKey: adUnitKey)
126
126
  body["requestId"] = requestId
127
127
  return body
128
128
  }