setupad-prebid-react-native 0.1.3
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/LICENSE +20 -0
- package/README.md +325 -0
- package/VeonPrebidReactNative.podspec +59 -0
- package/android/build.gradle +90 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/setupadprebidreactnative/VeonPrebidReactNativeModule.kt +130 -0
- package/android/src/main/java/com/setupadprebidreactnative/VeonPrebidReactNativePackage.kt +20 -0
- package/android/src/main/java/com/setupadprebidreactnative/VeonPrebidReactNativeView.kt +425 -0
- package/android/src/main/java/com/setupadprebidreactnative/VeonPrebidReactNativeViewManager.kt +186 -0
- package/ios/RCTFabricComponentsPlugins.h +12 -0
- package/ios/VeonPrebidReactNative-Bridging-Header.h +9 -0
- package/ios/VeonPrebidReactNativeModule.m +17 -0
- package/ios/VeonPrebidReactNativeModule.swift +108 -0
- package/ios/VeonPrebidReactNativeView+Delegates.swift +217 -0
- package/ios/VeonPrebidReactNativeView.h +5 -0
- package/ios/VeonPrebidReactNativeView.swift +381 -0
- package/ios/VeonPrebidReactNativeViewComponentView.h +13 -0
- package/ios/VeonPrebidReactNativeViewComponentView.mm +166 -0
- package/ios/VeonPrebidReactNativeViewManager.m +49 -0
- package/ios/VeonPrebidReactNativeViewManager.swift +105 -0
- package/lib/module/CodegenTypes.d.js +2 -0
- package/lib/module/CodegenTypes.d.js.map +1 -0
- package/lib/module/Commands.js +14 -0
- package/lib/module/Commands.js.map +1 -0
- package/lib/module/VeonPrebidAd.js +112 -0
- package/lib/module/VeonPrebidAd.js.map +1 -0
- package/lib/module/VeonPrebidModule.js +132 -0
- package/lib/module/VeonPrebidModule.js.map +1 -0
- package/lib/module/VeonPrebidReactNativeViewNativeComponent.ts +50 -0
- package/lib/module/VeonPrebidView.js +14 -0
- package/lib/module/VeonPrebidView.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +8 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/useVeonPrebidAd.js +154 -0
- package/lib/module/useVeonPrebidAd.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Commands.d.ts +14 -0
- package/lib/typescript/src/Commands.d.ts.map +1 -0
- package/lib/typescript/src/VeonPrebidAd.d.ts +4 -0
- package/lib/typescript/src/VeonPrebidAd.d.ts.map +1 -0
- package/lib/typescript/src/VeonPrebidModule.d.ts +59 -0
- package/lib/typescript/src/VeonPrebidModule.d.ts.map +1 -0
- package/lib/typescript/src/VeonPrebidReactNativeViewNativeComponent.d.ts +40 -0
- package/lib/typescript/src/VeonPrebidReactNativeViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/VeonPrebidView.d.ts +5 -0
- package/lib/typescript/src/VeonPrebidView.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +7 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +89 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/useVeonPrebidAd.d.ts +52 -0
- package/lib/typescript/src/useVeonPrebidAd.d.ts.map +1 -0
- package/package.json +169 -0
- package/src/CodegenTypes.d.ts +16 -0
- package/src/Commands.ts +25 -0
- package/src/VeonPrebidAd.tsx +159 -0
- package/src/VeonPrebidModule.ts +159 -0
- package/src/VeonPrebidReactNativeViewNativeComponent.ts +50 -0
- package/src/VeonPrebidView.tsx +13 -0
- package/src/index.tsx +12 -0
- package/src/types.ts +64 -0
- package/src/useVeonPrebidAd.ts +156 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import GoogleMobileAds
|
|
3
|
+
import PrebidMobile
|
|
4
|
+
import PrebidMobileGAMEventHandlers
|
|
5
|
+
|
|
6
|
+
// MARK: - AdParameters
|
|
7
|
+
|
|
8
|
+
struct AdParameters {
|
|
9
|
+
var configId: String?
|
|
10
|
+
var adUnitId: String?
|
|
11
|
+
var adType: String?
|
|
12
|
+
var bannerWidth: Int
|
|
13
|
+
var bannerHeight: Int
|
|
14
|
+
var refreshInterval: Double
|
|
15
|
+
|
|
16
|
+
init(configId: String? = nil,
|
|
17
|
+
adUnitId: String? = nil,
|
|
18
|
+
adType: String? = nil,
|
|
19
|
+
bannerWidth: Int = 0,
|
|
20
|
+
bannerHeight: Int = 0,
|
|
21
|
+
refreshInterval: Double = 30.0) {
|
|
22
|
+
self.configId = configId
|
|
23
|
+
self.adUnitId = adUnitId
|
|
24
|
+
self.adType = adType
|
|
25
|
+
self.bannerWidth = bannerWidth
|
|
26
|
+
self.bannerHeight = bannerHeight
|
|
27
|
+
self.refreshInterval = refreshInterval
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@objc(VeonPrebidReactNativeView)
|
|
32
|
+
class VeonPrebidReactNativeView: UIView {
|
|
33
|
+
|
|
34
|
+
// MARK: - Properties
|
|
35
|
+
|
|
36
|
+
/// Container view that holds ad views
|
|
37
|
+
private var container: UIView?
|
|
38
|
+
|
|
39
|
+
/// GAM Banner view
|
|
40
|
+
var gamBanner: AdManagerBannerView?
|
|
41
|
+
|
|
42
|
+
/// Prebid banner view
|
|
43
|
+
private var prebidBannerView: PrebidMobile.BannerView?
|
|
44
|
+
|
|
45
|
+
/// Prebid banner ad unit (must be retained for auto-refresh to work)
|
|
46
|
+
private var bannerAdUnit: BannerAdUnit?
|
|
47
|
+
|
|
48
|
+
/// Prebid interstitial rendering ad unit
|
|
49
|
+
private var prebidInterstitial: InterstitialRenderingAdUnit?
|
|
50
|
+
|
|
51
|
+
/// Prebid reward ad unit
|
|
52
|
+
private var rewardedAdUnit: RewardedAdUnit?
|
|
53
|
+
|
|
54
|
+
/// Ad parameters
|
|
55
|
+
var adParameters = AdParameters()
|
|
56
|
+
|
|
57
|
+
// MARK: - React Native Props
|
|
58
|
+
|
|
59
|
+
@objc var adTypeValue: NSString? {
|
|
60
|
+
didSet {
|
|
61
|
+
adParameters.adType = adTypeValue as String?
|
|
62
|
+
updateAdConfiguration()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@objc var configIdValue: NSString? {
|
|
67
|
+
didSet {
|
|
68
|
+
adParameters.configId = configIdValue as String?
|
|
69
|
+
updateAdConfiguration()
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@objc var adUnitIdValue: NSString? {
|
|
74
|
+
didSet {
|
|
75
|
+
adParameters.adUnitId = adUnitIdValue as String?
|
|
76
|
+
updateAdConfiguration()
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@objc var widthValue: NSNumber? {
|
|
81
|
+
didSet {
|
|
82
|
+
if let width = widthValue?.intValue {
|
|
83
|
+
adParameters.bannerWidth = width
|
|
84
|
+
updateAdConfiguration()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@objc var heightValue: NSNumber? {
|
|
90
|
+
didSet {
|
|
91
|
+
if let height = heightValue?.intValue {
|
|
92
|
+
adParameters.bannerHeight = height
|
|
93
|
+
updateAdConfiguration()
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@objc var refreshIntervalValue: NSNumber? {
|
|
99
|
+
didSet {
|
|
100
|
+
if let interval = refreshIntervalValue?.doubleValue {
|
|
101
|
+
adParameters.refreshInterval = interval
|
|
102
|
+
updateAdConfiguration()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// MARK: - React Native Events
|
|
108
|
+
|
|
109
|
+
@objc var onAdLoaded: RCTDirectEventBlock?
|
|
110
|
+
@objc var onAdDisplayed: RCTDirectEventBlock?
|
|
111
|
+
@objc var onAdFailed: RCTDirectEventBlock?
|
|
112
|
+
@objc var onAdClicked: RCTDirectEventBlock?
|
|
113
|
+
@objc var onAdClosed: RCTDirectEventBlock?
|
|
114
|
+
|
|
115
|
+
// MARK: - Constants
|
|
116
|
+
|
|
117
|
+
private enum AdType {
|
|
118
|
+
static let banner = "banner"
|
|
119
|
+
static let interstitial = "interstitial"
|
|
120
|
+
static let rewardVideo = "rewardvideo"
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// MARK: - Initialization
|
|
124
|
+
|
|
125
|
+
override init(frame: CGRect) {
|
|
126
|
+
super.init(frame: frame)
|
|
127
|
+
setupView()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
required init?(coder: NSCoder) {
|
|
131
|
+
super.init(coder: coder)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private func setupView() {
|
|
135
|
+
container = UIView(frame: bounds)
|
|
136
|
+
container?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
137
|
+
if let container = container {
|
|
138
|
+
addSubview(container)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
NSLog("VeonPrebid iOS: View initialized")
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// MARK: - Deinit
|
|
145
|
+
|
|
146
|
+
deinit {
|
|
147
|
+
cleanupAds()
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private func cleanupAds() {
|
|
151
|
+
bannerAdUnit?.stopAutoRefresh()
|
|
152
|
+
bannerAdUnit = nil
|
|
153
|
+
prebidBannerView?.delegate = nil
|
|
154
|
+
prebidBannerView = nil
|
|
155
|
+
gamBanner?.delegate = nil
|
|
156
|
+
gamBanner = nil
|
|
157
|
+
prebidInterstitial?.delegate = nil
|
|
158
|
+
prebidInterstitial = nil
|
|
159
|
+
rewardedAdUnit?.delegate = nil
|
|
160
|
+
rewardedAdUnit = nil
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// MARK: - Configuration
|
|
164
|
+
|
|
165
|
+
private func updateAdConfiguration() {
|
|
166
|
+
// Only proceed if we have all required parameters
|
|
167
|
+
guard let adType = adParameters.adType,
|
|
168
|
+
let configId = adParameters.configId,
|
|
169
|
+
let adUnitId = adParameters.adUnitId else {
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
NSLog("VeonPrebid iOS: Updating configuration - Type: \(adType), ConfigId: \(configId), AdUnitId: \(adUnitId)")
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// MARK: - Public Methods (called from ViewManager)
|
|
177
|
+
|
|
178
|
+
@objc func loadBanner() {
|
|
179
|
+
guard let configId = adParameters.configId,
|
|
180
|
+
let adUnitId = adParameters.adUnitId else {
|
|
181
|
+
NSLog("VeonPrebid iOS: Cannot load banner - missing configId or adUnitId")
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
NSLog("VeonPrebid iOS: Loading banner")
|
|
186
|
+
loadGamBanner(configId: configId, adUnitId: adUnitId)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
@objc func showBanner() {
|
|
190
|
+
NSLog("VeonPrebid iOS: Showing banner")
|
|
191
|
+
if let gamBanner = gamBanner {
|
|
192
|
+
addGamBannerViewToView(gamBanner)
|
|
193
|
+
}
|
|
194
|
+
if let prebidBannerView = prebidBannerView {
|
|
195
|
+
addPrebidBannerViewToView(prebidBannerView)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@objc func hideBanner() {
|
|
200
|
+
NSLog("VeonPrebid iOS: Hiding banner")
|
|
201
|
+
prebidBannerView?.removeFromSuperview()
|
|
202
|
+
gamBanner?.removeFromSuperview()
|
|
203
|
+
prebidBannerView?.delegate = nil
|
|
204
|
+
prebidBannerView = nil
|
|
205
|
+
gamBanner?.delegate = nil
|
|
206
|
+
gamBanner = nil
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@objc func loadInterstitial() {
|
|
210
|
+
guard let configId = adParameters.configId,
|
|
211
|
+
let adUnitId = adParameters.adUnitId,
|
|
212
|
+
let adType = adParameters.adType else {
|
|
213
|
+
NSLog("VeonPrebid iOS: Cannot load interstitial - missing parameters")
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
NSLog("VeonPrebid iOS: Loading interstitial")
|
|
218
|
+
|
|
219
|
+
if adType.lowercased() == AdType.rewardVideo {
|
|
220
|
+
loadRewardVideo(configId: configId, adUnitId: adUnitId)
|
|
221
|
+
} else {
|
|
222
|
+
loadInterstitialRendering(configId: configId, adUnitId: adUnitId)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
@objc func showInterstitial() {
|
|
227
|
+
NSLog("VeonPrebid iOS: Showing interstitial")
|
|
228
|
+
|
|
229
|
+
if let prebidInterstitial = prebidInterstitial {
|
|
230
|
+
let rootViewController = getRootViewController()
|
|
231
|
+
let controllerToPresent = rootViewController.presentedViewController ?? rootViewController
|
|
232
|
+
prebidInterstitial.show(from: controllerToPresent)
|
|
233
|
+
} else if let rewardedAdUnit = rewardedAdUnit, rewardedAdUnit.isReady {
|
|
234
|
+
rewardedAdUnit.show(from: getRootViewController())
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
@objc func hideInterstitial() {
|
|
239
|
+
NSLog("VeonPrebid iOS: Hiding interstitial")
|
|
240
|
+
prebidInterstitial?.delegate = nil
|
|
241
|
+
prebidInterstitial = nil
|
|
242
|
+
rewardedAdUnit?.delegate = nil
|
|
243
|
+
rewardedAdUnit = nil
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
@objc func pauseAuction() {
|
|
247
|
+
NSLog("VeonPrebid iOS: Pausing auction")
|
|
248
|
+
prebidBannerView?.stopRefresh()
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
@objc func resumeAuction() {
|
|
252
|
+
NSLog("VeonPrebid iOS: Resuming auction")
|
|
253
|
+
prebidBannerView?.refreshInterval = adParameters.refreshInterval
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
@objc func destroyAuction() {
|
|
257
|
+
NSLog("VeonPrebid iOS: Destroying auction")
|
|
258
|
+
cleanupAds()
|
|
259
|
+
container?.subviews.forEach { $0.removeFromSuperview() }
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// MARK: - Banner Loading
|
|
263
|
+
|
|
264
|
+
private func loadGamBanner(configId: String, adUnitId: String) {
|
|
265
|
+
let adSize = CGSize(width: adParameters.bannerWidth, height: adParameters.bannerHeight)
|
|
266
|
+
|
|
267
|
+
guard gamBanner == nil else {
|
|
268
|
+
NSLog("VeonPrebid iOS: GAM Banner already exists")
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Store as property so it stays alive for auto-refresh
|
|
273
|
+
bannerAdUnit = BannerAdUnit(configId: configId, size: adSize)
|
|
274
|
+
|
|
275
|
+
// Configure banner parameters
|
|
276
|
+
let parameters = BannerParameters()
|
|
277
|
+
parameters.api = [Signals.Api.MRAID_2]
|
|
278
|
+
bannerAdUnit?.bannerParameters = parameters
|
|
279
|
+
bannerAdUnit?.setAutoRefreshMillis(time: adParameters.refreshInterval * 1000)
|
|
280
|
+
|
|
281
|
+
// Create a GAMBannerView
|
|
282
|
+
gamBanner = AdManagerBannerView(adSize: adSizeFor(cgSize: adSize))
|
|
283
|
+
gamBanner?.adUnitID = adUnitId
|
|
284
|
+
gamBanner?.delegate = self
|
|
285
|
+
gamBanner?.rootViewController = getRootViewController()
|
|
286
|
+
|
|
287
|
+
// Make a bid request to Prebid Server
|
|
288
|
+
let gamRequest = AdManagerRequest()
|
|
289
|
+
bannerAdUnit?.fetchDemand(adObject: gamRequest) { [weak self] resultCode in
|
|
290
|
+
guard let self = self, let gamBanner = self.gamBanner else { return }
|
|
291
|
+
NSLog("VeonPrebid iOS: Prebid demand fetch for GAM - \(resultCode.name())")
|
|
292
|
+
|
|
293
|
+
// Load GAM Ad
|
|
294
|
+
gamBanner.load(gamRequest)
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
internal func loadPrebidBanner() {
|
|
299
|
+
let adSize = CGSize(width: adParameters.bannerWidth, height: adParameters.bannerHeight)
|
|
300
|
+
|
|
301
|
+
guard prebidBannerView == nil,
|
|
302
|
+
let configId = adParameters.configId else {
|
|
303
|
+
return
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
prebidBannerView = BannerView(
|
|
307
|
+
frame: CGRect(origin: .zero, size: adSize),
|
|
308
|
+
configID: configId,
|
|
309
|
+
adSize: adSize
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
// Configure the BannerView
|
|
313
|
+
prebidBannerView?.delegate = self
|
|
314
|
+
prebidBannerView?.adFormat = .banner
|
|
315
|
+
prebidBannerView?.refreshInterval = adParameters.refreshInterval
|
|
316
|
+
|
|
317
|
+
// Load the banner ad
|
|
318
|
+
prebidBannerView?.loadAd()
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// MARK: - Interstitial Loading
|
|
322
|
+
|
|
323
|
+
private func loadInterstitialRendering(configId: String, adUnitId: String) {
|
|
324
|
+
let eventHandler = GAMInterstitialEventHandler(adUnitID: adUnitId)
|
|
325
|
+
let size = CGSize(width: adParameters.bannerWidth, height: adParameters.bannerHeight)
|
|
326
|
+
|
|
327
|
+
prebidInterstitial = InterstitialRenderingAdUnit(
|
|
328
|
+
configID: configId,
|
|
329
|
+
minSizePercentage: size,
|
|
330
|
+
eventHandler: eventHandler
|
|
331
|
+
)
|
|
332
|
+
prebidInterstitial?.delegate = self
|
|
333
|
+
prebidInterstitial?.loadAd()
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private func loadRewardVideo(configId: String, adUnitId: String) {
|
|
337
|
+
let eventHandler = GAMRewardedAdEventHandler(adUnitID: adUnitId)
|
|
338
|
+
rewardedAdUnit = RewardedAdUnit(configID: configId, eventHandler: eventHandler)
|
|
339
|
+
rewardedAdUnit?.delegate = self
|
|
340
|
+
rewardedAdUnit?.loadAd()
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// MARK: - Utility Methods
|
|
344
|
+
|
|
345
|
+
func getRootViewController() -> UIViewController {
|
|
346
|
+
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
347
|
+
let rootViewController = windowScene.windows.first?.rootViewController {
|
|
348
|
+
return rootViewController
|
|
349
|
+
}
|
|
350
|
+
return UIViewController()
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
private func addGamBannerViewToView(_ bannerView: AdManagerBannerView) {
|
|
354
|
+
guard let container = container else { return }
|
|
355
|
+
bannerView.translatesAutoresizingMaskIntoConstraints = false
|
|
356
|
+
container.addSubview(bannerView)
|
|
357
|
+
|
|
358
|
+
NSLayoutConstraint.activate([
|
|
359
|
+
bannerView.centerXAnchor.constraint(equalTo: container.centerXAnchor),
|
|
360
|
+
bannerView.centerYAnchor.constraint(equalTo: container.centerYAnchor)
|
|
361
|
+
])
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
private func addPrebidBannerViewToView(_ bannerView: PrebidMobile.BannerView) {
|
|
365
|
+
guard let container = container else { return }
|
|
366
|
+
bannerView.translatesAutoresizingMaskIntoConstraints = false
|
|
367
|
+
container.addSubview(bannerView)
|
|
368
|
+
|
|
369
|
+
NSLayoutConstraint.activate([
|
|
370
|
+
bannerView.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 5),
|
|
371
|
+
bannerView.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: -5),
|
|
372
|
+
bannerView.centerXAnchor.constraint(equalTo: container.centerXAnchor),
|
|
373
|
+
bannerView.centerYAnchor.constraint(equalTo: container.centerYAnchor)
|
|
374
|
+
])
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
func adSizeFor(cgSize: CGSize) -> AdSize {
|
|
378
|
+
return AdSize(size: cgSize, flags: 0)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
+
#import "VeonPrebidReactNativeViewComponentView.h"
|
|
3
|
+
|
|
4
|
+
#import <React/RCTConversions.h>
|
|
5
|
+
#import <React/RCTFabricComponentsPlugins.h>
|
|
6
|
+
#import <react/renderer/components/VeonPrebidReactNativeViewSpec/ComponentDescriptors.h>
|
|
7
|
+
#import <react/renderer/components/VeonPrebidReactNativeViewSpec/EventEmitters.h>
|
|
8
|
+
#import <react/renderer/components/VeonPrebidReactNativeViewSpec/Props.h>
|
|
9
|
+
#import <react/renderer/components/VeonPrebidReactNativeViewSpec/RCTComponentViewHelpers.h>
|
|
10
|
+
|
|
11
|
+
#import "RCTFabricComponentsPlugins.h"
|
|
12
|
+
#import "VeonPrebidReactNative-Swift.h"
|
|
13
|
+
|
|
14
|
+
using namespace facebook::react;
|
|
15
|
+
|
|
16
|
+
@interface VeonPrebidReactNativeViewComponentView () <RCTVeonPrebidReactNativeViewViewProtocol>
|
|
17
|
+
@end
|
|
18
|
+
|
|
19
|
+
@implementation VeonPrebidReactNativeViewComponentView {
|
|
20
|
+
VeonPrebidReactNativeView *_view;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
24
|
+
{
|
|
25
|
+
return concreteComponentDescriptorProvider<VeonPrebidReactNativeViewComponentDescriptor>();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
29
|
+
{
|
|
30
|
+
if (self = [super initWithFrame:frame]) {
|
|
31
|
+
static const auto defaultProps = std::make_shared<const VeonPrebidReactNativeViewProps>();
|
|
32
|
+
_props = defaultProps;
|
|
33
|
+
|
|
34
|
+
_view = [[VeonPrebidReactNativeView alloc] init];
|
|
35
|
+
_view.frame = self.bounds;
|
|
36
|
+
_view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
37
|
+
|
|
38
|
+
self.contentView = _view;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return self;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
|
45
|
+
{
|
|
46
|
+
const auto &oldViewProps = *std::static_pointer_cast<const VeonPrebidReactNativeViewProps>(_props);
|
|
47
|
+
const auto &newViewProps = *std::static_pointer_cast<const VeonPrebidReactNativeViewProps>(props);
|
|
48
|
+
|
|
49
|
+
// Update adType
|
|
50
|
+
if (oldViewProps.adType != newViewProps.adType) {
|
|
51
|
+
_view.adTypeValue = [NSString stringWithUTF8String:newViewProps.adType.c_str()];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Update configId
|
|
55
|
+
if (oldViewProps.configId != newViewProps.configId) {
|
|
56
|
+
_view.configIdValue = [NSString stringWithUTF8String:newViewProps.configId.c_str()];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Update adUnitId
|
|
60
|
+
if (oldViewProps.adUnitId != newViewProps.adUnitId) {
|
|
61
|
+
_view.adUnitIdValue = [NSString stringWithUTF8String:newViewProps.adUnitId.c_str()];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Update width
|
|
65
|
+
if (oldViewProps.width != newViewProps.width) {
|
|
66
|
+
_view.widthValue = @(newViewProps.width);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Update height
|
|
70
|
+
if (oldViewProps.height != newViewProps.height) {
|
|
71
|
+
_view.heightValue = @(newViewProps.height);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Update refreshInterval
|
|
75
|
+
if (oldViewProps.refreshInterval != newViewProps.refreshInterval) {
|
|
76
|
+
_view.refreshIntervalValue = @(newViewProps.refreshInterval);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
[super updateProps:props oldProps:oldProps];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
- (void)updateEventEmitter:(EventEmitter::Shared const &)eventEmitter
|
|
83
|
+
{
|
|
84
|
+
[super updateEventEmitter:eventEmitter];
|
|
85
|
+
|
|
86
|
+
__weak __typeof(self) weakSelf = self;
|
|
87
|
+
|
|
88
|
+
// Set up event handlers
|
|
89
|
+
_view.onAdLoaded = ^(NSDictionary *event) {
|
|
90
|
+
__typeof(self) strongSelf = weakSelf;
|
|
91
|
+
if (strongSelf && strongSelf->_eventEmitter) {
|
|
92
|
+
auto emitter = std::static_pointer_cast<const VeonPrebidReactNativeViewEventEmitter>(strongSelf->_eventEmitter);
|
|
93
|
+
|
|
94
|
+
VeonPrebidReactNativeViewEventEmitter::OnAdLoaded data;
|
|
95
|
+
if (event[@"adId"]) data.adId = std::string([event[@"adId"] UTF8String]);
|
|
96
|
+
if (event[@"sdk"]) data.sdk = std::string([event[@"sdk"] UTF8String]);
|
|
97
|
+
if (event[@"message"]) data.message = std::string([event[@"message"] UTF8String]);
|
|
98
|
+
|
|
99
|
+
emitter->onAdLoaded(data);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
_view.onAdDisplayed = ^(NSDictionary *event) {
|
|
104
|
+
__typeof(self) strongSelf = weakSelf;
|
|
105
|
+
if (strongSelf && strongSelf->_eventEmitter) {
|
|
106
|
+
auto emitter = std::static_pointer_cast<const VeonPrebidReactNativeViewEventEmitter>(strongSelf->_eventEmitter);
|
|
107
|
+
|
|
108
|
+
VeonPrebidReactNativeViewEventEmitter::OnAdDisplayed data;
|
|
109
|
+
if (event[@"adId"]) data.adId = std::string([event[@"adId"] UTF8String]);
|
|
110
|
+
if (event[@"sdk"]) data.sdk = std::string([event[@"sdk"] UTF8String]);
|
|
111
|
+
if (event[@"message"]) data.message = std::string([event[@"message"] UTF8String]);
|
|
112
|
+
|
|
113
|
+
emitter->onAdDisplayed(data);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
_view.onAdFailed = ^(NSDictionary *event) {
|
|
118
|
+
__typeof(self) strongSelf = weakSelf;
|
|
119
|
+
if (strongSelf && strongSelf->_eventEmitter) {
|
|
120
|
+
auto emitter = std::static_pointer_cast<const VeonPrebidReactNativeViewEventEmitter>(strongSelf->_eventEmitter);
|
|
121
|
+
|
|
122
|
+
VeonPrebidReactNativeViewEventEmitter::OnAdFailed data;
|
|
123
|
+
if (event[@"adId"]) data.adId = std::string([event[@"adId"] UTF8String]);
|
|
124
|
+
if (event[@"sdk"]) data.sdk = std::string([event[@"sdk"] UTF8String]);
|
|
125
|
+
if (event[@"message"]) data.message = std::string([event[@"message"] UTF8String]);
|
|
126
|
+
|
|
127
|
+
emitter->onAdFailed(data);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
_view.onAdClicked = ^(NSDictionary *event) {
|
|
132
|
+
__typeof(self) strongSelf = weakSelf;
|
|
133
|
+
if (strongSelf && strongSelf->_eventEmitter) {
|
|
134
|
+
auto emitter = std::static_pointer_cast<const VeonPrebidReactNativeViewEventEmitter>(strongSelf->_eventEmitter);
|
|
135
|
+
|
|
136
|
+
VeonPrebidReactNativeViewEventEmitter::OnAdClicked data;
|
|
137
|
+
if (event[@"adId"]) data.adId = std::string([event[@"adId"] UTF8String]);
|
|
138
|
+
if (event[@"sdk"]) data.sdk = std::string([event[@"sdk"] UTF8String]);
|
|
139
|
+
if (event[@"message"]) data.message = std::string([event[@"message"] UTF8String]);
|
|
140
|
+
|
|
141
|
+
emitter->onAdClicked(data);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
_view.onAdClosed = ^(NSDictionary *event) {
|
|
146
|
+
__typeof(self) strongSelf = weakSelf;
|
|
147
|
+
if (strongSelf && strongSelf->_eventEmitter) {
|
|
148
|
+
auto emitter = std::static_pointer_cast<const VeonPrebidReactNativeViewEventEmitter>(strongSelf->_eventEmitter);
|
|
149
|
+
|
|
150
|
+
VeonPrebidReactNativeViewEventEmitter::OnAdClosed data;
|
|
151
|
+
if (event[@"adId"]) data.adId = std::string([event[@"adId"] UTF8String]);
|
|
152
|
+
if (event[@"sdk"]) data.sdk = std::string([event[@"sdk"] UTF8String]);
|
|
153
|
+
if (event[@"message"]) data.message = std::string([event[@"message"] UTF8String]);
|
|
154
|
+
|
|
155
|
+
emitter->onAdClosed(data);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
Class<RCTComponentViewProtocol> VeonPrebidReactNativeViewCls(void)
|
|
161
|
+
{
|
|
162
|
+
return VeonPrebidReactNativeViewComponentView.class;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@end
|
|
166
|
+
#endif
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#import <React/RCTViewManager.h>
|
|
2
|
+
#import <React/RCTBridgeModule.h>
|
|
3
|
+
|
|
4
|
+
@interface RCT_EXTERN_MODULE(VeonPrebidReactNativeViewManager, RCTViewManager)
|
|
5
|
+
|
|
6
|
+
// Props - using UIView type
|
|
7
|
+
RCT_CUSTOM_VIEW_PROPERTY(adType, NSString, UIView) {
|
|
8
|
+
[view setValue:[RCTConvert NSString:json] forKey:@"adTypeValue"];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
RCT_CUSTOM_VIEW_PROPERTY(configId, NSString, UIView) {
|
|
12
|
+
[view setValue:[RCTConvert NSString:json] forKey:@"configIdValue"];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
RCT_CUSTOM_VIEW_PROPERTY(adUnitId, NSString, UIView) {
|
|
16
|
+
[view setValue:[RCTConvert NSString:json] forKey:@"adUnitIdValue"];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
RCT_CUSTOM_VIEW_PROPERTY(width, NSNumber, UIView) {
|
|
20
|
+
[view setValue:[RCTConvert NSNumber:json] forKey:@"widthValue"];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
RCT_CUSTOM_VIEW_PROPERTY(height, NSNumber, UIView) {
|
|
24
|
+
[view setValue:[RCTConvert NSNumber:json] forKey:@"heightValue"];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
RCT_CUSTOM_VIEW_PROPERTY(refreshInterval, NSNumber, UIView) {
|
|
28
|
+
[view setValue:[RCTConvert NSNumber:json] forKey:@"refreshIntervalValue"];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Commands (must be BEFORE events in Old Architecture)
|
|
32
|
+
RCT_EXTERN_METHOD(loadBanner:(nonnull NSNumber *)node)
|
|
33
|
+
RCT_EXTERN_METHOD(showBanner:(nonnull NSNumber *)node)
|
|
34
|
+
RCT_EXTERN_METHOD(hideBanner:(nonnull NSNumber *)node)
|
|
35
|
+
RCT_EXTERN_METHOD(loadInterstitial:(nonnull NSNumber *)node)
|
|
36
|
+
RCT_EXTERN_METHOD(showInterstitial:(nonnull NSNumber *)node)
|
|
37
|
+
RCT_EXTERN_METHOD(hideInterstitial:(nonnull NSNumber *)node)
|
|
38
|
+
RCT_EXTERN_METHOD(pauseAuction:(nonnull NSNumber *)node)
|
|
39
|
+
RCT_EXTERN_METHOD(resumeAuction:(nonnull NSNumber *)node)
|
|
40
|
+
RCT_EXTERN_METHOD(destroyAuction:(nonnull NSNumber *)node)
|
|
41
|
+
|
|
42
|
+
// Events (must be AFTER commands)
|
|
43
|
+
RCT_EXPORT_VIEW_PROPERTY(onAdLoaded, RCTDirectEventBlock)
|
|
44
|
+
RCT_EXPORT_VIEW_PROPERTY(onAdDisplayed, RCTDirectEventBlock)
|
|
45
|
+
RCT_EXPORT_VIEW_PROPERTY(onAdFailed, RCTDirectEventBlock)
|
|
46
|
+
RCT_EXPORT_VIEW_PROPERTY(onAdClicked, RCTDirectEventBlock)
|
|
47
|
+
RCT_EXPORT_VIEW_PROPERTY(onAdClosed, RCTDirectEventBlock)
|
|
48
|
+
|
|
49
|
+
@end
|