react-native-daro 2.0.8 → 2.1.0
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 +5 -0
- package/android/src/main/java/com/daro/reactnative/DaroRNAdNativeViewManager.kt +5 -0
- package/android/src/main/java/com/daro/reactnative/DaroRNModule.kt +42 -0
- package/android/src/main/java/com/daro/reactnative/event/DaroRNEvent.kt +8 -0
- package/android/src/main/java/com/daro/reactnative/impl/DaroRNPreloadModuleImpl.kt +77 -0
- package/android/src/main/java/com/daro/reactnative/preload/DaroRNPreloadRegistry.kt +57 -0
- package/android/src/main/java/com/daro/reactnative/util/AdInfoUtil.kt +11 -0
- package/android/src/main/java/com/daro/reactnative/view/DaroMediaView.kt +3 -0
- package/android/src/main/java/com/daro/reactnative/view/DaroRNAdBannerViewContainer.kt +29 -8
- package/android/src/main/java/com/daro/reactnative/view/DaroRNAdNativeViewContainer.kt +29 -8
- package/android/src/oldarch/java/com/daro/reactnative/DaroRNModuleSpec.kt +14 -0
- 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+Preload.swift +122 -0
- package/ios/DaroRNModule.mm +6 -0
- package/ios/DaroRNModule.swift +5 -0
- package/ios/Fabric/DaroRNAdBannerComponentView.mm +5 -0
- package/ios/Fabric/DaroRNNativeAdComponentView.mm +5 -0
- package/ios/Paper/DaroRNAdBannerViewManager.m +1 -0
- package/ios/Paper/DaroRNNativeAdViewManager.m +1 -0
- package/ios/Shared/DaroRNBannerAdView.swift +16 -2
- package/ios/Shared/DaroRNNativeAdView.swift +63 -32
- package/ios/Shared/DaroRNPreloadRegistry.swift +54 -0
- package/lib/commonjs/AdBannerView.js +2 -0
- 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/DaroRNAdBannerViewNativeComponent.ts +2 -0
- package/lib/commonjs/DaroRNNativeAdViewNativeComponent.ts +2 -0
- package/lib/commonjs/NativeDaroModule.js.map +1 -1
- package/lib/commonjs/hooks/useAdPreload.js +61 -0
- package/lib/commonjs/hooks/useAdPreload.js.map +1 -0
- package/lib/commonjs/index.js +37 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdView.js +2 -0
- package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
- package/lib/commonjs/types/NativeAdViewProps.js.map +1 -1
- package/lib/module/AdBannerView.js +2 -0
- 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/DaroRNAdBannerViewNativeComponent.ts +2 -0
- package/lib/module/DaroRNNativeAdViewNativeComponent.ts +2 -0
- package/lib/module/NativeDaroModule.js.map +1 -1
- package/lib/module/hooks/useAdPreload.js +56 -0
- package/lib/module/hooks/useAdPreload.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeAd/NativeAdView.js +2 -0
- 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/DaroRNAdBannerViewNativeComponent.d.ts +1 -0
- package/lib/typescript/commonjs/src/DaroRNAdBannerViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts +1 -0
- package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/NativeDaroModule.d.ts +5 -0
- package/lib/typescript/commonjs/src/NativeDaroModule.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/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/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/DaroRNAdBannerViewNativeComponent.d.ts +1 -0
- package/lib/typescript/module/src/DaroRNAdBannerViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts +1 -0
- package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeDaroModule.d.ts +5 -0
- package/lib/typescript/module/src/NativeDaroModule.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/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/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 +2 -0
- package/src/AdPreload.ts +141 -0
- package/src/DaroRNAdBannerViewNativeComponent.ts +2 -0
- package/src/DaroRNNativeAdViewNativeComponent.ts +2 -0
- package/src/NativeDaroModule.ts +17 -0
- package/src/hooks/useAdPreload.ts +82 -0
- package/src/index.tsx +16 -0
- package/src/nativeAd/NativeAdView.tsx +2 -0
- package/src/types/AdBannerViewProps.ts +6 -0
- package/src/types/NativeAdViewProps.ts +6 -0
package/README.md
CHANGED
|
@@ -58,6 +58,6 @@ If an Android Release build fails in a SafeDK or manifest task with a
|
|
|
58
58
|
Configuration Cache error, set Boolean `android.safedkConfigurationCacheWorkaround`
|
|
59
59
|
to `true` in the plugin options and rerun prebuild or EAS Build. `false` disables
|
|
60
60
|
the workaround; omission preserves the existing Gradle value. Generated Android
|
|
61
|
-
builds use SDK 2.0
|
|
61
|
+
builds use SDK 2.1.0 and Gradle plugin 2.0.3. React Native CLI projects can set
|
|
62
62
|
`daro.safedkConfigurationCacheWorkaround=true` in `android/gradle.properties`
|
|
63
|
-
after updating the Gradle plugin to 2.0.
|
|
63
|
+
after updating the Gradle plugin to 2.0.3.
|
package/android/build.gradle
CHANGED
|
@@ -33,7 +33,7 @@ apply plugin: "kotlin-android"
|
|
|
33
33
|
apply plugin: "com.facebook.react"
|
|
34
34
|
|
|
35
35
|
// 통합 daro-sdk 는 AdMob·MAX 미디에이션을 한 아티팩트에 담는다 — 빌드타임 분기가 없다.
|
|
36
|
-
def daroSdkDependency = "so.daro:daro-sdk:2.0
|
|
36
|
+
def daroSdkDependency = "so.daro:daro-sdk:2.1.0"
|
|
37
37
|
def isNewArchitectureEnabled =
|
|
38
38
|
(project.hasProperty("newArchEnabled") && project.property("newArchEnabled").toString().toBoolean()) ||
|
|
39
39
|
(project.hasProperty("react.newArchEnabled") && project.property("react.newArchEnabled").toString().toBoolean())
|
|
@@ -83,6 +83,8 @@ dependencies {
|
|
|
83
83
|
testImplementation daroSdkDependency
|
|
84
84
|
testImplementation "org.robolectric:robolectric:4.16.1"
|
|
85
85
|
testImplementation "io.mockk:mockk:1.13.17"
|
|
86
|
+
// SDK 뷰의 생성자를 건너뛰는 데 쓴다. mockk 의 mockkConstructor 는 Android 뷰 계층에서 테스트 JVM 을 멈춘다.
|
|
87
|
+
testImplementation "org.mockito:mockito-core:5.12.0"
|
|
86
88
|
// Match the existing RN runtime lifecycle floor; daro-sdk supplies runtime
|
|
87
89
|
// classes but its implementation dependencies are not on our compile path.
|
|
88
90
|
compileOnly "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
|
|
@@ -92,6 +92,11 @@ class DaroRNAdBannerViewManager : SimpleViewManager<DaroRNAdBannerViewContainer>
|
|
|
92
92
|
view.loadOnMount = loadOnMount
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
@ReactProp(name = "preloadId")
|
|
96
|
+
override fun setPreloadId(view: DaroRNAdBannerViewContainer, preloadId: String?) {
|
|
97
|
+
view.preloadId = preloadId
|
|
98
|
+
}
|
|
99
|
+
|
|
95
100
|
override fun loadAd(view: DaroRNAdBannerViewContainer) {
|
|
96
101
|
view.loadAd()
|
|
97
102
|
}
|
|
@@ -97,6 +97,11 @@ class DaroRNAdNativeViewManager : ViewGroupManager<DaroRNAdNativeViewContainer>(
|
|
|
97
97
|
view.loadOnMount = loadOnMount
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
@ReactProp(name = "preloadId")
|
|
101
|
+
override fun setPreloadId(view: DaroRNAdNativeViewContainer, preloadId: String?) {
|
|
102
|
+
view.preloadId = preloadId
|
|
103
|
+
}
|
|
104
|
+
|
|
100
105
|
@ReactProp(name = "adChoicesPosition")
|
|
101
106
|
override fun setAdChoicesPosition(view: DaroRNAdNativeViewContainer, value: String?) {
|
|
102
107
|
view.setAdChoicesPosition(value)
|
|
@@ -7,10 +7,12 @@ import com.daro.reactnative.event.AppOpenEvent
|
|
|
7
7
|
import com.daro.reactnative.event.DaroRNEvent
|
|
8
8
|
import com.daro.reactnative.event.InterstitialEvent
|
|
9
9
|
import com.daro.reactnative.event.LightPopupEvent
|
|
10
|
+
import com.daro.reactnative.event.PreloadEvent
|
|
10
11
|
import com.daro.reactnative.event.RewardedEvent
|
|
11
12
|
import com.daro.reactnative.impl.DaroRNBannerViewModuleImpl
|
|
12
13
|
import com.daro.reactnative.impl.DaroRNInterstitialModuleImpl
|
|
13
14
|
import com.daro.reactnative.impl.DaroRNLightPopupModuleImpl
|
|
15
|
+
import com.daro.reactnative.impl.DaroRNPreloadModuleImpl
|
|
14
16
|
import com.daro.reactnative.impl.DaroRNRewardedAdModuleImpl
|
|
15
17
|
import com.daro.reactnative.util.DaroQaProbe
|
|
16
18
|
import com.daro.reactnative.util.EventEmitterUtil
|
|
@@ -200,6 +202,7 @@ class DaroRNModule(reactContext: ReactApplicationContext) :
|
|
|
200
202
|
constants.putAll(daroRNLightPopupModule.getComponents())
|
|
201
203
|
constants.putAll(daroRNAppOpenModule.getComponents())
|
|
202
204
|
constants.putAll(daroRNBannerModule.getComponents())
|
|
205
|
+
constants.putAll(daroRNPreloadModule.getComponents())
|
|
203
206
|
|
|
204
207
|
return constants
|
|
205
208
|
}
|
|
@@ -314,6 +317,7 @@ class DaroRNModule(reactContext: ReactApplicationContext) :
|
|
|
314
317
|
|
|
315
318
|
override fun invalidate() {
|
|
316
319
|
daroRNLightPopupModule.invalidate()
|
|
320
|
+
daroRNPreloadModule.invalidate()
|
|
317
321
|
super.invalidate()
|
|
318
322
|
}
|
|
319
323
|
|
|
@@ -388,4 +392,42 @@ class DaroRNModule(reactContext: ReactApplicationContext) :
|
|
|
388
392
|
|
|
389
393
|
private val daroRNBannerModule: DaroRNBannerModule =
|
|
390
394
|
DaroRNBannerViewModuleImpl(context = reactContext)
|
|
395
|
+
|
|
396
|
+
@OptIn(ExperimentalStdlibApi::class)
|
|
397
|
+
internal abstract class DaroRNPreloadModule(context: ReactContext) : DaroRNComponentModule(context) {
|
|
398
|
+
abstract fun preloadBannerAd(preloadId: String, adUnitKey: String, adFormat: String, promise: Promise)
|
|
399
|
+
abstract fun preloadNativeAd(preloadId: String, adUnitKey: String, promise: Promise)
|
|
400
|
+
abstract fun destroyAdPreload(preloadId: String)
|
|
401
|
+
abstract fun invalidate()
|
|
402
|
+
|
|
403
|
+
override fun getComponents(): MutableMap<String, Any> {
|
|
404
|
+
return PreloadEvent.entries.associate { it.value to it.value }.toMutableMap()
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
private val daroRNPreloadModule: DaroRNPreloadModule = DaroRNPreloadModuleImpl(
|
|
409
|
+
context = reactContext,
|
|
410
|
+
getCurrentActivity = { reactApplicationContext.currentActivity }
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
@ReactMethod
|
|
414
|
+
override fun preloadBannerAd(preloadId: String, adUnitKey: String, adFormat: String, promise: Promise) {
|
|
415
|
+
daroRNPreloadModule.preloadBannerAd(preloadId, adUnitKey, adFormat, promise)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// AdChoices 위치는 Android 에서 뷰의 바인더가 정한다. 광고를 받는 데는 쓰지 않는다.
|
|
419
|
+
@ReactMethod
|
|
420
|
+
override fun preloadNativeAd(
|
|
421
|
+
preloadId: String,
|
|
422
|
+
adUnitKey: String,
|
|
423
|
+
adChoicesPosition: String,
|
|
424
|
+
promise: Promise,
|
|
425
|
+
) {
|
|
426
|
+
daroRNPreloadModule.preloadNativeAd(preloadId, adUnitKey, promise)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
@ReactMethod
|
|
430
|
+
override fun destroyAdPreload(preloadId: String) {
|
|
431
|
+
daroRNPreloadModule.destroyAdPreload(preloadId)
|
|
432
|
+
}
|
|
391
433
|
}
|
|
@@ -57,6 +57,14 @@ internal enum class AppOpenEvent : DaroRNEvent {
|
|
|
57
57
|
get() = name
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
internal enum class PreloadEvent : DaroRNEvent {
|
|
61
|
+
ON_AD_PRELOAD_SUCCESS_EVENT,
|
|
62
|
+
ON_AD_PRELOAD_FAILED_EVENT;
|
|
63
|
+
|
|
64
|
+
override val value: String
|
|
65
|
+
get() = name
|
|
66
|
+
}
|
|
67
|
+
|
|
60
68
|
internal enum class AdViewEvent(
|
|
61
69
|
val registrationName: String,
|
|
62
70
|
override val value: String,
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
package com.daro.reactnative.impl
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import com.daro.reactnative.DaroRNModule
|
|
5
|
+
import com.daro.reactnative.constants.InternalDaroRNBannerSize
|
|
6
|
+
import com.daro.reactnative.event.PreloadEvent
|
|
7
|
+
import com.daro.reactnative.preload.DaroRNPreloadRegistry
|
|
8
|
+
import com.daro.reactnative.util.AdInfoUtil
|
|
9
|
+
import com.facebook.react.bridge.Promise
|
|
10
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
12
|
+
import droom.daro.core.adunit.DaroBannerAdUnit
|
|
13
|
+
import droom.daro.core.adunit.DaroNativeAdUnit
|
|
14
|
+
import droom.daro.core.listener.DaroPreloadListener
|
|
15
|
+
import droom.daro.core.model.DaroAdInfo
|
|
16
|
+
import droom.daro.core.model.DaroError
|
|
17
|
+
import droom.daro.view.DaroBannerAdController
|
|
18
|
+
import droom.daro.view.DaroNativeAdController
|
|
19
|
+
|
|
20
|
+
internal class DaroRNPreloadModuleImpl(
|
|
21
|
+
context: ReactApplicationContext,
|
|
22
|
+
private val getCurrentActivity: () -> Activity?,
|
|
23
|
+
private val registry: DaroRNPreloadRegistry = DaroRNPreloadRegistry.shared,
|
|
24
|
+
) : DaroRNModule.DaroRNPreloadModule(context) {
|
|
25
|
+
|
|
26
|
+
override fun preloadBannerAd(preloadId: String, adUnitKey: String, adFormat: String, promise: Promise) {
|
|
27
|
+
val size = InternalDaroRNBannerSize.fromName(adFormat).toBannerSize()
|
|
28
|
+
?: return promise.reject("INVALID_AD_FORMAT", "Unknown banner ad format: $adFormat")
|
|
29
|
+
preload(preloadId, promise) { activity ->
|
|
30
|
+
val controller = DaroBannerAdController(activity, DaroBannerAdUnit(adUnitKey, bannerSize = size))
|
|
31
|
+
controller.setListener(listener(preloadId, adUnitKey))
|
|
32
|
+
DaroRNPreloadRegistry.Entry(adUnitKey, size.name, controller, { it.preload() }, { it.destroy() })
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override fun preloadNativeAd(preloadId: String, adUnitKey: String, promise: Promise) {
|
|
37
|
+
preload(preloadId, promise) { activity ->
|
|
38
|
+
val controller = DaroNativeAdController(activity, DaroNativeAdUnit(adUnitKey))
|
|
39
|
+
controller.setListener(listener(preloadId, adUnitKey))
|
|
40
|
+
DaroRNPreloadRegistry.Entry(adUnitKey, "", controller, { it.preload() }, { it.destroy() })
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override fun destroyAdPreload(preloadId: String) {
|
|
45
|
+
UiThreadUtil.runOnUiThread { registry.destroy(preloadId) }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override fun invalidate() {
|
|
49
|
+
UiThreadUtil.runOnUiThread { registry.destroyAll() }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 컨트롤러는 Activity 를 받는다. 뷰도 같은 Activity 로 만들어야 받아 둔 광고를 넘겨받는다.
|
|
53
|
+
private fun preload(preloadId: String, promise: Promise, create: (Activity) -> DaroRNPreloadRegistry.Entry<*>) {
|
|
54
|
+
UiThreadUtil.runOnUiThread {
|
|
55
|
+
val activity = getCurrentActivity()
|
|
56
|
+
?: return@runOnUiThread promise.reject("NO_ACTIVITY", "Preload requires a foreground Activity")
|
|
57
|
+
registry.preload(preloadId) { create(activity) }
|
|
58
|
+
promise.resolve(null)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private fun listener(preloadId: String, adUnitKey: String) = object : DaroPreloadListener {
|
|
63
|
+
override fun onPreloadSuccess(adInfo: DaroAdInfo) {
|
|
64
|
+
sendNativeEvent(
|
|
65
|
+
event = PreloadEvent.ON_AD_PRELOAD_SUCCESS_EVENT,
|
|
66
|
+
params = AdInfoUtil.getAdInfo(adUnitKey, adInfo).apply { putString("preloadId", preloadId) },
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override fun onPreloadFail(error: DaroError) {
|
|
71
|
+
sendNativeEvent(
|
|
72
|
+
event = PreloadEvent.ON_AD_PRELOAD_FAILED_EVENT,
|
|
73
|
+
params = AdInfoUtil.getPreloadFailedInfo(adUnitKey, error).apply { putString("preloadId", preloadId) },
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
package com.daro.reactnative.preload
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `preloadId` 로 preload 컨트롤러를 들고 있다가 뷰가 마운트될 때 한 번 넘긴다.
|
|
5
|
+
*
|
|
6
|
+
* - 넘긴 항목은 레지스트리에서 빠진다. 그 뒤의 정리는 가져간 뷰의 몫이다.
|
|
7
|
+
* - 광고 유닛이나 포맷이 뷰와 다르면 넘기지 않고 정리한다 — 뷰는 일반 로드를 한다.
|
|
8
|
+
* - RN 은 Activity 하나 위에서 화면을 바꾸므로 SDK 의 Activity 파괴 정리에 기대지 않는다.
|
|
9
|
+
* 안 쓴 항목은 JS 의 `destroy()` 와 모듈 invalidate 가 정리한다.
|
|
10
|
+
*
|
|
11
|
+
* UI 스레드에서만 부른다.
|
|
12
|
+
*/
|
|
13
|
+
internal class DaroRNPreloadRegistry {
|
|
14
|
+
class Entry<C : Any>(
|
|
15
|
+
val adUnitKey: String,
|
|
16
|
+
/** 같은 유닛 안에서 갈리는 요청 조건 ( 배너 크기 ). 없으면 빈 문자열. */
|
|
17
|
+
val variant: String,
|
|
18
|
+
val controller: C,
|
|
19
|
+
private val onPreload: (C) -> Unit,
|
|
20
|
+
private val onDestroy: (C) -> Unit,
|
|
21
|
+
) {
|
|
22
|
+
fun preload() = onPreload(controller)
|
|
23
|
+
fun destroy() = onDestroy(controller)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private val entries = mutableMapOf<String, Entry<*>>()
|
|
27
|
+
|
|
28
|
+
/** 같은 id 로 다시 부르면 들고 있는 컨트롤러에 다시 요청한다. 중복과 TTL 판정은 SDK 가 한다. */
|
|
29
|
+
fun preload(preloadId: String, create: () -> Entry<*>) {
|
|
30
|
+
val entry = entries[preloadId] ?: create().also { entries[preloadId] = it }
|
|
31
|
+
entry.preload()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fun <C : Any> take(preloadId: String?, adUnitKey: String, variant: String, type: Class<C>): C? {
|
|
35
|
+
if (preloadId.isNullOrEmpty()) return null
|
|
36
|
+
val entry = entries.remove(preloadId) ?: return null
|
|
37
|
+
if (entry.adUnitKey != adUnitKey || entry.variant != variant || !type.isInstance(entry.controller)) {
|
|
38
|
+
entry.destroy()
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
return type.cast(entry.controller)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fun destroy(preloadId: String) {
|
|
45
|
+
entries.remove(preloadId)?.destroy()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fun destroyAll() {
|
|
49
|
+
val remaining = entries.values.toList()
|
|
50
|
+
entries.clear()
|
|
51
|
+
remaining.forEach { it.destroy() }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
companion object {
|
|
55
|
+
val shared = DaroRNPreloadRegistry()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -5,6 +5,7 @@ import com.facebook.react.bridge.WritableMap
|
|
|
5
5
|
import droom.daro.core.model.DaroAdDisplayFailError
|
|
6
6
|
import droom.daro.core.model.DaroAdInfo
|
|
7
7
|
import droom.daro.core.model.DaroAdLoadError
|
|
8
|
+
import droom.daro.core.model.DaroError
|
|
8
9
|
import droom.daro.core.model.DaroRewardedAd
|
|
9
10
|
|
|
10
11
|
internal object AdInfoUtil {
|
|
@@ -55,6 +56,16 @@ internal object AdInfoUtil {
|
|
|
55
56
|
return errInfo
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
// preload 실패는 SDK 의 공통 오류 ( DaroError ) 로 온다. 기존 로드 실패와 같은 모양으로 싣는다.
|
|
60
|
+
fun getPreloadFailedInfo(adUnitKey: String, error: DaroError): WritableMap {
|
|
61
|
+
val errInfo = Arguments.createMap()
|
|
62
|
+
errInfo.putString("adUnitKey", adUnitKey)
|
|
63
|
+
errInfo.putInt("code", error.errorCode)
|
|
64
|
+
errInfo.putString("message", error.errorMessage)
|
|
65
|
+
errInfo.putInt("latencyMillis", 0)
|
|
66
|
+
return errInfo
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
fun getAdDisplayFailedInfo(adUnitKey: String, ad: DaroAdInfo, error: DaroAdDisplayFailError): WritableMap {
|
|
59
70
|
val info = getAdInfo(adUnitKey, ad)
|
|
60
71
|
|
|
@@ -94,6 +94,9 @@ class DaroMediaView(context: Context) : FrameLayout(context) {
|
|
|
94
94
|
for (i in 0 until childCount) {
|
|
95
95
|
val child = getChildAt(i)
|
|
96
96
|
if (child.visibility == GONE) continue
|
|
97
|
+
// 창에 붙지 않은 자식은 재지 않는다. 광고 SDK 는 이 뷰가 창에 붙기 전에 미디어 뷰를 넣고,
|
|
98
|
+
// ComposeView 가 든 미디어는 window 없이 measure 하면 예외를 던진다. 붙은 뒤의 재배치가 처리한다.
|
|
99
|
+
if (!child.isAttachedToWindow) continue
|
|
97
100
|
|
|
98
101
|
forceLayoutRecursive(child)
|
|
99
102
|
child.measure(
|
|
@@ -9,6 +9,7 @@ import android.widget.FrameLayout
|
|
|
9
9
|
import androidx.core.view.children
|
|
10
10
|
import androidx.core.view.isVisible
|
|
11
11
|
import com.daro.reactnative.event.AdViewEvent
|
|
12
|
+
import com.daro.reactnative.preload.DaroRNPreloadRegistry
|
|
12
13
|
import com.daro.reactnative.util.AdInfoUtil
|
|
13
14
|
import com.daro.reactnative.util.EventEmitterUtil.sendNativeViewEvent
|
|
14
15
|
import com.facebook.react.bridge.ReactContext
|
|
@@ -19,6 +20,7 @@ import droom.daro.core.model.DaroAdLoadError
|
|
|
19
20
|
import droom.daro.core.model.DaroBannerSize
|
|
20
21
|
import droom.daro.core.model.DaroViewAd
|
|
21
22
|
import droom.daro.view.DaroAdViewListener
|
|
23
|
+
import droom.daro.view.DaroBannerAdController
|
|
22
24
|
import droom.daro.view.DaroBannerAdView
|
|
23
25
|
|
|
24
26
|
@SuppressLint("ViewConstructor")
|
|
@@ -37,6 +39,10 @@ class DaroRNAdBannerViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
37
39
|
|
|
38
40
|
internal var loadOnMount: Boolean = true
|
|
39
41
|
|
|
42
|
+
/** preload 로 받아 둔 광고의 id. 뷰를 처음 만들 때 한 번만 본다. */
|
|
43
|
+
internal var preloadId: String? = null
|
|
44
|
+
private var preloadController: DaroBannerAdController? = null
|
|
45
|
+
|
|
40
46
|
private var isAdVisible: Boolean = true
|
|
41
47
|
private var isAdPaused: Boolean = false
|
|
42
48
|
private var hasRequestedInitialLoad: Boolean = false
|
|
@@ -51,7 +57,8 @@ class DaroRNAdBannerViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
51
57
|
private val visibleRect = Rect()
|
|
52
58
|
|
|
53
59
|
fun loadAd() {
|
|
54
|
-
|
|
60
|
+
val existing = adView
|
|
61
|
+
(existing ?: buildAdView())?.apply {
|
|
55
62
|
adView = this
|
|
56
63
|
|
|
57
64
|
if (this.parent == null) {
|
|
@@ -63,6 +70,10 @@ class DaroRNAdBannerViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
layoutAdView()
|
|
73
|
+
// 받아 둔 광고를 넘겨받은 새 뷰는 화면에 붙을 때 SDK 가 그 광고를 쓴다. 여기서 loadAd 를
|
|
74
|
+
// 부르면 ( 지금이든, 크기가 준비된 뒤의 재시도든 ) SDK 의 처리가 끝난 뒤에는 새 요청이 되어
|
|
75
|
+
// 받아 둔 광고를 덮어쓴다. 그 뒤의 loadAd 는 재로드이므로 그대로 부른다.
|
|
76
|
+
if (existing == null && preloadController != null) return
|
|
66
77
|
if (!canLoadAd()) {
|
|
67
78
|
if (!hasPendingLoad) {
|
|
68
79
|
pendingLoadRetryCount = 0
|
|
@@ -88,13 +99,21 @@ class DaroRNAdBannerViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
88
99
|
return null
|
|
89
100
|
}
|
|
90
101
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
val bannerSize = adSize!!
|
|
103
|
+
// 받아 둔 광고는 컨트롤러와 같은 Activity 로 만든 뷰에만 넘어온다. 없으면 일반 로드다.
|
|
104
|
+
val activity = context.currentActivity
|
|
105
|
+
val controller = activity?.let {
|
|
106
|
+
DaroRNPreloadRegistry.shared.take(preloadId, adUnitKey, bannerSize.name, DaroBannerAdController::class.java)
|
|
107
|
+
}
|
|
108
|
+
preloadController = controller
|
|
109
|
+
|
|
110
|
+
val bannerView = if (activity != null && controller != null) {
|
|
111
|
+
DaroBannerAdView(activity, controller)
|
|
112
|
+
} else {
|
|
113
|
+
DaroBannerAdView(context, DaroBannerAdUnit(adUnitKey, bannerSize = bannerSize))
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return bannerView.also { view ->
|
|
98
117
|
view.setListener(this)
|
|
99
118
|
view.setOnHierarchyChangeListener(object : ViewGroup.OnHierarchyChangeListener {
|
|
100
119
|
override fun onChildViewAdded(parent: View, child: View) {
|
|
@@ -125,6 +144,8 @@ class DaroRNAdBannerViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
125
144
|
adView?.setOnHierarchyChangeListener(null)
|
|
126
145
|
adView?.destroy()
|
|
127
146
|
adView = null
|
|
147
|
+
preloadController?.destroy()
|
|
148
|
+
preloadController = null
|
|
128
149
|
}
|
|
129
150
|
|
|
130
151
|
fun setAdVisibility(visible: Boolean) {
|
|
@@ -13,6 +13,7 @@ import android.widget.TextView
|
|
|
13
13
|
import androidx.annotation.IdRes
|
|
14
14
|
import androidx.core.view.children
|
|
15
15
|
import com.daro.reactnative.event.AdViewEvent
|
|
16
|
+
import com.daro.reactnative.preload.DaroRNPreloadRegistry
|
|
16
17
|
import com.daro.reactnative.util.AdInfoUtil
|
|
17
18
|
import com.daro.reactnative.util.EventEmitterUtil.sendNativeViewEvent
|
|
18
19
|
import com.facebook.react.bridge.Arguments
|
|
@@ -27,6 +28,7 @@ import droom.daro.core.model.DaroNativeAdChoicePlacement
|
|
|
27
28
|
import droom.daro.core.model.DaroViewAd
|
|
28
29
|
import droom.daro.core.model.NativeAdAssetType
|
|
29
30
|
import droom.daro.view.DaroAdViewListener
|
|
31
|
+
import droom.daro.view.DaroNativeAdController
|
|
30
32
|
import droom.daro.view.DaroNativeAdView
|
|
31
33
|
import kotlin.math.min
|
|
32
34
|
import kotlin.math.roundToInt
|
|
@@ -56,6 +58,11 @@ class DaroRNAdNativeViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
56
58
|
internal var adUnitKey: String = ""
|
|
57
59
|
|
|
58
60
|
internal var loadOnMount: Boolean = true
|
|
61
|
+
|
|
62
|
+
/** preload 로 받아 둔 광고의 id. 뷰를 처음 만들 때 한 번만 본다. */
|
|
63
|
+
internal var preloadId: String? = null
|
|
64
|
+
private var preloadController: DaroNativeAdController? = null
|
|
65
|
+
|
|
59
66
|
private var adChoicesPosition: DaroNativeAdChoicePlacement =
|
|
60
67
|
DaroNativeAdChoicePlacement.BOTTOM_RIGHT
|
|
61
68
|
|
|
@@ -113,7 +120,8 @@ class DaroRNAdNativeViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
113
120
|
pendingLoadAssetViewRetryCount = 0
|
|
114
121
|
captureRegisteredTextSpans()
|
|
115
122
|
|
|
116
|
-
|
|
123
|
+
val existing = adView
|
|
124
|
+
return (existing ?: buildAdView())?.let { view ->
|
|
117
125
|
|
|
118
126
|
adView = view
|
|
119
127
|
|
|
@@ -121,7 +129,10 @@ class DaroRNAdNativeViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
121
129
|
this@DaroRNAdNativeViewContainer.addView(view)
|
|
122
130
|
}
|
|
123
131
|
|
|
124
|
-
|
|
132
|
+
// 받아 둔 광고를 넘겨받은 새 뷰는 화면에 붙을 때 SDK 가 그 광고를 쓴다. 여기서 loadAd 를
|
|
133
|
+
// 부르면 SDK 의 처리가 끝난 뒤에는 새 요청이 되어 받아 둔 광고를 덮어쓴다. 그 뒤의
|
|
134
|
+
// loadAd 는 재로드이므로 그대로 부른다.
|
|
135
|
+
if (existing != null || preloadController == null) view.loadAd()
|
|
125
136
|
isFirstLoad = false
|
|
126
137
|
true
|
|
127
138
|
} ?: false
|
|
@@ -132,12 +143,20 @@ class DaroRNAdNativeViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
132
143
|
return null
|
|
133
144
|
}
|
|
134
145
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
// 받아 둔 광고는 컨트롤러와 같은 Activity 로 만든 뷰에만 넘어온다. 없으면 일반 로드다.
|
|
147
|
+
val activity = context.currentActivity
|
|
148
|
+
val controller = activity?.let {
|
|
149
|
+
DaroRNPreloadRegistry.shared.take(preloadId, adUnitKey, "", DaroNativeAdController::class.java)
|
|
150
|
+
}
|
|
151
|
+
preloadController = controller
|
|
152
|
+
|
|
153
|
+
val nativeView = if (activity != null && controller != null) {
|
|
154
|
+
DaroNativeAdView(activity, controller)
|
|
155
|
+
} else {
|
|
156
|
+
DaroNativeAdView(context, DaroNativeAdUnit(adUnitKey))
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return nativeView.also { view ->
|
|
141
160
|
view.setAdBinder(
|
|
142
161
|
DaroNativeAdBinder
|
|
143
162
|
.Builder(adViewContainer)
|
|
@@ -184,6 +203,8 @@ class DaroRNAdNativeViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
184
203
|
installFallbackAssetViews()
|
|
185
204
|
}
|
|
186
205
|
adView = null
|
|
206
|
+
preloadController?.destroy()
|
|
207
|
+
preloadController = null
|
|
187
208
|
pendingLoadAssetViewRetryCount = 0
|
|
188
209
|
removeAllViews()
|
|
189
210
|
testSpanMap.clear()
|
|
@@ -122,4 +122,18 @@ abstract class DaroRNModuleSpec(reactContext: ReactApplicationContext) :
|
|
|
122
122
|
configuration: ReadableMap,
|
|
123
123
|
promise: Promise,
|
|
124
124
|
)
|
|
125
|
+
|
|
126
|
+
@ReactMethod
|
|
127
|
+
abstract fun preloadBannerAd(preloadId: String, adUnitKey: String, adFormat: String, promise: Promise)
|
|
128
|
+
|
|
129
|
+
@ReactMethod
|
|
130
|
+
abstract fun preloadNativeAd(
|
|
131
|
+
preloadId: String,
|
|
132
|
+
adUnitKey: String,
|
|
133
|
+
adChoicesPosition: String,
|
|
134
|
+
promise: Promise,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
@ReactMethod
|
|
138
|
+
abstract fun destroyAdPreload(preloadId: String)
|
|
125
139
|
}
|
|
@@ -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
|
+
}
|