react-native-daro 2.0.0-rc.1 → 2.0.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 +13 -1
- package/android/build.gradle +12 -1
- package/android/src/main/java/com/daro/reactnative/DaroRNModule.kt +23 -8
- package/android/src/main/java/com/daro/reactnative/DaroSdkBridge.kt +52 -7
- package/android/src/main/java/com/daro/reactnative/event/DaroRNEvent.kt +2 -1
- package/android/src/main/java/com/daro/reactnative/impl/DaroRNLightPopupModuleImpl.kt +86 -73
- package/android/src/main/java/com/daro/reactnative/impl/LightPopupRequest.kt +51 -0
- package/android/src/main/java/com/daro/reactnative/view/DaroRNAdNativeViewContainer.kt +20 -0
- package/android/src/oldarch/java/com/daro/reactnative/DaroRNModuleSpec.kt +6 -0
- package/android/src/test/AndroidManifest.xml +10 -0
- package/android/src/test/java/com/daro/reactnative/DaroSdkBridgeTest.kt +144 -0
- package/android/src/test/java/com/daro/reactnative/impl/LightPopupRequestTest.kt +62 -0
- package/ios/DaroRNModule+LightPopup.swift +130 -102
- package/ios/DaroRNModule+Qa.swift +38 -37
- package/ios/DaroRNModule.mm +2 -0
- package/ios/DaroRNModule.swift +39 -20
- package/ios/Fabric/DaroRNNativeAdComponentView.mm +14 -0
- package/ios/Paper/DaroRNNativeAdViewManager.m +1 -0
- package/ios/Shared/DaroRNAdEventSink.swift +1 -0
- package/ios/Shared/DaroRNInitialization.swift +47 -0
- package/ios/Shared/DaroRNNativeAdView.swift +8 -0
- package/lib/commonjs/DaroRNNativeAdViewNativeComponent.ts +3 -0
- package/lib/commonjs/LightPopupAd.js +15 -1
- package/lib/commonjs/LightPopupAd.js.map +1 -1
- package/lib/commonjs/NativeDaroModule.js.map +1 -1
- package/lib/commonjs/hooks/useLightPopupAd.js +6 -4
- package/lib/commonjs/hooks/useLightPopupAd.js.map +1 -1
- package/lib/commonjs/index.js +16 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdView.js +7 -0
- package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
- package/lib/commonjs/types/NativeAdViewProps.js +21 -0
- package/lib/commonjs/types/NativeAdViewProps.js.map +1 -1
- package/lib/module/DaroRNNativeAdViewNativeComponent.ts +3 -0
- package/lib/module/LightPopupAd.js +15 -1
- package/lib/module/LightPopupAd.js.map +1 -1
- package/lib/module/NativeDaroModule.js.map +1 -1
- package/lib/module/hooks/useLightPopupAd.js +6 -4
- package/lib/module/hooks/useLightPopupAd.js.map +1 -1
- package/lib/module/index.js +15 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeAd/NativeAdView.js +7 -0
- package/lib/module/nativeAd/NativeAdView.js.map +1 -1
- package/lib/module/types/NativeAdViewProps.js +22 -1
- package/lib/module/types/NativeAdViewProps.js.map +1 -1
- package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts +3 -0
- package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/LightPopupAd.d.ts +3 -0
- package/lib/typescript/commonjs/src/LightPopupAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/NativeDaroModule.d.ts +2 -0
- package/lib/typescript/commonjs/src/NativeDaroModule.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +11 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts +2 -0
- package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts +9 -0
- package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts.map +1 -1
- package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts +3 -0
- package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/module/src/LightPopupAd.d.ts +3 -0
- package/lib/typescript/module/src/LightPopupAd.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeDaroModule.d.ts +2 -0
- package/lib/typescript/module/src/NativeDaroModule.d.ts.map +1 -1
- package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +11 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts +2 -0
- package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts.map +1 -1
- package/lib/typescript/module/src/types/NativeAdViewProps.d.ts +9 -0
- package/lib/typescript/module/src/types/NativeAdViewProps.d.ts.map +1 -1
- package/package.json +6 -3
- package/plugin/build/withAndroid.js +2 -2
- package/react-native-daro.podspec +1 -1
- package/src/DaroRNNativeAdViewNativeComponent.ts +3 -0
- package/src/LightPopupAd.ts +18 -1
- package/src/NativeDaroModule.ts +2 -0
- package/src/hooks/useLightPopupAd.ts +6 -4
- package/src/index.tsx +14 -0
- package/src/nativeAd/NativeAdView.tsx +21 -0
- package/src/types/NativeAdViewProps.ts +10 -0
package/README.md
CHANGED
|
@@ -11,14 +11,26 @@ npm install react-native-daro
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
|
-
import { initialize, InterstitialAd } from 'react-native-daro';
|
|
14
|
+
import { initialize, setAppMuted, InterstitialAd } from 'react-native-daro';
|
|
15
15
|
|
|
16
|
+
// Optional: explicitly enable sound. Omit this call to keep the RN default mute.
|
|
17
|
+
// await setAppMuted(false);
|
|
16
18
|
await initialize();
|
|
17
19
|
|
|
18
20
|
const interstitialAd = InterstitialAd.createForAdRequest('AD_UNIT_ID');
|
|
19
21
|
interstitialAd.load();
|
|
20
22
|
```
|
|
21
23
|
|
|
24
|
+
Ads are muted by default in React Native. Use `await setAppMuted(false)` to
|
|
25
|
+
enable sound or `await setAppMuted(true)` to mute again. The latest setting made
|
|
26
|
+
before or during initialization is applied before `initialize()` resolves.
|
|
27
|
+
Always await successful initialization before loading the first ad. Duplicate
|
|
28
|
+
initialization and JS bridge reloads retain the process's explicit setting;
|
|
29
|
+
failed initialization rejects and can be retried without resetting it.
|
|
30
|
+
|
|
31
|
+
The setting follows the native SDK's supported ad and mediation paths. It does
|
|
32
|
+
not guarantee changing already-loaded ads or controlling every network's audio.
|
|
33
|
+
|
|
22
34
|
## Expo Config Plugin
|
|
23
35
|
|
|
24
36
|
For Expo apps, add `react-native-daro` to `plugins`.
|
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.0.1"
|
|
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())
|
|
@@ -66,6 +66,8 @@ android {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
testOptions.unitTests.includeAndroidResources = true
|
|
70
|
+
|
|
69
71
|
lint {
|
|
70
72
|
disable "GradleCompatible"
|
|
71
73
|
}
|
|
@@ -77,6 +79,15 @@ android {
|
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
dependencies {
|
|
82
|
+
testImplementation "junit:junit:4.13.2"
|
|
83
|
+
testImplementation daroSdkDependency
|
|
84
|
+
testImplementation "org.robolectric:robolectric:4.16.1"
|
|
85
|
+
testImplementation "io.mockk:mockk:1.13.17"
|
|
86
|
+
// Match the existing RN runtime lifecycle floor; daro-sdk supplies runtime
|
|
87
|
+
// classes but its implementation dependencies are not on our compile path.
|
|
88
|
+
compileOnly "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
|
|
89
|
+
compileOnly "androidx.lifecycle:lifecycle-process:2.6.2"
|
|
90
|
+
testImplementation "androidx.lifecycle:lifecycle-process:2.6.2"
|
|
80
91
|
implementation "com.facebook.react:react-android"
|
|
81
92
|
compileOnly daroSdkDependency
|
|
82
93
|
// QA 표면(DaroQaProbe)이 벤더 API 를 직접 부른다 — 런타임 클래스는 daro-sdk 가
|
|
@@ -20,7 +20,6 @@ import com.facebook.react.bridge.ReactContext
|
|
|
20
20
|
import com.facebook.react.bridge.ReactMethod
|
|
21
21
|
import com.facebook.react.bridge.ReadableMap
|
|
22
22
|
import com.facebook.react.bridge.WritableMap
|
|
23
|
-
import droom.daro.SDKConfig
|
|
24
23
|
import droom.daro.core.consent.CcpaStatus
|
|
25
24
|
import droom.daro.core.consent.CoppaStatus
|
|
26
25
|
import droom.daro.core.consent.GdprStatus
|
|
@@ -75,14 +74,18 @@ class DaroRNModule(reactContext: ReactApplicationContext) :
|
|
|
75
74
|
|
|
76
75
|
@ReactMethod
|
|
77
76
|
override fun initializeSdk(promise: Promise) {
|
|
78
|
-
DaroSdkBridge.initialize(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
)
|
|
77
|
+
DaroSdkBridge.initialize(context.applicationContext as Application) { error ->
|
|
78
|
+
if (error == null) promise.resolve(null)
|
|
79
|
+
else promise.reject("INIT_ERROR", error.message, error)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
84
82
|
|
|
85
|
-
|
|
83
|
+
@ReactMethod
|
|
84
|
+
override fun setAppMuted(muted: Boolean, promise: Promise) {
|
|
85
|
+
DaroSdkBridge.setAppMuted(muted) { error ->
|
|
86
|
+
if (error == null) promise.resolve(null)
|
|
87
|
+
else promise.reject("MUTE_ERROR", error.message, error)
|
|
88
|
+
}
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
// 상태 출처는 프로세스 수명인 DaroSdkBridge 다 — 모듈 필드로 두면 JS 리로드마다
|
|
@@ -292,6 +295,8 @@ class DaroRNModule(reactContext: ReactApplicationContext) :
|
|
|
292
295
|
internal abstract class DaroRNLightPopupModule(context: ReactContext) :
|
|
293
296
|
DaroRNComponentModule(context) {
|
|
294
297
|
abstract fun isLightPopupReady(requestId: Int, adUnitId: String, promise: Promise)
|
|
298
|
+
abstract fun destroyLightPopup(requestId: Int)
|
|
299
|
+
abstract fun invalidate()
|
|
295
300
|
abstract fun loadLightPopup(requestId: Int, adUnitId: String)
|
|
296
301
|
abstract fun showLightPopup(requestId: Int, adUnitId: String)
|
|
297
302
|
|
|
@@ -307,6 +312,16 @@ class DaroRNModule(reactContext: ReactApplicationContext) :
|
|
|
307
312
|
getCurrentActivity = { reactApplicationContext.currentActivity }
|
|
308
313
|
)
|
|
309
314
|
|
|
315
|
+
override fun invalidate() {
|
|
316
|
+
daroRNLightPopupModule.invalidate()
|
|
317
|
+
super.invalidate()
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
@ReactMethod
|
|
321
|
+
override fun destroyLightPopup(requestId: Double, adUnitId: String) {
|
|
322
|
+
daroRNLightPopupModule.destroyLightPopup(requestId.toInt())
|
|
323
|
+
}
|
|
324
|
+
|
|
310
325
|
@ReactMethod
|
|
311
326
|
override fun isLightPopupReady(requestId: Double, adUnitId: String, promise: Promise) {
|
|
312
327
|
daroRNLightPopupModule.isLightPopupReady(requestId.toInt(), adUnitId, promise)
|
|
@@ -2,6 +2,12 @@ package com.daro.reactnative
|
|
|
2
2
|
|
|
3
3
|
import android.app.Application
|
|
4
4
|
import android.content.Context
|
|
5
|
+
import android.os.Handler
|
|
6
|
+
import android.os.Looper
|
|
7
|
+
import androidx.lifecycle.ProcessLifecycleOwner
|
|
8
|
+
import androidx.lifecycle.lifecycleScope
|
|
9
|
+
import androidx.lifecycle.withStarted
|
|
10
|
+
import kotlinx.coroutines.launch
|
|
5
11
|
import droom.daro.SDKConfig
|
|
6
12
|
import droom.daro.core.consent.CcpaStatus
|
|
7
13
|
import droom.daro.core.consent.CoppaStatus
|
|
@@ -11,7 +17,7 @@ import droom.daro.sdk.Daro
|
|
|
11
17
|
internal object DaroSdkBridge {
|
|
12
18
|
|
|
13
19
|
/**
|
|
14
|
-
* 이 프로세스에서 SDK
|
|
20
|
+
* 이 프로세스에서 SDK 초기화와 마지막 음소거 설정 적용이 끝났나.
|
|
15
21
|
*
|
|
16
22
|
* **모듈 인스턴스가 아니라 여기(프로세스 수명 object)가 갖는다.** 모듈은
|
|
17
23
|
* ReactContext 수명이라 JS 리로드마다 새로 생기는데, 네이티브 SDK 는 그대로 서 있다.
|
|
@@ -22,12 +28,51 @@ internal object DaroSdkBridge {
|
|
|
22
28
|
var isInitialized: Boolean = false
|
|
23
29
|
private set
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
// Main-thread confined process state: ReactContext/JS reload must not reset it.
|
|
32
|
+
private val main = Handler(Looper.getMainLooper())
|
|
33
|
+
private var appMuted = true
|
|
34
|
+
private val initWaiters = mutableListOf<(Exception?) -> Unit>()
|
|
35
|
+
|
|
36
|
+
fun initialize(application: Application, completion: (Exception?) -> Unit) {
|
|
37
|
+
main.post {
|
|
38
|
+
if (isInitialized) {
|
|
39
|
+
completion(null)
|
|
40
|
+
return@post
|
|
41
|
+
}
|
|
42
|
+
initWaiters.add(completion)
|
|
43
|
+
if (initWaiters.size > 1) return@post
|
|
44
|
+
|
|
45
|
+
val owner = ProcessLifecycleOwner.get()
|
|
46
|
+
owner.lifecycleScope.launch {
|
|
47
|
+
val error = try {
|
|
48
|
+
owner.lifecycle.withStarted {}
|
|
49
|
+
val config = SDKConfig.Builder().setDebugMode(false).setAppMuted(appMuted).build()
|
|
50
|
+
check(Daro.initAsync(application, config)) { "Daro Android SDK initialization failed" }
|
|
51
|
+
// An explicit value received while init was suspended wins over config.
|
|
52
|
+
Daro.setAppMuted(appMuted)
|
|
53
|
+
isInitialized = true
|
|
54
|
+
null
|
|
55
|
+
} catch (error: Exception) {
|
|
56
|
+
error
|
|
57
|
+
}
|
|
58
|
+
val waiters = initWaiters.toList()
|
|
59
|
+
initWaiters.clear() // Failure permits retry, retaining the user's setting.
|
|
60
|
+
waiters.forEach { it(error) }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fun setAppMuted(muted: Boolean, completion: (Exception?) -> Unit) {
|
|
66
|
+
main.post {
|
|
67
|
+
val error = try {
|
|
68
|
+
appMuted = muted
|
|
69
|
+
if (isInitialized) Daro.setAppMuted(muted)
|
|
70
|
+
null
|
|
71
|
+
} catch (error: Exception) {
|
|
72
|
+
error
|
|
73
|
+
}
|
|
74
|
+
completion(error)
|
|
75
|
+
}
|
|
31
76
|
}
|
|
32
77
|
|
|
33
78
|
fun openDebugger(context: Context) {
|
|
@@ -64,5 +64,6 @@ internal enum class AdViewEvent(
|
|
|
64
64
|
ON_AD_CLICKED("onAdClickedEvent", "topAdClickedEvent"),
|
|
65
65
|
ON_AD_FAILED_TO_LOAD("onAdLoadFailedEvent", "topAdLoadFailedEvent"),
|
|
66
66
|
ON_AD_IMPRESSION("onAdImpressionRecordedEvent", "topAdImpressionRecordedEvent"),
|
|
67
|
-
ON_AD_LOADED("onAdLoadedEvent", "topAdLoadedEvent")
|
|
67
|
+
ON_AD_LOADED("onAdLoadedEvent", "topAdLoadedEvent"),
|
|
68
|
+
ON_NATIVE_ASSETS_LOADED("onNativeAdAssetLoadedEvent", "topNativeAdAssetLoadedEvent");
|
|
68
69
|
}
|
|
@@ -5,6 +5,7 @@ import androidx.core.graphics.toColorInt
|
|
|
5
5
|
import com.daro.reactnative.DaroRNModule
|
|
6
6
|
import com.daro.reactnative.event.LightPopupEvent
|
|
7
7
|
import com.daro.reactnative.util.AdInfoUtil
|
|
8
|
+
import com.facebook.react.bridge.LifecycleEventListener
|
|
8
9
|
import com.facebook.react.bridge.Promise
|
|
9
10
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
10
11
|
import com.facebook.react.bridge.ReadableMap
|
|
@@ -21,22 +22,43 @@ import droom.daro.loader.DaroLightPopupAdLoader
|
|
|
21
22
|
internal class DaroRNLightPopupModuleImpl(
|
|
22
23
|
context: ReactApplicationContext,
|
|
23
24
|
private val getCurrentActivity: () -> Activity?,
|
|
24
|
-
) : DaroRNModule.DaroRNLightPopupModule(context) {
|
|
25
|
+
) : DaroRNModule.DaroRNLightPopupModule(context), LifecycleEventListener {
|
|
25
26
|
|
|
26
27
|
private val currentActivity: Activity?
|
|
27
28
|
get() = getCurrentActivity()
|
|
28
29
|
|
|
29
|
-
private val
|
|
30
|
+
private val requests = mutableMapOf<Int, LightPopupRequest<DaroLightPopupAd>>()
|
|
31
|
+
private var invalidated = false
|
|
32
|
+
|
|
33
|
+
init { context.addLifecycleEventListener(this) }
|
|
30
34
|
private val optionMap: MutableMap<Int, DaroLightPopupAdOptions> = mutableMapOf()
|
|
31
|
-
private val loaderMap: MutableMap<Int, DaroLightPopupAdLoader> = mutableMapOf()
|
|
32
35
|
|
|
33
36
|
override fun isLightPopupReady(requestId: Int, adUnitId: String, promise: Promise) {
|
|
34
|
-
promise.resolve(
|
|
37
|
+
context.runOnUiQueueThread { promise.resolve(requests[requestId]?.isReady == true) }
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
override fun loadLightPopup(requestId: Int, adUnitId: String) {
|
|
38
41
|
context.runOnUiQueueThread {
|
|
39
|
-
|
|
42
|
+
if (invalidated) return@runOnUiQueueThread
|
|
43
|
+
requests.remove(requestId)?.destroy()
|
|
44
|
+
val loader = DaroLightPopupAdLoader(
|
|
45
|
+
context, DaroLightPopupAdUnit(adUnitId, optionMap[requestId] ?: DaroLightPopupAdOptions())
|
|
46
|
+
)
|
|
47
|
+
val request = LightPopupRequest(loader::destroy, DaroLightPopupAd::destroy)
|
|
48
|
+
requests[requestId] = request
|
|
49
|
+
loader.setListener(object : DaroLightPopupAdLoaderListener {
|
|
50
|
+
override fun onAdLoadSuccess(ad: DaroLightPopupAd, responseInfo: DaroAdInfo) {
|
|
51
|
+
if (!request.accept(ad)) return
|
|
52
|
+
sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_LOADED_EVENT,
|
|
53
|
+
AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo))
|
|
54
|
+
}
|
|
55
|
+
override fun onAdLoadFail(err: DaroAdLoadError) {
|
|
56
|
+
if (!request.active) return
|
|
57
|
+
sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_LOAD_FAILED_EVENT,
|
|
58
|
+
AdInfoUtil.getAdLoadFailedInfo(requestId, adUnitId, err))
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
loader.load()
|
|
40
62
|
}
|
|
41
63
|
}
|
|
42
64
|
|
|
@@ -67,84 +89,75 @@ internal class DaroRNLightPopupModuleImpl(
|
|
|
67
89
|
)
|
|
68
90
|
}
|
|
69
91
|
|
|
70
|
-
|
|
92
|
+
context.runOnUiQueueThread {
|
|
93
|
+
if (!invalidated) optionMap[requestId] = newOption
|
|
94
|
+
}
|
|
71
95
|
}
|
|
72
96
|
|
|
73
97
|
override fun showLightPopup(requestId: Int, adUnitId: String) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
override fun onFailedToShow(ad: DaroAdInfo, error: DaroAdDisplayFailError) {
|
|
86
|
-
sendNativeEvent(
|
|
87
|
-
event = LightPopupEvent.ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT,
|
|
88
|
-
params = AdInfoUtil.getAdDisplayFailedInfo(requestId, adUnitId, ad, error),
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
override fun onShown(ad: DaroAdInfo) {
|
|
93
|
-
sendNativeEvent(
|
|
94
|
-
event = LightPopupEvent.ON_LIGHTPOPUP_DISPLAYED_EVENT,
|
|
95
|
-
params = AdInfoUtil.getAdInfo(requestId, adUnitId, ad),
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
lightpopupAdMap.remove(requestId)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
override fun onAdClicked(responseInfo: DaroAdInfo) {
|
|
102
|
-
sendNativeEvent(
|
|
103
|
-
event = LightPopupEvent.ON_LIGHTPOPUP_CLICKED_EVENT,
|
|
104
|
-
params = AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo),
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
override fun onAdImpression(responseInfo: DaroAdInfo) {
|
|
109
|
-
sendNativeEvent(
|
|
110
|
-
event = LightPopupEvent.ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED,
|
|
111
|
-
params = AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo),
|
|
112
|
-
)
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
show(it)
|
|
98
|
+
context.runOnUiQueueThread {
|
|
99
|
+
val activity = currentActivity ?: return@runOnUiQueueThread
|
|
100
|
+
val request = requests[requestId] ?: return@runOnUiQueueThread
|
|
101
|
+
val popup = request.takeForPresentation() ?: return@runOnUiQueueThread
|
|
102
|
+
popup.setListener(object : DaroLightPopupAdListener {
|
|
103
|
+
override fun onDismiss(ad: DaroAdInfo) {
|
|
104
|
+
if (!request.ownsPresentation(popup)) return
|
|
105
|
+
request.finishPresentation(popup)
|
|
106
|
+
sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_HIDDEN_EVENT,
|
|
107
|
+
AdInfoUtil.getAdInfo(requestId, adUnitId, ad))
|
|
117
108
|
}
|
|
118
|
-
|
|
109
|
+
override fun onFailedToShow(ad: DaroAdInfo, error: DaroAdDisplayFailError) {
|
|
110
|
+
if (!request.ownsPresentation(popup)) return
|
|
111
|
+
request.finishPresentation(popup)
|
|
112
|
+
sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT,
|
|
113
|
+
AdInfoUtil.getAdDisplayFailedInfo(requestId, adUnitId, ad, error))
|
|
114
|
+
}
|
|
115
|
+
override fun onShown(ad: DaroAdInfo) {
|
|
116
|
+
if (!request.ownsPresentation(popup)) return
|
|
117
|
+
sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_DISPLAYED_EVENT,
|
|
118
|
+
AdInfoUtil.getAdInfo(requestId, adUnitId, ad))
|
|
119
|
+
}
|
|
120
|
+
override fun onAdClicked(responseInfo: DaroAdInfo) {
|
|
121
|
+
if (!request.ownsPresentation(popup)) return
|
|
122
|
+
sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_CLICKED_EVENT,
|
|
123
|
+
AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo))
|
|
124
|
+
}
|
|
125
|
+
override fun onAdImpression(responseInfo: DaroAdInfo) {
|
|
126
|
+
if (!request.ownsPresentation(popup)) return
|
|
127
|
+
sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED,
|
|
128
|
+
AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo))
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
popup.show(activity)
|
|
119
132
|
}
|
|
120
133
|
}
|
|
121
134
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
it.setListener(object : DaroLightPopupAdLoaderListener {
|
|
129
|
-
override fun onAdLoadSuccess(ad: DaroLightPopupAd, responseInfo: DaroAdInfo) {
|
|
130
|
-
lightpopupAdMap[requestId] = ad
|
|
131
|
-
sendNativeEvent(
|
|
132
|
-
event = LightPopupEvent.ON_LIGHTPOPUP_LOADED_EVENT,
|
|
133
|
-
params = AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo),
|
|
134
|
-
)
|
|
135
|
-
}
|
|
135
|
+
override fun destroyLightPopup(requestId: Int) {
|
|
136
|
+
context.runOnUiQueueThread {
|
|
137
|
+
requests.remove(requestId)?.destroy()
|
|
138
|
+
optionMap.remove(requestId)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
136
141
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
})
|
|
142
|
+
override fun invalidate() {
|
|
143
|
+
context.removeLifecycleEventListener(this)
|
|
144
|
+
context.runOnUiQueueThread {
|
|
145
|
+
invalidated = true
|
|
146
|
+
clearRequests()
|
|
144
147
|
}
|
|
145
148
|
}
|
|
146
149
|
|
|
147
|
-
private fun
|
|
148
|
-
|
|
150
|
+
private fun clearRequests() {
|
|
151
|
+
val owned = requests.values.toList()
|
|
152
|
+
requests.clear()
|
|
153
|
+
optionMap.clear()
|
|
154
|
+
owned.forEach { it.destroy() }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
override fun onHostDestroy() {
|
|
158
|
+
// RN configuration changes do not destroy the host Activity; native layout handles rotation.
|
|
159
|
+
context.runOnUiQueueThread { clearRequests() }
|
|
149
160
|
}
|
|
161
|
+
override fun onHostResume() = Unit
|
|
162
|
+
override fun onHostPause() = Unit
|
|
150
163
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
package com.daro.reactnative.impl
|
|
2
|
+
|
|
3
|
+
/** Owns one native load and presentation. All access runs on the UI thread. */
|
|
4
|
+
internal class LightPopupRequest<Ad : Any>(
|
|
5
|
+
private val cancelLoad: () -> Unit,
|
|
6
|
+
private val destroyAd: (Ad) -> Unit,
|
|
7
|
+
) {
|
|
8
|
+
var active = true
|
|
9
|
+
private set
|
|
10
|
+
private var loaded: Ad? = null
|
|
11
|
+
private var presented: Ad? = null
|
|
12
|
+
val isReady: Boolean get() = active && loaded != null && presented == null
|
|
13
|
+
|
|
14
|
+
fun accept(ad: Ad): Boolean {
|
|
15
|
+
if (!active) {
|
|
16
|
+
destroyAd(ad)
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
loaded?.let(destroyAd)
|
|
20
|
+
loaded = ad
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fun takeForPresentation(): Ad? {
|
|
25
|
+
if (!isReady) return null
|
|
26
|
+
return loaded?.also {
|
|
27
|
+
loaded = null
|
|
28
|
+
presented = it
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fun ownsPresentation(ad: Ad): Boolean = active && presented === ad
|
|
33
|
+
|
|
34
|
+
fun finishPresentation(ad: Ad) {
|
|
35
|
+
if (!ownsPresentation(ad)) return
|
|
36
|
+
presented = null
|
|
37
|
+
destroyAd(ad)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fun destroy() {
|
|
41
|
+
if (!active) return
|
|
42
|
+
active = false
|
|
43
|
+
val ready = loaded
|
|
44
|
+
val showing = presented
|
|
45
|
+
loaded = null
|
|
46
|
+
presented = null
|
|
47
|
+
cancelLoad()
|
|
48
|
+
ready?.let(destroyAd)
|
|
49
|
+
showing?.let(destroyAd)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -15,6 +15,7 @@ import androidx.core.view.children
|
|
|
15
15
|
import com.daro.reactnative.event.AdViewEvent
|
|
16
16
|
import com.daro.reactnative.util.AdInfoUtil
|
|
17
17
|
import com.daro.reactnative.util.EventEmitterUtil.sendNativeViewEvent
|
|
18
|
+
import com.facebook.react.bridge.Arguments
|
|
18
19
|
import com.facebook.react.bridge.ReactContext
|
|
19
20
|
import com.facebook.react.views.text.ReactTextView
|
|
20
21
|
import com.facebook.react.views.view.ReactViewGroup
|
|
@@ -24,6 +25,7 @@ import droom.daro.core.model.DaroAdLoadError
|
|
|
24
25
|
import droom.daro.core.model.DaroNativeAdBinder
|
|
25
26
|
import droom.daro.core.model.DaroNativeAdChoicePlacement
|
|
26
27
|
import droom.daro.core.model.DaroViewAd
|
|
28
|
+
import droom.daro.core.model.NativeAdAssetType
|
|
27
29
|
import droom.daro.view.DaroAdViewListener
|
|
28
30
|
import droom.daro.view.DaroNativeAdView
|
|
29
31
|
import kotlin.math.min
|
|
@@ -194,6 +196,24 @@ class DaroRNAdNativeViewContainer(val context: ReactContext) : ReactViewGroup(co
|
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
198
|
|
|
199
|
+
override fun onNativeAdAssetLoaded(assetTypes: Set<NativeAdAssetType>) {
|
|
200
|
+
if (isDestroyed) return
|
|
201
|
+
val values = Arguments.createArray()
|
|
202
|
+
assetTypes.forEach { type ->
|
|
203
|
+
values.pushString(when (type.name) {
|
|
204
|
+
"TITLE" -> "title"
|
|
205
|
+
"BODY" -> "body"
|
|
206
|
+
"ICON" -> "icon"
|
|
207
|
+
"MEDIA" -> "media"
|
|
208
|
+
"CALL_TO_ACTION" -> "callToAction"
|
|
209
|
+
"ADVERTISER" -> "advertiser"
|
|
210
|
+
else -> type.name.lowercase()
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
sendNativeViewEvent(context, AdViewEvent.ON_NATIVE_ASSETS_LOADED,
|
|
214
|
+
Arguments.createMap().apply { putArray("assetTypes", values) })
|
|
215
|
+
}
|
|
216
|
+
|
|
197
217
|
override fun onAdLoadSuccess(
|
|
198
218
|
ad: DaroViewAd,
|
|
199
219
|
adInfo: DaroAdInfo,
|
|
@@ -27,6 +27,9 @@ abstract class DaroRNModuleSpec(reactContext: ReactApplicationContext) :
|
|
|
27
27
|
@ReactMethod
|
|
28
28
|
abstract fun initializeSdk(promise: Promise)
|
|
29
29
|
|
|
30
|
+
@ReactMethod
|
|
31
|
+
abstract fun setAppMuted(muted: Boolean, promise: Promise)
|
|
32
|
+
|
|
30
33
|
@ReactMethod
|
|
31
34
|
abstract fun setUserId(userId: String, promise: Promise)
|
|
32
35
|
|
|
@@ -100,6 +103,9 @@ abstract class DaroRNModuleSpec(reactContext: ReactApplicationContext) :
|
|
|
100
103
|
promise: Promise,
|
|
101
104
|
)
|
|
102
105
|
|
|
106
|
+
@ReactMethod
|
|
107
|
+
abstract fun destroyLightPopup(requestId: Double, adUnitId: String)
|
|
108
|
+
|
|
103
109
|
@ReactMethod
|
|
104
110
|
abstract fun isLightPopupReady(requestId: Double, adUnitId: String, promise: Promise)
|
|
105
111
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
xmlns:tools="http://schemas.android.com/tools">
|
|
3
|
+
<application>
|
|
4
|
+
<!-- Unit tests mock Daro; they must not initialize mediation SDKs. -->
|
|
5
|
+
<meta-data android:name="DARO_APP_KEY" tools:node="remove" />
|
|
6
|
+
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" tools:node="remove" />
|
|
7
|
+
<meta-data android:name="APPLOVIN_KEY" tools:node="remove" />
|
|
8
|
+
<provider android:name="com.google.android.gms.ads.MobileAdsInitProvider" tools:node="remove" />
|
|
9
|
+
</application>
|
|
10
|
+
</manifest>
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
package com.daro.reactnative
|
|
2
|
+
|
|
3
|
+
import android.os.Looper
|
|
4
|
+
import androidx.lifecycle.Lifecycle
|
|
5
|
+
import androidx.lifecycle.LifecycleRegistry
|
|
6
|
+
import androidx.lifecycle.ProcessLifecycleOwner
|
|
7
|
+
import droom.daro.SDKConfig
|
|
8
|
+
import droom.daro.sdk.Daro
|
|
9
|
+
import io.mockk.*
|
|
10
|
+
import kotlinx.coroutines.CompletableDeferred
|
|
11
|
+
import org.junit.After
|
|
12
|
+
import org.junit.Assert.*
|
|
13
|
+
import org.junit.Before
|
|
14
|
+
import org.junit.Test
|
|
15
|
+
import org.junit.runner.RunWith
|
|
16
|
+
import org.robolectric.RobolectricTestRunner
|
|
17
|
+
import org.robolectric.RuntimeEnvironment
|
|
18
|
+
import org.robolectric.Shadows.shadowOf
|
|
19
|
+
import org.robolectric.annotation.Config
|
|
20
|
+
|
|
21
|
+
@RunWith(RobolectricTestRunner::class)
|
|
22
|
+
@Config(sdk = [28], manifest = Config.NONE)
|
|
23
|
+
class DaroSdkBridgeTest {
|
|
24
|
+
private lateinit var result: CompletableDeferred<Boolean>
|
|
25
|
+
private val muted = mutableListOf<Boolean>()
|
|
26
|
+
private var completed = 0
|
|
27
|
+
private var failure: Exception? = null
|
|
28
|
+
private lateinit var config: SDKConfig
|
|
29
|
+
|
|
30
|
+
@Before fun setUp() {
|
|
31
|
+
// Robolectric reuses the sandbox's Kotlin object across test methods.
|
|
32
|
+
// Each scenario starts a fresh process; reloads within one scenario do not.
|
|
33
|
+
for ((name, value) in listOf("isInitialized" to false, "appMuted" to true)) {
|
|
34
|
+
DaroSdkBridge::class.java.getDeclaredField(name).apply {
|
|
35
|
+
isAccessible = true
|
|
36
|
+
setBoolean(null, value)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
DaroSdkBridge::class.java.getDeclaredField("initWaiters").apply {
|
|
40
|
+
isAccessible = true
|
|
41
|
+
(get(null) as MutableList<*>).clear()
|
|
42
|
+
}
|
|
43
|
+
mockkObject(Daro)
|
|
44
|
+
result = CompletableDeferred()
|
|
45
|
+
coEvery { Daro.initAsync(any(), any()) } coAnswers {
|
|
46
|
+
config = secondArg()
|
|
47
|
+
result.await()
|
|
48
|
+
}
|
|
49
|
+
every { Daro.setAppMuted(any()) } answers { muted.add(firstArg()); Unit }
|
|
50
|
+
(ProcessLifecycleOwner.get().lifecycle as LifecycleRegistry).currentState = Lifecycle.State.STARTED
|
|
51
|
+
}
|
|
52
|
+
@After fun tearDown() { unmockkAll() }
|
|
53
|
+
private fun idle() = shadowOf(Looper.getMainLooper()).idle()
|
|
54
|
+
private fun initialize() {
|
|
55
|
+
DaroSdkBridge.initialize(RuntimeEnvironment.getApplication()) {
|
|
56
|
+
completed++
|
|
57
|
+
failure = it
|
|
58
|
+
if (it == null) {
|
|
59
|
+
assertTrue(DaroSdkBridge.isInitialized)
|
|
60
|
+
assertTrue(muted.isNotEmpty()) // first consumer load happens after mute
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
idle()
|
|
64
|
+
}
|
|
65
|
+
private fun mute(value: Boolean) {
|
|
66
|
+
DaroSdkBridge.setAppMuted(value) { assertNull(it) }
|
|
67
|
+
idle()
|
|
68
|
+
}
|
|
69
|
+
private fun succeed() { result.complete(true); idle() }
|
|
70
|
+
|
|
71
|
+
@Test fun defaultMutedOnlyCompletesAfterNativeSuccessAndApply() {
|
|
72
|
+
initialize()
|
|
73
|
+
assertFalse(DaroSdkBridge.isInitialized)
|
|
74
|
+
assertEquals(0, completed)
|
|
75
|
+
assertTrue(config.setAppMuted)
|
|
76
|
+
succeed()
|
|
77
|
+
assertEquals(listOf(true), muted)
|
|
78
|
+
assertEquals(1, completed)
|
|
79
|
+
assertNull(failure)
|
|
80
|
+
}
|
|
81
|
+
@Test fun explicitFalseBeforeInitializationWins() {
|
|
82
|
+
mute(false)
|
|
83
|
+
initialize()
|
|
84
|
+
assertFalse(config.setAppMuted)
|
|
85
|
+
succeed()
|
|
86
|
+
assertEquals(listOf(false), muted)
|
|
87
|
+
}
|
|
88
|
+
@Test fun latestSettingDuringInitWinsAndDuplicateDoesNotRestartOrReset() {
|
|
89
|
+
mute(false)
|
|
90
|
+
initialize()
|
|
91
|
+
initialize()
|
|
92
|
+
mute(true)
|
|
93
|
+
mute(false)
|
|
94
|
+
mute(true)
|
|
95
|
+
assertEquals(0, completed)
|
|
96
|
+
succeed()
|
|
97
|
+
assertEquals(listOf(true), muted)
|
|
98
|
+
assertEquals(2, completed)
|
|
99
|
+
mute(false)
|
|
100
|
+
initialize() // same process after JS reload
|
|
101
|
+
assertEquals(3, completed)
|
|
102
|
+
assertEquals(listOf(true, false), muted)
|
|
103
|
+
coVerify(exactly = 1) { Daro.initAsync(any(), any()) }
|
|
104
|
+
}
|
|
105
|
+
@Test fun falseFailureAllowsRetryAndRetainsExplicitValue() {
|
|
106
|
+
initialize()
|
|
107
|
+
mute(false)
|
|
108
|
+
result.complete(false)
|
|
109
|
+
idle()
|
|
110
|
+
assertFalse(DaroSdkBridge.isInitialized)
|
|
111
|
+
assertNotNull(failure)
|
|
112
|
+
assertTrue(muted.isEmpty())
|
|
113
|
+
result = CompletableDeferred()
|
|
114
|
+
initialize()
|
|
115
|
+
assertFalse(config.setAppMuted)
|
|
116
|
+
succeed()
|
|
117
|
+
assertNull(failure)
|
|
118
|
+
assertEquals(2, completed)
|
|
119
|
+
assertEquals(listOf(false), muted)
|
|
120
|
+
}
|
|
121
|
+
@Test fun nativeExceptionRejectsAllWaitersWithoutSuccess() {
|
|
122
|
+
initialize()
|
|
123
|
+
initialize()
|
|
124
|
+
result.completeExceptionally(IllegalStateException("init failed"))
|
|
125
|
+
idle()
|
|
126
|
+
assertFalse(DaroSdkBridge.isInitialized)
|
|
127
|
+
assertEquals(2, completed)
|
|
128
|
+
assertEquals("init failed", failure?.message)
|
|
129
|
+
assertTrue(muted.isEmpty())
|
|
130
|
+
}
|
|
131
|
+
@Test fun backgroundWaitsForForegroundAndLatestSetting() {
|
|
132
|
+
val lifecycle = ProcessLifecycleOwner.get().lifecycle as LifecycleRegistry
|
|
133
|
+
lifecycle.currentState = Lifecycle.State.CREATED
|
|
134
|
+
initialize()
|
|
135
|
+
mute(false)
|
|
136
|
+
coVerify(exactly = 0) { Daro.initAsync(any(), any()) }
|
|
137
|
+
assertEquals(0, completed)
|
|
138
|
+
lifecycle.currentState = Lifecycle.State.STARTED
|
|
139
|
+
idle()
|
|
140
|
+
assertFalse(config.setAppMuted)
|
|
141
|
+
succeed()
|
|
142
|
+
assertEquals(listOf(false), muted)
|
|
143
|
+
}
|
|
144
|
+
}
|