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.
- package/README.md +2 -2
- package/android/build.gradle +3 -1
- package/android/src/main/java/com/daro/reactnative/DaroRNAdBannerViewManager.kt +8 -3
- package/android/src/main/java/com/daro/reactnative/DaroRNAdNativeViewManager.kt +8 -3
- package/android/src/main/java/com/daro/reactnative/DaroRNModule.kt +76 -34
- package/android/src/main/java/com/daro/reactnative/event/DaroRNEvent.kt +8 -0
- package/android/src/main/java/com/daro/reactnative/impl/DaroRNInterstitialModuleImpl.kt +13 -13
- package/android/src/main/java/com/daro/reactnative/impl/DaroRNLightPopupModuleImpl.kt +12 -12
- package/android/src/main/java/com/daro/reactnative/impl/DaroRNPreloadModuleImpl.kt +77 -0
- package/android/src/main/java/com/daro/reactnative/impl/DaroRNRewardedAdModuleImpl.kt +14 -14
- package/android/src/main/java/com/daro/reactnative/preload/DaroRNPreloadRegistry.kt +57 -0
- package/android/src/main/java/com/daro/reactnative/util/AdInfoUtil.kt +27 -16
- package/android/src/main/java/com/daro/reactnative/view/DaroMediaView.kt +3 -0
- package/android/src/main/java/com/daro/reactnative/view/DaroRNAdBannerViewContainer.kt +36 -15
- package/android/src/main/java/com/daro/reactnative/view/DaroRNAdNativeViewContainer.kt +36 -15
- package/android/src/oldarch/java/com/daro/reactnative/DaroRNModuleSpec.kt +28 -14
- package/android/src/test/java/com/daro/reactnative/preload/DaroRNPreloadRegistryTest.kt +65 -0
- package/android/src/test/java/com/daro/reactnative/view/DaroMediaViewTest.kt +45 -0
- package/android/src/test/java/com/daro/reactnative/view/DaroRNPreloadFirstLoadTest.kt +160 -0
- package/ios/DaroRNModule+AppOpen.swift +9 -9
- package/ios/DaroRNModule+Interstitial.swift +9 -9
- package/ios/DaroRNModule+LightPopup.swift +13 -13
- package/ios/DaroRNModule+Preload.swift +122 -0
- package/ios/DaroRNModule+Rewarded.swift +14 -14
- package/ios/DaroRNModule.mm +20 -14
- package/ios/DaroRNModule.swift +6 -1
- package/ios/Fabric/DaroRNAdBannerComponentView.mm +12 -7
- package/ios/Fabric/DaroRNNativeAdComponentView.mm +12 -7
- package/ios/Paper/DaroRNAdBannerViewManager.m +2 -1
- package/ios/Paper/DaroRNNativeAdViewManager.m +2 -1
- package/ios/Shared/DaroRNBannerAdView.swift +23 -9
- package/ios/Shared/DaroRNNativeAdView.swift +77 -46
- package/ios/Shared/DaroRNPreloadRegistry.swift +54 -0
- package/lib/commonjs/AdBannerView.js +4 -2
- package/lib/commonjs/AdBannerView.js.map +1 -1
- package/lib/commonjs/AdPreload.js +105 -0
- package/lib/commonjs/AdPreload.js.map +1 -0
- package/lib/commonjs/AppOpenAd.js +22 -22
- package/lib/commonjs/AppOpenAd.js.map +1 -1
- package/lib/commonjs/DaroRNAdBannerViewNativeComponent.ts +5 -3
- package/lib/commonjs/DaroRNNativeAdViewNativeComponent.ts +5 -3
- package/lib/commonjs/InterstitialAd.js +24 -24
- package/lib/commonjs/InterstitialAd.js.map +1 -1
- package/lib/commonjs/LightPopupAd.js +27 -27
- package/lib/commonjs/LightPopupAd.js.map +1 -1
- package/lib/commonjs/NativeDaroModule.js.map +1 -1
- package/lib/commonjs/RewardedAd.js +22 -22
- package/lib/commonjs/RewardedAd.js.map +1 -1
- package/lib/commonjs/hooks/useAdPreload.js +61 -0
- package/lib/commonjs/hooks/useAdPreload.js.map +1 -0
- package/lib/commonjs/hooks/useInterstitialAd.js +6 -6
- package/lib/commonjs/hooks/useInterstitialAd.js.map +1 -1
- package/lib/commonjs/hooks/useLightPopupAd.js +5 -5
- package/lib/commonjs/hooks/useLightPopupAd.js.map +1 -1
- package/lib/commonjs/hooks/useRewardedAd.js +6 -6
- package/lib/commonjs/hooks/useRewardedAd.js.map +1 -1
- package/lib/commonjs/index.js +37 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdView.js +4 -2
- package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
- package/lib/commonjs/types/NativeAdViewProps.js.map +1 -1
- package/lib/module/AdBannerView.js +4 -2
- package/lib/module/AdBannerView.js.map +1 -1
- package/lib/module/AdPreload.js +98 -0
- package/lib/module/AdPreload.js.map +1 -0
- package/lib/module/AppOpenAd.js +22 -22
- package/lib/module/AppOpenAd.js.map +1 -1
- package/lib/module/DaroRNAdBannerViewNativeComponent.ts +5 -3
- package/lib/module/DaroRNNativeAdViewNativeComponent.ts +5 -3
- package/lib/module/InterstitialAd.js +24 -24
- package/lib/module/InterstitialAd.js.map +1 -1
- package/lib/module/LightPopupAd.js +27 -27
- package/lib/module/LightPopupAd.js.map +1 -1
- package/lib/module/NativeDaroModule.js.map +1 -1
- package/lib/module/RewardedAd.js +22 -22
- package/lib/module/RewardedAd.js.map +1 -1
- package/lib/module/hooks/useAdPreload.js +56 -0
- package/lib/module/hooks/useAdPreload.js.map +1 -0
- package/lib/module/hooks/useInterstitialAd.js +6 -6
- package/lib/module/hooks/useInterstitialAd.js.map +1 -1
- package/lib/module/hooks/useLightPopupAd.js +5 -5
- package/lib/module/hooks/useLightPopupAd.js.map +1 -1
- package/lib/module/hooks/useRewardedAd.js +6 -6
- package/lib/module/hooks/useRewardedAd.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeAd/NativeAdView.js +4 -2
- package/lib/module/nativeAd/NativeAdView.js.map +1 -1
- package/lib/module/types/NativeAdViewProps.js.map +1 -1
- package/lib/typescript/commonjs/src/AdBannerView.d.ts +1 -0
- package/lib/typescript/commonjs/src/AdBannerView.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/AdPreload.d.ts +62 -0
- package/lib/typescript/commonjs/src/AdPreload.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/AppOpenAd.d.ts +8 -8
- package/lib/typescript/commonjs/src/AppOpenAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/DaroRNAdBannerViewNativeComponent.d.ts +4 -3
- package/lib/typescript/commonjs/src/DaroRNAdBannerViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts +4 -3
- package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/InterstitialAd.d.ts +8 -8
- package/lib/typescript/commonjs/src/InterstitialAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/LightPopupAd.d.ts +9 -9
- package/lib/typescript/commonjs/src/LightPopupAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/NativeDaroModule.d.ts +19 -14
- package/lib/typescript/commonjs/src/NativeDaroModule.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/RewardedAd.d.ts +8 -8
- package/lib/typescript/commonjs/src/RewardedAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/hooks/useAdPreload.d.ts +19 -0
- package/lib/typescript/commonjs/src/hooks/useAdPreload.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/hooks/useInterstitialAd.d.ts +1 -1
- package/lib/typescript/commonjs/src/hooks/useInterstitialAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts +1 -1
- package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/hooks/useRewardedAd.d.ts +1 -1
- package/lib/typescript/commonjs/src/hooks/useRewardedAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +4 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts +1 -0
- package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdBannerViewProps.d.ts +6 -0
- package/lib/typescript/commonjs/src/types/AdBannerViewProps.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdInfo.d.ts +2 -2
- package/lib/typescript/commonjs/src/types/AdInfo.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdProps.d.ts +1 -1
- package/lib/typescript/commonjs/src/types/AdProps.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts +6 -0
- package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts.map +1 -1
- package/lib/typescript/module/src/AdBannerView.d.ts +1 -0
- package/lib/typescript/module/src/AdBannerView.d.ts.map +1 -1
- package/lib/typescript/module/src/AdPreload.d.ts +62 -0
- package/lib/typescript/module/src/AdPreload.d.ts.map +1 -0
- package/lib/typescript/module/src/AppOpenAd.d.ts +8 -8
- package/lib/typescript/module/src/AppOpenAd.d.ts.map +1 -1
- package/lib/typescript/module/src/DaroRNAdBannerViewNativeComponent.d.ts +4 -3
- package/lib/typescript/module/src/DaroRNAdBannerViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts +4 -3
- package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/InterstitialAd.d.ts +8 -8
- package/lib/typescript/module/src/InterstitialAd.d.ts.map +1 -1
- package/lib/typescript/module/src/LightPopupAd.d.ts +9 -9
- package/lib/typescript/module/src/LightPopupAd.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeDaroModule.d.ts +19 -14
- package/lib/typescript/module/src/NativeDaroModule.d.ts.map +1 -1
- package/lib/typescript/module/src/RewardedAd.d.ts +8 -8
- package/lib/typescript/module/src/RewardedAd.d.ts.map +1 -1
- package/lib/typescript/module/src/hooks/useAdPreload.d.ts +19 -0
- package/lib/typescript/module/src/hooks/useAdPreload.d.ts.map +1 -0
- package/lib/typescript/module/src/hooks/useInterstitialAd.d.ts +1 -1
- package/lib/typescript/module/src/hooks/useInterstitialAd.d.ts.map +1 -1
- package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts +1 -1
- package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts.map +1 -1
- package/lib/typescript/module/src/hooks/useRewardedAd.d.ts +1 -1
- package/lib/typescript/module/src/hooks/useRewardedAd.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +4 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts +1 -0
- package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdBannerViewProps.d.ts +6 -0
- package/lib/typescript/module/src/types/AdBannerViewProps.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdInfo.d.ts +2 -2
- package/lib/typescript/module/src/types/AdInfo.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdProps.d.ts +1 -1
- package/lib/typescript/module/src/types/AdProps.d.ts.map +1 -1
- package/lib/typescript/module/src/types/NativeAdViewProps.d.ts +6 -0
- package/lib/typescript/module/src/types/NativeAdViewProps.d.ts.map +1 -1
- package/package.json +1 -1
- package/plugin/build/withAndroid.js +2 -2
- package/react-native-daro.podspec +1 -1
- package/src/AdBannerView.tsx +4 -2
- package/src/AdPreload.ts +141 -0
- package/src/AppOpenAd.ts +21 -21
- package/src/DaroRNAdBannerViewNativeComponent.ts +5 -3
- package/src/DaroRNNativeAdViewNativeComponent.ts +5 -3
- package/src/InterstitialAd.ts +23 -23
- package/src/LightPopupAd.ts +26 -26
- package/src/NativeDaroModule.ts +31 -14
- package/src/RewardedAd.ts +21 -21
- package/src/hooks/useAdPreload.ts +82 -0
- package/src/hooks/useInterstitialAd.ts +6 -6
- package/src/hooks/useLightPopupAd.ts +5 -5
- package/src/hooks/useRewardedAd.ts +6 -6
- package/src/index.tsx +16 -0
- package/src/nativeAd/NativeAdView.tsx +4 -2
- package/src/types/AdBannerViewProps.ts +6 -0
- package/src/types/AdInfo.ts +2 -2
- package/src/types/AdProps.ts +1 -1
- 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:
|
|
7
|
+
@objc(isAppOpenAdReady:adUnitKey:resolve:reject:)
|
|
8
8
|
func isAppOpenAdReady(
|
|
9
9
|
requestId: Double,
|
|
10
|
-
|
|
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:
|
|
23
|
+
@objc(loadAppOpenAd:adUnitKey:resolve:reject:)
|
|
24
24
|
func loadAppOpenAd(
|
|
25
25
|
requestId: Double,
|
|
26
|
-
|
|
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,
|
|
31
|
+
let appOpenAdLoader = retrieveAppOpenLoader(requestId: requestId, adUnitKey: adUnitKey)
|
|
32
32
|
appOpenAdLoader.loadAd()
|
|
33
33
|
resolve(Void())
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
@objc(showAppOpenAd:
|
|
36
|
+
@objc(showAppOpenAd:adUnitKey:customData:resolve:reject:)
|
|
37
37
|
func showAppOpenAd(
|
|
38
38
|
requestId: Double,
|
|
39
|
-
|
|
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,
|
|
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(
|
|
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:
|
|
7
|
+
@objc(isInterstitialReady:adUnitKey:resolve:reject:)
|
|
8
8
|
func isInterstitialReady(
|
|
9
9
|
requestId: Double,
|
|
10
|
-
|
|
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:
|
|
23
|
+
@objc(loadInterstitial:adUnitKey:resolve:reject:)
|
|
24
24
|
func loadInterstitial(
|
|
25
25
|
requestId: Double,
|
|
26
|
-
|
|
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,
|
|
31
|
+
let interstitialLoader = retrieveInterstitialLoader(requestId: requestId, adUnitKey: adUnitKey)
|
|
32
32
|
interstitialLoader.loadAd()
|
|
33
33
|
resolve(Void())
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
@objc(showInterstitial:
|
|
36
|
+
@objc(showInterstitial:adUnitKey:resolve:reject:)
|
|
37
37
|
func showInterstitial(
|
|
38
38
|
requestId: Double,
|
|
39
|
-
|
|
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,
|
|
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(
|
|
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:
|
|
7
|
-
func destroyLightPopup(requestId: Double,
|
|
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:
|
|
45
|
-
func isLightPopupReady(requestId: Double,
|
|
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:
|
|
54
|
-
func loadLightPopup(requestId: Double,
|
|
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,
|
|
62
|
+
retrieveLightPopupLoader(requestId: id, adUnitKey: adUnitKey).loadAd()
|
|
63
63
|
resolve(Void())
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
@objc(showLightPopup:
|
|
68
|
-
func showLightPopup(requestId: Double,
|
|
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:
|
|
97
|
-
func setLightPopupAdConfiguration(requestId: Double,
|
|
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,
|
|
138
|
-
let loader = DaroLightPopupAdLoader(unit: DaroAdUnit(
|
|
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:
|
|
4
|
+
@objc(isRewardedAdReady:adUnitKey:resolve:reject:)
|
|
5
5
|
func isRewardedAdReady(
|
|
6
6
|
requestId: Double,
|
|
7
|
-
|
|
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:
|
|
21
|
+
@objc(loadRewardedAd:adUnitKey:resolve:reject:)
|
|
22
22
|
func loadRewardedAd(
|
|
23
23
|
requestId: Double,
|
|
24
|
-
|
|
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,
|
|
29
|
+
let rewardedLoader = retrieveRewardedLoader(requestId: requestId, adUnitKey: adUnitKey)
|
|
30
30
|
rewardedLoader.loadAd()
|
|
31
31
|
resolve(Void())
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
@objc(showRewardedAd:
|
|
34
|
+
@objc(showRewardedAd:adUnitKey:customData:resolve:reject:)
|
|
35
35
|
func showRewardedAd(
|
|
36
36
|
requestId: Double,
|
|
37
|
-
|
|
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,
|
|
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(
|
|
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,
|
|
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(
|
|
116
|
+
func toBody(adUnitKey: String) -> [String: Any] {
|
|
117
117
|
return [
|
|
118
|
-
"
|
|
118
|
+
"adUnitKey": adUnitKey,
|
|
119
119
|
"rewardLabel": self.rewardType,
|
|
120
120
|
"rewardAmount": self.amount,
|
|
121
121
|
]
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
func toBody(requestId: Int,
|
|
125
|
-
var body = self.toBody(
|
|
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
|
}
|