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.
Files changed (81) hide show
  1. package/README.md +13 -1
  2. package/android/build.gradle +12 -1
  3. package/android/src/main/java/com/daro/reactnative/DaroRNModule.kt +23 -8
  4. package/android/src/main/java/com/daro/reactnative/DaroSdkBridge.kt +52 -7
  5. package/android/src/main/java/com/daro/reactnative/event/DaroRNEvent.kt +2 -1
  6. package/android/src/main/java/com/daro/reactnative/impl/DaroRNLightPopupModuleImpl.kt +86 -73
  7. package/android/src/main/java/com/daro/reactnative/impl/LightPopupRequest.kt +51 -0
  8. package/android/src/main/java/com/daro/reactnative/view/DaroRNAdNativeViewContainer.kt +20 -0
  9. package/android/src/oldarch/java/com/daro/reactnative/DaroRNModuleSpec.kt +6 -0
  10. package/android/src/test/AndroidManifest.xml +10 -0
  11. package/android/src/test/java/com/daro/reactnative/DaroSdkBridgeTest.kt +144 -0
  12. package/android/src/test/java/com/daro/reactnative/impl/LightPopupRequestTest.kt +62 -0
  13. package/ios/DaroRNModule+LightPopup.swift +130 -102
  14. package/ios/DaroRNModule+Qa.swift +38 -37
  15. package/ios/DaroRNModule.mm +2 -0
  16. package/ios/DaroRNModule.swift +39 -20
  17. package/ios/Fabric/DaroRNNativeAdComponentView.mm +14 -0
  18. package/ios/Paper/DaroRNNativeAdViewManager.m +1 -0
  19. package/ios/Shared/DaroRNAdEventSink.swift +1 -0
  20. package/ios/Shared/DaroRNInitialization.swift +47 -0
  21. package/ios/Shared/DaroRNNativeAdView.swift +8 -0
  22. package/lib/commonjs/DaroRNNativeAdViewNativeComponent.ts +3 -0
  23. package/lib/commonjs/LightPopupAd.js +15 -1
  24. package/lib/commonjs/LightPopupAd.js.map +1 -1
  25. package/lib/commonjs/NativeDaroModule.js.map +1 -1
  26. package/lib/commonjs/hooks/useLightPopupAd.js +6 -4
  27. package/lib/commonjs/hooks/useLightPopupAd.js.map +1 -1
  28. package/lib/commonjs/index.js +16 -0
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/commonjs/nativeAd/NativeAdView.js +7 -0
  31. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  32. package/lib/commonjs/types/NativeAdViewProps.js +21 -0
  33. package/lib/commonjs/types/NativeAdViewProps.js.map +1 -1
  34. package/lib/module/DaroRNNativeAdViewNativeComponent.ts +3 -0
  35. package/lib/module/LightPopupAd.js +15 -1
  36. package/lib/module/LightPopupAd.js.map +1 -1
  37. package/lib/module/NativeDaroModule.js.map +1 -1
  38. package/lib/module/hooks/useLightPopupAd.js +6 -4
  39. package/lib/module/hooks/useLightPopupAd.js.map +1 -1
  40. package/lib/module/index.js +15 -0
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/nativeAd/NativeAdView.js +7 -0
  43. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  44. package/lib/module/types/NativeAdViewProps.js +22 -1
  45. package/lib/module/types/NativeAdViewProps.js.map +1 -1
  46. package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts +3 -0
  47. package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
  48. package/lib/typescript/commonjs/src/LightPopupAd.d.ts +3 -0
  49. package/lib/typescript/commonjs/src/LightPopupAd.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/src/NativeDaroModule.d.ts +2 -0
  51. package/lib/typescript/commonjs/src/NativeDaroModule.d.ts.map +1 -1
  52. package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/src/index.d.ts +11 -0
  54. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  55. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts +2 -0
  56. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts.map +1 -1
  57. package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts +9 -0
  58. package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts.map +1 -1
  59. package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts +3 -0
  60. package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
  61. package/lib/typescript/module/src/LightPopupAd.d.ts +3 -0
  62. package/lib/typescript/module/src/LightPopupAd.d.ts.map +1 -1
  63. package/lib/typescript/module/src/NativeDaroModule.d.ts +2 -0
  64. package/lib/typescript/module/src/NativeDaroModule.d.ts.map +1 -1
  65. package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts.map +1 -1
  66. package/lib/typescript/module/src/index.d.ts +11 -0
  67. package/lib/typescript/module/src/index.d.ts.map +1 -1
  68. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts +2 -0
  69. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts.map +1 -1
  70. package/lib/typescript/module/src/types/NativeAdViewProps.d.ts +9 -0
  71. package/lib/typescript/module/src/types/NativeAdViewProps.d.ts.map +1 -1
  72. package/package.json +6 -3
  73. package/plugin/build/withAndroid.js +2 -2
  74. package/react-native-daro.podspec +1 -1
  75. package/src/DaroRNNativeAdViewNativeComponent.ts +3 -0
  76. package/src/LightPopupAd.ts +18 -1
  77. package/src/NativeDaroModule.ts +2 -0
  78. package/src/hooks/useLightPopupAd.ts +6 -4
  79. package/src/index.tsx +14 -0
  80. package/src/nativeAd/NativeAdView.tsx +21 -0
  81. package/src/types/NativeAdViewProps.ts +10 -0
@@ -0,0 +1,62 @@
1
+ package com.daro.reactnative.impl
2
+
3
+ import org.junit.Assert.*
4
+ import org.junit.Test
5
+
6
+ class LightPopupRequestTest {
7
+ private class Ad(var destroyed: Int = 0)
8
+
9
+ @Test fun disposeCancelsLoaderAndRejectsLateDelivery() {
10
+ var cancellations = 0
11
+ val request = LightPopupRequest({ cancellations++ }, { ad: Ad -> ad.destroyed++ })
12
+ request.destroy()
13
+ request.destroy()
14
+ val late = Ad()
15
+ assertFalse(request.accept(late))
16
+ assertEquals(1, late.destroyed)
17
+ assertEquals(1, cancellations)
18
+ assertNull(request.takeForPresentation())
19
+ }
20
+
21
+ @Test fun showingConsumesReadinessButRetainsOwnershipUntilDismissal() {
22
+ val request = LightPopupRequest({}, { ad: Ad -> ad.destroyed++ })
23
+ val ad = Ad()
24
+ assertTrue(request.accept(ad))
25
+ assertTrue(request.isReady)
26
+ assertSame(ad, request.takeForPresentation())
27
+ assertFalse(request.isReady)
28
+ assertNull(request.takeForPresentation())
29
+ assertTrue(request.ownsPresentation(ad))
30
+ request.finishPresentation(ad)
31
+ request.finishPresentation(ad)
32
+ assertFalse(request.ownsPresentation(ad))
33
+ assertEquals(1, ad.destroyed)
34
+ }
35
+
36
+ @Test fun disposalDestroysPresentedAdAndRevokesEventsBeforeCleanup() {
37
+ lateinit var request: LightPopupRequest<Ad>
38
+ val ad = Ad()
39
+ request = LightPopupRequest({}, { value ->
40
+ assertFalse(request.ownsPresentation(value))
41
+ value.destroyed++
42
+ })
43
+ request.accept(ad)
44
+ request.takeForPresentation()
45
+ request.destroy()
46
+ assertEquals(1, ad.destroyed)
47
+ assertFalse(request.active)
48
+ }
49
+
50
+ @Test fun staleDismissCannotReleaseAnotherAd() {
51
+ val request = LightPopupRequest({}, { ad: Ad -> ad.destroyed++ })
52
+ val stale = Ad()
53
+ val current = Ad()
54
+ request.accept(stale)
55
+ request.accept(current)
56
+ request.takeForPresentation()
57
+ request.finishPresentation(stale)
58
+ assertTrue(request.ownsPresentation(current))
59
+ assertEquals(0, current.destroyed)
60
+ assertEquals(1, stale.destroyed)
61
+ }
62
+ }
@@ -3,79 +3,108 @@ import UIKit
3
3
  // MARK: - LightPopup Ad
4
4
  extension DaroRNModule {
5
5
 
6
+ @objc(destroyLightPopup:adUnitId:)
7
+ func destroyLightPopup(requestId: Double, adUnitId: String) {
8
+ performLightPopupOnMain { releaseLightPopup(requestId: Int(requestId)) }
9
+ }
10
+
11
+ func releaseLightPopup(requestId: Int) {
12
+ lightPopupConfigurations.removeValue(forKey: requestId)
13
+ guard let request = lightPopups.removeValue(forKey: requestId) else { return }
14
+ request.loader.listener.onAdLoadSuccess = nil
15
+ request.loader.listener.onAdLoadFail = nil
16
+ request.loader.listener.onAdClicked = nil
17
+ request.loader.listener.onAdImpression = nil
18
+ for ad in [request.loadedAd, request.presentedAd].compactMap({ $0 }) {
19
+ ad.lightPopupAdListener.onShown = nil
20
+ ad.lightPopupAdListener.onDismiss = nil
21
+ ad.lightPopupAdListener.onFailedToShow = nil
22
+ }
23
+ request.loadedAd = nil
24
+ request.presentedAd = nil
25
+ // The SDK has no public dismiss API. Only dismiss the controller this request presented.
26
+ // UIKit disappearance lets the SDK stop its own refresh and auto-close work.
27
+ if let controller = request.presentedController {
28
+ let dismiss = {
29
+ if controller.presentingViewController != nil && !controller.isBeingDismissed {
30
+ controller.dismiss(animated: false)
31
+ }
32
+ }
33
+ if controller.isBeingPresented, let transition = controller.transitionCoordinator {
34
+ if !transition.animate(alongsideTransition: nil, completion: { _ in dismiss() }) {
35
+ dismiss()
36
+ }
37
+ } else {
38
+ dismiss()
39
+ }
40
+ }
41
+ request.presentedController = nil
42
+ }
43
+
6
44
  @objc(isLightPopupReady:adUnitId:resolve:reject:)
7
- func isLightPopupReady(
8
- requestId: Double,
9
- adUnitId: String,
10
- resolve: RCTPromiseResolveBlock,
11
- reject: RCTPromiseRejectBlock
12
- ) {
13
- let requestId = Int(requestId)
14
- if !Self.sdkInitialized {
15
- DaroRNModule.logger.debug("[DaroRNMobileAds] !isInitialized")
16
- resolve(false)
17
- return
45
+ func isLightPopupReady(requestId: Double, adUnitId: String,
46
+ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
47
+ performLightPopupOnMain {
48
+ let request = lightPopups[Int(requestId)]
49
+ resolve(Self.sdkInitialized && request?.loadedAd != nil && request?.presentedAd == nil)
18
50
  }
19
- resolve(lightPopups[requestId]?.loadedAd != nil)
20
51
  }
21
52
 
22
53
  @objc(loadLightPopup:adUnitId:resolve:reject:)
23
- func loadLightPopup(
24
- requestId: Double,
25
- adUnitId: String,
26
- resolve: RCTPromiseResolveBlock,
27
- reject: RCTPromiseRejectBlock
28
- ) {
29
- let requestId = Int(requestId)
30
- let lightPopupLoader = retrieveLightPopupLoader(requestId: requestId, adUnitId: adUnitId)
31
- lightPopupLoader.loadAd()
32
- resolve(Void())
54
+ func loadLightPopup(requestId: Double, adUnitId: String,
55
+ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
56
+ performLightPopupOnMain {
57
+ guard !lightPopupInvalidated else { resolve(Void()); return }
58
+ let id = Int(requestId)
59
+ let configuration = lightPopupConfigurations[id]
60
+ releaseLightPopup(requestId: id)
61
+ lightPopupConfigurations[id] = configuration
62
+ retrieveLightPopupLoader(requestId: id, adUnitId: adUnitId).loadAd()
63
+ resolve(Void())
64
+ }
33
65
  }
34
66
 
35
67
  @objc(showLightPopup:adUnitId:resolve:reject:)
36
- func showLightPopup(
37
- requestId: Double,
38
- adUnitId: String,
39
- resolve: @escaping RCTPromiseResolveBlock,
40
- reject: @escaping RCTPromiseRejectBlock
41
- ) {
42
- let requestId = Int(requestId)
43
- guard let loadedAd = lightPopups[requestId]?.loadedAd else {
44
- reject("LIGHTPOPUP_NOT_LOADED", "LightPopup ad not loaded", nil)
45
- return
46
- }
47
- let reqIdInt = requestId
48
- executeOnMainThread { [weak self] in
49
- guard let viewController = UIApplication.shared.windows.first?.rootViewController else {
50
- reject("VIEW_CONTROLLER_NOT_FOUND", "Root view controller not found", nil)
68
+ func showLightPopup(requestId: Double, adUnitId: String,
69
+ resolve: @escaping RCTPromiseResolveBlock,
70
+ reject: @escaping RCTPromiseRejectBlock) {
71
+ performLightPopupOnMain {
72
+ let id = Int(requestId)
73
+ guard let request = lightPopups[id], let ad = request.loadedAd,
74
+ request.presentedAd == nil else {
75
+ reject("LIGHTPOPUP_NOT_LOADED", "LightPopup ad not loaded", nil)
51
76
  return
52
77
  }
53
- self?.applyStoredConfiguration(to: loadedAd, for: reqIdInt)
54
- loadedAd.show(viewController: viewController)
78
+ guard let presenter = RCTPresentedViewController(),
79
+ presenter.viewIfLoaded?.window != nil,
80
+ presenter.presentedViewController == nil, !presenter.isBeingDismissed else {
81
+ reject("VIEW_CONTROLLER_NOT_FOUND", "View controller not available", nil)
82
+ return
83
+ }
84
+ applyStoredConfiguration(to: ad, for: id)
85
+ request.loadedAd = nil
86
+ request.presentedAd = ad
87
+ ad.show(viewController: presenter)
88
+ // A refused show synchronously clears presentedAd through onFailedToShow.
89
+ if request.presentedAd === ad {
90
+ request.presentedController = presenter.presentedViewController
91
+ }
55
92
  resolve(Void())
56
93
  }
57
94
  }
58
95
 
59
96
  @objc(setLightPopupAdConfiguration:adUnitId:configuration:resolve:reject:)
60
- func setLightPopupAdConfiguration(
61
- requestId: Double,
62
- adUnitId: String,
63
- configuration: [String: Any],
64
- resolve: RCTPromiseResolveBlock,
65
- reject: RCTPromiseRejectBlock
66
- ) {
67
- let reqIdInt = Int(requestId)
68
- guard let loadedAd = lightPopups[reqIdInt]?.loadedAd else {
69
- lightPopupConfigurations[reqIdInt] = configuration
70
- resolve(Void())
71
- return
72
- }
73
- lightPopupConfigurations[reqIdInt] = configuration
74
- executeOnMainThread { [weak self] in
75
- self?.applyStoredConfiguration(to: loadedAd, for: reqIdInt)
76
- }
97
+ func setLightPopupAdConfiguration(requestId: Double, adUnitId: String,
98
+ configuration: [String: Any],
99
+ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
100
+ performLightPopupOnMain {
101
+ guard !lightPopupInvalidated else { resolve(Void()); return }
102
+ let id = Int(requestId)
103
+ lightPopupConfigurations[id] = configuration
104
+ if let ad = lightPopups[id]?.loadedAd { applyStoredConfiguration(to: ad, for: id) }
77
105
  resolve(Void())
78
106
  }
107
+ }
79
108
 
80
109
  func applyStoredConfiguration(to ad: DaroLightPopupAd, for requestId: Int) {
81
110
  if let configuration = lightPopupConfigurations[requestId] {
@@ -106,60 +135,59 @@ extension DaroRNModule {
106
135
  }
107
136
 
108
137
  func retrieveLightPopupLoader(requestId: Int, adUnitId: String) -> DaroLightPopupAdLoader {
109
- if let lightPopupAd = lightPopups[requestId] {
110
- return lightPopupAd.loader
111
- } else {
112
- let lightPopupLoader = DaroLightPopupAdLoader(unit: DaroAdUnit(unitId: adUnitId))
113
-
114
- lightPopupLoader.listener.onAdClicked = { [weak self] adInfo in
115
- self?.sendEvent(with: .onLightPopupClickedEvent, body: adInfo?.toBody(requestId: requestId))
116
- }
117
-
118
- lightPopupLoader.listener.onAdImpression = { [weak self] adInfo in
119
- self?.lightPopups[requestId]?.loadedAd = nil
120
- self?.sendEvent(with: .onLightPopupAdImpressionRecordedEvent, body: adInfo?.toBody(requestId: requestId))
121
- }
122
-
123
- lightPopupLoader.listener.onAdLoadSuccess = { [weak self] ad, adInfo in
124
- self?.lightPopups[requestId]?.loadedAd = ad
125
- self?.sendEvent(with: .onLightPopupLoadedEvent, body: adInfo?.toBody(requestId: requestId))
126
- self?.setupLightPopupListener(for: ad, requestId: requestId)
127
- }
128
-
129
- lightPopupLoader.listener.onAdLoadFail = { [weak self] error in
130
- self?.sendEvent(with: .onLightPopupLoadFailedEvent, body: error.toBody(requestId: requestId))
131
- }
132
-
133
- self.lightPopups[requestId] = LightPopupAd(loader: lightPopupLoader)
134
- return lightPopupLoader
138
+ let loader = DaroLightPopupAdLoader(unit: DaroAdUnit(unitId: adUnitId))
139
+ let request = LightPopupAd(loader: loader)
140
+ lightPopups[requestId] = request
141
+ loader.listener.onAdClicked = { [weak self, weak request] adInfo in
142
+ guard let self, let request, self.lightPopups[requestId] === request,
143
+ request.presentedAd != nil else { return }
144
+ self.sendEvent(with: .onLightPopupClickedEvent, body: adInfo?.toBody(requestId: requestId))
145
+ }
146
+ loader.listener.onAdImpression = { [weak self, weak request] adInfo in
147
+ guard let self, let request, self.lightPopups[requestId] === request,
148
+ request.presentedAd != nil else { return }
149
+ self.sendEvent(with: .onLightPopupAdImpressionRecordedEvent, body: adInfo?.toBody(requestId: requestId))
150
+ }
151
+ loader.listener.onAdLoadSuccess = { [weak self, weak request] ad, adInfo in
152
+ guard let self, let request, self.lightPopups[requestId] === request else { return }
153
+ request.loadedAd = ad
154
+ self.setupLightPopupListener(for: ad, request: request, requestId: requestId)
155
+ self.sendEvent(with: .onLightPopupLoadedEvent, body: adInfo?.toBody(requestId: requestId))
156
+ }
157
+ loader.listener.onAdLoadFail = { [weak self, weak request] error in
158
+ guard let self, let request, self.lightPopups[requestId] === request else { return }
159
+ self.sendEvent(with: .onLightPopupLoadFailedEvent, body: error.toBody(requestId: requestId))
135
160
  }
161
+ return loader
136
162
  }
137
163
 
138
- private func setupLightPopupListener(for ad: DaroLightPopupAd, requestId: Int) {
139
- ad.lightPopupAdListener.onShown = { [weak self] adInfo in
140
- self?.sendEvent(with: .onLightPopupDisplayedEvent, body: adInfo?.toBody(requestId: requestId))
164
+ private func setupLightPopupListener(for ad: DaroLightPopupAd, request: LightPopupAd, requestId: Int) {
165
+ ad.lightPopupAdListener.onShown = { [weak self, weak request, weak ad] adInfo in
166
+ guard let self, let request, let ad, self.lightPopups[requestId] === request,
167
+ request.presentedAd === ad else { return }
168
+ self.sendEvent(with: .onLightPopupDisplayedEvent, body: adInfo?.toBody(requestId: requestId))
141
169
  }
142
-
143
- ad.lightPopupAdListener.onDismiss = { [weak self] adInfo in
144
- self?.sendEvent(with: .onLightPopupHiddenEvent, body: adInfo?.toBody(requestId: requestId))
170
+ ad.lightPopupAdListener.onDismiss = { [weak self, weak request, weak ad] adInfo in
171
+ guard let self, let request, let ad, self.lightPopups[requestId] === request,
172
+ request.presentedAd === ad else { return }
173
+ request.presentedAd = nil
174
+ request.presentedController = nil
175
+ self.sendEvent(with: .onLightPopupHiddenEvent, body: adInfo?.toBody(requestId: requestId))
145
176
  }
146
-
147
- ad.lightPopupAdListener.onFailedToShow = { [weak self] adInfo, error in
148
- self?.sendEvent(with: .onLightPopupAdFailedToDisplayEvent, body: adInfo?.toBody(requestId: requestId))
177
+ ad.lightPopupAdListener.onFailedToShow = { [weak self, weak request, weak ad] adInfo, error in
178
+ guard let self, let request, let ad, self.lightPopups[requestId] === request,
179
+ request.presentedAd === ad else { return }
180
+ request.presentedAd = nil
181
+ request.presentedController = nil
182
+ var body = adInfo?.toBody(requestId: requestId) ?? ["requestId": requestId]
183
+ body.merge(error.toBody) { _, new in new }
184
+ self.sendEvent(with: .onLightPopupAdFailedToDisplayEvent, body: body)
149
185
  }
150
186
  }
151
187
 
152
- // 메인 스레드에서 실행하는 헬퍼 메서드
153
- private func executeOnMainThread<T>(_ block: () -> T) -> T {
154
- if Thread.isMainThread {
155
- return block()
156
- } else {
157
- var result: T!
158
- DispatchQueue.main.sync {
159
- result = block()
160
- }
161
- return result
162
- }
188
+ func performLightPopupOnMain<T>(_ block: () -> T) -> T {
189
+ if Thread.isMainThread { return block() }
190
+ return DispatchQueue.main.sync(execute: block)
163
191
  }
164
192
  }
165
193
 
@@ -1,5 +1,7 @@
1
1
  import AppLovinSDK
2
- import Daro
2
+ // `openDebugger` 가 @_spi(DaroQA) 라 SPI 로 받는다 — 발행된 xcframework 의
3
+ // private.swiftinterface 에 실려 있다(rc.5 실측).
4
+ @_spi(DaroQA) import Daro
3
5
  import Dispatch
4
6
  import GoogleMobileAds
5
7
  import React
@@ -48,55 +50,54 @@ extension DaroRNModule {
48
50
  }
49
51
  }
50
52
 
53
+ /// **어휘 판정을 SDK 에 맡긴다.** 손으로 비교하면 모르는 값이 조용히 한쪽으로 떨어져
54
+ /// 엉뚱한 검사기가 뜨고 아무도 모른다 — 어휘가 `daroa`/`darom` 으로 옮겨간 뒤 실제로
55
+ /// 그랬다(DARO-1615). `mediation == "applovin"` 이 참이 될 방법이 없어져서 iOS 는
56
+ /// **항상 AdMob 검사기를 열었고**, 문자열 리터럴 비교라 컴파일러가 아무 말도 안 했다.
57
+ ///
58
+ /// `AdProvider.matching` 이 구 어휘(`admob`/`applovin`)도 받으므로 그 값으로 붙은 베타
59
+ /// 소비자도 안 깨진다. Android 는 같은 자리를 `DaroMediationType.matching` 으로 고쳤다.
51
60
  @objc(showMediationDebuggerFor:resolve:reject:)
52
61
  func showMediationDebuggerFor(
53
62
  mediation: String,
54
63
  resolve: @escaping RCTPromiseResolveBlock,
55
64
  reject: @escaping RCTPromiseRejectBlock
56
65
  ) {
66
+ // **콜백 하나가 세 사건을 겸한다**: 거절(모르는 어휘·미등록 프로바이더), 제시 실패,
67
+ // 그리고 닫힘(정상 종료). 그래서 콜백만으로 성공을 판정할 수 없다 — 기다리면
68
+ // "열렸다"가 검사기를 닫을 때까지(앱을 그대로 죽이면 영영) 안 뜨고, 안 기다리면
69
+ // 비동기로 오는 실패(GMA 는 설정을 받아본 뒤에야 거절 사유를 안다)를 놓쳐 성공
70
+ // 로그만 남는다.
71
+ //
72
+ // 그래서 짧은 유예를 둔다. 그 안에 온 것은 실패로 보고 reject 하고, 조용하면 떠 있는
73
+ // 것으로 보고 resolve 한다 — 그 뒤에 오는 콜백은 닫힘이다. AppLovin 은 제시 직후
74
+ // 바로 `nil` 로 오므로 유예 안에서 성공으로 settle 된다.
75
+ //
76
+ // **모든 판정을 메인 큐에서 한다** — 어느 큐로 콜백이 오든 이중 settle 이 나지 않게
77
+ // (RN 은 두 번 settle 하면 예외를 던진다).
78
+ let state = DebuggerPresentation()
57
79
  DispatchQueue.main.async {
58
- if mediation == "applovin" {
59
- // ALSdk 초기화 뒤에 불러야 한다 — 전이면 빈 화면이 뜬다 (QA 앱 DebuggerHelper 실측).
60
- ALSdk.shared().showMediationDebugger()
61
- resolve(nil)
62
- } else {
63
- // **에러를 삼키지 않는다.** 초기화 전이거나 테스트 기기가 아니면 GMA 가 여기로
64
- // 사유를 준다 — 버리면 화면에는 성공 로그만 남고 검사기는 안 뜬다.
65
- //
66
- // 이 콜백 하나가 두 사건을 겸한다: **실패(제시 못 함)** 와 **닫힘(정상 종료)**.
67
- // 그래서 어느 쪽도 그냥 믿을 수 없다 — 콜백을 기다려 성공을 판정하면 "열렸다"가
68
- // 검사기를 닫을 때까지(또는 앱을 그대로 죽이면 영영) 안 뜨고, 기다리지 않고 바로
69
- // 성공 처리하면 **비동기로 오는 실패**(GMA 는 설정을 받아본 뒤에야 거절 사유를
70
- // 안다)를 놓쳐 성공 로그만 남는다.
71
- //
72
- // 그래서 짧은 유예를 둔다. 그 안에 온 콜백은 제시 실패로 보고 reject 하고,
73
- // 조용하면 떠 있는 것으로 보고 resolve 한다 — 그 뒤에 오는 콜백은 닫힘이다.
74
- // **모든 판정을 메인 큐에서 한다** — 벤더가 어느 큐로 콜백하든 이중 settle 이
75
- // 나지 않게(RN 은 두 번 settle 하면 예외를 던진다).
76
- let state = DebuggerPresentation()
77
- MobileAds.shared.presentAdInspector(from: nil) { error in
78
- DispatchQueue.main.async {
79
- if state.settled {
80
- if let error {
81
- Self.logger.error("Ad Inspector 종료 시 에러: \(error.localizedDescription)")
82
- }
83
- return
84
- }
85
- state.settled = true
80
+ DaroAds.shared.openDebugger(mediation: mediation) { error in
81
+ DispatchQueue.main.async {
82
+ if state.settled {
86
83
  if let error {
87
- reject("AD_INSPECTOR_FAILED", error.localizedDescription, error)
88
- } else {
89
- // 유예 안에 에러 없이 닫혔다 — 열렸다가 곧장 닫힌 경우다.
90
- resolve(nil)
84
+ Self.logger.error("검사기 종료 시 에러: \(error.localizedDescription)")
91
85
  }
86
+ return
92
87
  }
93
- }
94
- DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
95
- guard !state.settled else { return }
96
88
  state.settled = true
97
- resolve(nil)
89
+ if let error {
90
+ reject("MEDIATION_DEBUGGER_FAILED", error.localizedDescription, error)
91
+ } else {
92
+ resolve(nil)
93
+ }
98
94
  }
99
95
  }
96
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
97
+ guard !state.settled else { return }
98
+ state.settled = true
99
+ resolve(nil)
100
+ }
100
101
  }
101
102
  }
102
103
 
@@ -10,6 +10,7 @@
10
10
  #pragma mark - Initialization
11
11
 
12
12
  RCT_EXTERN_METHOD(isInitialized:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
13
+ RCT_EXTERN_METHOD(setAppMuted:(BOOL)muted resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
13
14
  RCT_EXTERN_METHOD(initializeSdk:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
14
15
  RCT_EXTERN_METHOD(setUserId:(NSString *)userId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
15
16
 
@@ -52,6 +53,7 @@ RCT_EXTERN_METHOD(showAppOpenAd:(double)requestId adUnitId:(NSString *)adUnitId
52
53
 
53
54
  #pragma mark - Light Popup
54
55
 
56
+ RCT_EXTERN_METHOD(destroyLightPopup:(double)requestId adUnitId:(NSString *)adUnitId)
55
57
  RCT_EXTERN_METHOD(isLightPopupReady:(double)requestId adUnitId:(NSString *)adUnitId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
56
58
  RCT_EXTERN_METHOD(loadLightPopup:(double)requestId adUnitId:(NSString *)adUnitId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
57
59
  RCT_EXTERN_METHOD(showLightPopup:(double)requestId adUnitId:(NSString *)adUnitId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
@@ -80,19 +80,27 @@ class DaroRNModule: RCTEventEmitter {
80
80
  }
81
81
  }
82
82
 
83
- static var sdkInitialized: Bool = false
83
+ private static let initialization = DaroRNInitialization(
84
+ start: { completion in
85
+ DaroAds.shared.logLevel = .debug
86
+ DaroAds.shared.initialized { error in completion(error) }
87
+ },
88
+ applyMuted: { DaroAds.shared.setAppMuted($0) }
89
+ )
90
+ static var sdkInitialized: Bool { initialization.isInitialized }
84
91
  // 광고 인스턴스 저장소
85
92
  internal var interstitials: [Int: InterstitialAd] = [:]
86
93
  internal var rewardedAds: [Int: RewardedAd] = [:]
87
94
  internal var appOpenAds: [Int: AppOpenAd] = [:]
88
95
  internal var lightPopups: [Int: LightPopupAd] = [:]
96
+ internal var lightPopupInvalidated = false
89
97
  internal var lightPopupConfigurations: [Int: [String: Any]] = [:]
90
98
 
91
99
  // MARK: - SDK 초기화 및 설정
92
100
 
93
101
  @objc(isInitialized:reject:)
94
- func isInitialized(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
95
- resolve(Self.sdkInitialized)
102
+ func isInitialized(resolve: @escaping RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
103
+ DispatchQueue.main.async { resolve(Self.sdkInitialized) }
96
104
  }
97
105
 
98
106
  @objc(initializeSdk:reject:)
@@ -100,27 +108,27 @@ class DaroRNModule: RCTEventEmitter {
100
108
  resolve: @escaping RCTPromiseResolveBlock,
101
109
  reject: @escaping RCTPromiseRejectBlock
102
110
  ) {
103
- // 이미 초기화되었는지 확인
104
- if Self.sdkInitialized {
105
- Self.logger.debug("SDK already initialized, returning success")
106
- resolve(Void())
107
- return
108
- }
109
-
110
- // 초기화 진행
111
- DaroAds.shared.logLevel = .debug
112
- DaroAds.shared.initialized { error in
113
- if let error {
114
- Self.logger.error("SDK initialization failed: \(error.localizedDescription)")
115
- reject("INIT_ERROR", error.localizedDescription, error)
116
- } else {
117
- Self.sdkInitialized = true
118
- Self.logger.info("SDK initialized successfully")
119
- resolve(Void())
111
+ DispatchQueue.main.async {
112
+ Self.initialization.initialize { error in
113
+ if let error {
114
+ reject("INIT_ERROR", error.localizedDescription, error)
115
+ } else {
116
+ resolve(nil)
117
+ }
120
118
  }
121
119
  }
122
120
  }
123
121
 
122
+ @objc(setAppMuted:resolve:reject:)
123
+ func setAppMuted(
124
+ muted: Bool, resolve: @escaping RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock
125
+ ) {
126
+ DispatchQueue.main.async {
127
+ Self.initialization.setAppMuted(muted)
128
+ resolve(nil)
129
+ }
130
+ }
131
+
124
132
  @objc(showMediationDebugger:reject:)
125
133
  func showMediationDebugger(resolve: @escaping RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
126
134
  DaroMediationDebugger.show {
@@ -161,9 +169,20 @@ class DaroRNModule: RCTEventEmitter {
161
169
  }
162
170
  }
163
171
 
172
+ override func invalidate() {
173
+ performLightPopupOnMain {
174
+ lightPopupInvalidated = true
175
+ let requests = Array(lightPopups.keys)
176
+ requests.forEach { releaseLightPopup(requestId: $0) }
177
+ }
178
+ super.invalidate()
179
+ }
180
+
164
181
  class LightPopupAd {
165
182
  let loader: DaroLightPopupAdLoader
166
183
  var loadedAd: DaroLightPopupAd?
184
+ var presentedAd: DaroLightPopupAd?
185
+ weak var presentedController: UIViewController?
167
186
 
168
187
  init(loader: DaroLightPopupAdLoader) {
169
188
  self.loader = loader
@@ -78,6 +78,18 @@ static NSString *DaroRNFabricAdChoicesPositionString(DaroRNNativeAdViewAdChoices
78
78
  {
79
79
  __weak DaroRNNativeAdViewComponentView *weakSelf = self;
80
80
 
81
+ RCTDirectEventBlock onNativeAdAssetLoadedEvent = ^(NSDictionary *body) {
82
+ DaroRNNativeAdViewComponentView *strongSelf = weakSelf;
83
+ if (!strongSelf) return;
84
+ auto eventEmitter = std::static_pointer_cast<const DaroRNNativeAdViewEventEmitter>(strongSelf->_eventEmitter);
85
+ if (!eventEmitter) return;
86
+ std::vector<std::string> assetTypes;
87
+ for (NSString *value in DaroRNFabricEventBody(body)[@"assetTypes"]) {
88
+ assetTypes.push_back(std::string(value.UTF8String));
89
+ }
90
+ eventEmitter->onNativeAdAssetLoadedEvent({.assetTypes = assetTypes});
91
+ };
92
+
81
93
  RCTDirectEventBlock onAdLoadedEvent = ^(NSDictionary *body) {
82
94
  DaroRNNativeAdViewComponentView *strongSelf = weakSelf;
83
95
  if (!strongSelf) {
@@ -164,6 +176,7 @@ static NSString *DaroRNFabricAdChoicesPositionString(DaroRNNativeAdViewAdChoices
164
176
  });
165
177
  };
166
178
 
179
+ DaroRNFabricSetValue(_nativeAdView, @"onNativeAdAssetLoadedEvent", onNativeAdAssetLoadedEvent);
167
180
  DaroRNFabricSetValue(_nativeAdView, @"onAdLoadedEvent", onAdLoadedEvent);
168
181
  DaroRNFabricSetValue(_nativeAdView, @"onAdLoadFailedEvent", onAdLoadFailedEvent);
169
182
  DaroRNFabricSetValue(_nativeAdView, @"onAdClickedEvent", onAdClickedEvent);
@@ -284,6 +297,7 @@ static NSString *DaroRNFabricAdChoicesPositionString(DaroRNNativeAdViewAdChoices
284
297
  - (void)prepareForRecycle
285
298
  {
286
299
  [super prepareForRecycle];
300
+ DaroRNFabricSetValue(_nativeAdView, @"onNativeAdAssetLoadedEvent", nil);
287
301
  DaroRNFabricSetValue(_nativeAdView, @"onAdLoadedEvent", nil);
288
302
  DaroRNFabricSetValue(_nativeAdView, @"onAdLoadFailedEvent", nil);
289
303
  DaroRNFabricSetValue(_nativeAdView, @"onAdClickedEvent", nil);
@@ -18,6 +18,7 @@ RCT_EXPORT_VIEW_PROPERTY(callToActionViewStyleProps, NSDictionary)
18
18
  RCT_EXPORT_VIEW_PROPERTY(iconViewStyleProps, NSDictionary)
19
19
  RCT_EXPORT_VIEW_PROPERTY(mediaViewStyleProps, NSDictionary)
20
20
 
21
+ RCT_EXPORT_VIEW_PROPERTY(onNativeAdAssetLoadedEvent, RCTDirectEventBlock)
21
22
  RCT_EXPORT_VIEW_PROPERTY(onAdLoadedEvent, RCTDirectEventBlock)
22
23
  RCT_EXPORT_VIEW_PROPERTY(onAdLoadFailedEvent, RCTDirectEventBlock)
23
24
  RCT_EXPORT_VIEW_PROPERTY(onAdClickedEvent, RCTDirectEventBlock)
@@ -1,6 +1,7 @@
1
1
  import React
2
2
 
3
3
  final class DaroRNAdEventSink {
4
+ var onNativeAdAssetLoadedEvent: RCTDirectEventBlock?
4
5
  var onAdLoadedEvent: RCTDirectEventBlock?
5
6
  var onAdLoadFailedEvent: RCTDirectEventBlock?
6
7
  var onAdClickedEvent: RCTDirectEventBlock?
@@ -0,0 +1,47 @@
1
+ import Foundation
2
+
3
+ /// Process-owned RN settings. Callers enter on the main queue; SDK completion
4
+ /// may arrive on any queue. A JS bridge reload must not replace this instance.
5
+ final class DaroRNInitialization {
6
+ private let start: (@escaping (Error?) -> Void) -> Void
7
+ private let applyMuted: (Bool) -> Void
8
+ private var waiters: [(Error?) -> Void] = []
9
+ private var appMuted = true
10
+ private(set) var isInitialized = false
11
+
12
+ init(
13
+ start: @escaping (@escaping (Error?) -> Void) -> Void,
14
+ applyMuted: @escaping (Bool) -> Void
15
+ ) {
16
+ self.start = start
17
+ self.applyMuted = applyMuted
18
+ }
19
+
20
+ func setAppMuted(_ muted: Bool) {
21
+ dispatchPrecondition(condition: .onQueue(.main))
22
+ appMuted = muted
23
+ if isInitialized { applyMuted(muted) }
24
+ }
25
+
26
+ func initialize(completion: @escaping (Error?) -> Void) {
27
+ dispatchPrecondition(condition: .onQueue(.main))
28
+ if isInitialized {
29
+ completion(nil)
30
+ return
31
+ }
32
+ waiters.append(completion)
33
+ guard waiters.count == 1 else { return }
34
+ applyMuted(appMuted)
35
+ start { error in
36
+ DispatchQueue.main.async {
37
+ if error == nil {
38
+ self.applyMuted(self.appMuted)
39
+ self.isInitialized = true
40
+ }
41
+ let completions = self.waiters
42
+ self.waiters.removeAll() // Failed init can retry without resetting mute.
43
+ completions.forEach { $0(error) }
44
+ }
45
+ }
46
+ }
47
+ }