react-native-applovin-max 8.1.1 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/android/build.gradle +14 -3
  2. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdView.java +33 -26
  3. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewManagerImpl.java +110 -0
  4. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewUiComponent.java +17 -15
  5. package/android/src/main/java/com/applovin/reactnative/{AppLovinMAXModule.java → AppLovinMAXModuleImpl.java} +115 -179
  6. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdView.java +84 -56
  7. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManagerImpl.java +101 -0
  8. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXPackage.java +44 -11
  9. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXUtils.java +56 -0
  10. package/android/src/newarch/com/applovin/reactnative/AppLovinMAXAdViewManager.java +151 -0
  11. package/android/src/newarch/com/applovin/reactnative/AppLovinMAXModule.java +453 -0
  12. package/android/src/newarch/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +130 -0
  13. package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXAdViewManager.java +128 -0
  14. package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXModule.java +453 -0
  15. package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +93 -0
  16. package/ios/AppLovinMAX.h +8 -8
  17. package/ios/{AppLovinMAX.m → AppLovinMAX.mm} +73 -64
  18. package/ios/AppLovinMAXAdView.h +7 -2
  19. package/ios/AppLovinMAXAdView.mm +747 -0
  20. package/ios/{AppLovinMAXAdViewManager.m → AppLovinMAXAdViewManager.mm} +3 -2
  21. package/ios/{AppLovinMAXAdViewUIComponent.m → AppLovinMAXAdViewUIComponent.mm} +2 -1
  22. package/ios/AppLovinMAXNativeAdView.h +15 -4
  23. package/ios/AppLovinMAXNativeAdView.mm +745 -0
  24. package/ios/AppLovinMAXNativeAdViewManager.mm +116 -0
  25. package/lib/commonjs/AdView.js +67 -85
  26. package/lib/commonjs/AdView.js.map +1 -1
  27. package/lib/commonjs/AppLovinMAX.js +51 -10
  28. package/lib/commonjs/AppLovinMAX.js.map +1 -1
  29. package/lib/commonjs/AppOpenAd.js +8 -10
  30. package/lib/commonjs/AppOpenAd.js.map +1 -1
  31. package/lib/commonjs/BannerAd.js +19 -21
  32. package/lib/commonjs/BannerAd.js.map +1 -1
  33. package/lib/commonjs/ErrorCode.js +57 -5
  34. package/lib/commonjs/ErrorCode.js.map +1 -1
  35. package/lib/commonjs/EventEmitter.js +3 -5
  36. package/lib/commonjs/EventEmitter.js.map +1 -1
  37. package/lib/commonjs/InterstitialAd.js +8 -10
  38. package/lib/commonjs/InterstitialAd.js.map +1 -1
  39. package/lib/commonjs/MRecAd.js +14 -16
  40. package/lib/commonjs/MRecAd.js.map +1 -1
  41. package/lib/commonjs/Privacy.js +3 -5
  42. package/lib/commonjs/Privacy.js.map +1 -1
  43. package/lib/commonjs/RewardedAd.js +8 -10
  44. package/lib/commonjs/RewardedAd.js.map +1 -1
  45. package/lib/commonjs/Utils.js +25 -0
  46. package/lib/commonjs/Utils.js.map +1 -0
  47. package/lib/commonjs/nativeAd/NativeAdView.js +65 -42
  48. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  49. package/lib/commonjs/nativeAd/NativeAdViewComponents.js +51 -47
  50. package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
  51. package/lib/commonjs/nativeAd/NativeAdViewProvider.js +38 -8
  52. package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
  53. package/lib/commonjs/nativeAd/img/blank_icon.png +0 -0
  54. package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js +14 -0
  55. package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -0
  56. package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js +14 -0
  57. package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -0
  58. package/lib/commonjs/specs/NativeAppLovinMAXModule.js +9 -0
  59. package/lib/commonjs/specs/NativeAppLovinMAXModule.js.map +1 -0
  60. package/lib/commonjs/types/AdInfo.js +10 -3
  61. package/lib/commonjs/types/AdInfo.js.map +1 -1
  62. package/lib/module/AdView.js +62 -81
  63. package/lib/module/AdView.js.map +1 -1
  64. package/lib/module/AppLovinMAX.js +47 -7
  65. package/lib/module/AppLovinMAX.js.map +1 -1
  66. package/lib/module/AppOpenAd.js +1 -4
  67. package/lib/module/AppOpenAd.js.map +1 -1
  68. package/lib/module/BannerAd.js +1 -4
  69. package/lib/module/BannerAd.js.map +1 -1
  70. package/lib/module/ErrorCode.js +55 -4
  71. package/lib/module/ErrorCode.js.map +1 -1
  72. package/lib/module/EventEmitter.js +2 -4
  73. package/lib/module/EventEmitter.js.map +1 -1
  74. package/lib/module/InterstitialAd.js +2 -5
  75. package/lib/module/InterstitialAd.js.map +1 -1
  76. package/lib/module/MRecAd.js +1 -4
  77. package/lib/module/MRecAd.js.map +1 -1
  78. package/lib/module/Privacy.js +1 -4
  79. package/lib/module/Privacy.js.map +1 -1
  80. package/lib/module/RewardedAd.js +2 -5
  81. package/lib/module/RewardedAd.js.map +1 -1
  82. package/lib/module/Utils.js +17 -0
  83. package/lib/module/Utils.js.map +1 -0
  84. package/lib/module/nativeAd/NativeAdView.js +63 -40
  85. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  86. package/lib/module/nativeAd/NativeAdViewComponents.js +53 -49
  87. package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
  88. package/lib/module/nativeAd/NativeAdViewProvider.js +39 -9
  89. package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
  90. package/lib/module/nativeAd/img/blank_icon.png +0 -0
  91. package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js +7 -0
  92. package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -0
  93. package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js +7 -0
  94. package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -0
  95. package/lib/module/specs/NativeAppLovinMAXModule.js +3 -0
  96. package/lib/module/specs/NativeAppLovinMAXModule.js.map +1 -0
  97. package/lib/module/types/AdInfo.js +10 -4
  98. package/lib/module/types/AdInfo.js.map +1 -1
  99. package/lib/typescript/src/AdView.d.ts +16 -16
  100. package/lib/typescript/src/AdView.d.ts.map +1 -1
  101. package/lib/typescript/src/AppLovinMAX.d.ts.map +1 -1
  102. package/lib/typescript/src/AppOpenAd.d.ts.map +1 -1
  103. package/lib/typescript/src/BannerAd.d.ts.map +1 -1
  104. package/lib/typescript/src/ErrorCode.d.ts.map +1 -1
  105. package/lib/typescript/src/EventEmitter.d.ts.map +1 -1
  106. package/lib/typescript/src/InterstitialAd.d.ts.map +1 -1
  107. package/lib/typescript/src/MRecAd.d.ts.map +1 -1
  108. package/lib/typescript/src/Privacy.d.ts.map +1 -1
  109. package/lib/typescript/src/RewardedAd.d.ts.map +1 -1
  110. package/lib/typescript/src/Utils.d.ts +16 -0
  111. package/lib/typescript/src/Utils.d.ts.map +1 -0
  112. package/lib/typescript/src/nativeAd/NativeAdView.d.ts.map +1 -1
  113. package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts +1 -1
  114. package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  115. package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts +14 -5
  116. package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  117. package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts +86 -0
  118. package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts.map +1 -0
  119. package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts +80 -0
  120. package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts.map +1 -0
  121. package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts +132 -0
  122. package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts.map +1 -0
  123. package/lib/typescript/src/types/AdEvent.d.ts +2 -2
  124. package/lib/typescript/src/types/AdEvent.d.ts.map +1 -1
  125. package/lib/typescript/src/types/AdInfo.d.ts +24 -25
  126. package/lib/typescript/src/types/AdInfo.d.ts.map +1 -1
  127. package/lib/typescript/src/types/AdProps.d.ts +4 -4
  128. package/lib/typescript/src/types/AdProps.d.ts.map +1 -1
  129. package/lib/typescript/src/types/FullscreenAd.d.ts +4 -4
  130. package/lib/typescript/src/types/FullscreenAd.d.ts.map +1 -1
  131. package/lib/typescript/src/types/NativeAd.d.ts +4 -0
  132. package/lib/typescript/src/types/NativeAd.d.ts.map +1 -1
  133. package/lib/typescript/src/types/ViewAd.d.ts +4 -4
  134. package/lib/typescript/src/types/ViewAd.d.ts.map +1 -1
  135. package/package.json +9 -1
  136. package/react-native-applovin-max.podspec +3 -3
  137. package/src/AdView.tsx +56 -121
  138. package/src/AppLovinMAX.ts +7 -8
  139. package/src/AppOpenAd.ts +3 -5
  140. package/src/BannerAd.ts +3 -5
  141. package/src/ErrorCode.ts +1 -3
  142. package/src/EventEmitter.ts +2 -3
  143. package/src/InterstitialAd.ts +4 -6
  144. package/src/MRecAd.ts +3 -5
  145. package/src/Privacy.ts +1 -3
  146. package/src/RewardedAd.ts +4 -6
  147. package/src/Utils.ts +26 -0
  148. package/src/nativeAd/NativeAdView.tsx +65 -65
  149. package/src/nativeAd/NativeAdViewComponents.tsx +32 -60
  150. package/src/nativeAd/NativeAdViewProvider.tsx +37 -12
  151. package/src/nativeAd/img/blank_icon.png +0 -0
  152. package/src/specs/AppLovinMAXAdViewNativeComponent.ts +96 -0
  153. package/src/specs/AppLovinMAXNativeAdViewNativeComponent.ts +89 -0
  154. package/src/specs/NativeAppLovinMAXModule.ts +208 -0
  155. package/src/types/AdEvent.ts +2 -2
  156. package/src/types/AdInfo.ts +28 -28
  157. package/src/types/AdProps.ts +4 -4
  158. package/src/types/FullscreenAd.ts +4 -4
  159. package/src/types/NativeAd.ts +5 -0
  160. package/src/types/ViewAd.ts +4 -4
  161. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewManager.java +0 -149
  162. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +0 -163
  163. package/ios/AppLovinMAXAdView.m +0 -323
  164. package/ios/AppLovinMAXNativeAdView.m +0 -432
  165. package/ios/AppLovinMAXNativeAdViewManager.m +0 -64
@@ -0,0 +1,747 @@
1
+ //
2
+ // AppLovinMAXAdView.m
3
+ // AppLovin MAX React Native Module
4
+ //
5
+ // Copyright © 2022 AppLovin. All rights reserved.
6
+ //
7
+
8
+ #import <AppLovinSDK/AppLovinSDK.h>
9
+ #import "AppLovinMAX.h"
10
+ #import "AppLovinMAXAdView.h"
11
+ #import "AppLovinMAXAdViewUIComponent.h"
12
+
13
+ #ifdef RCT_NEW_ARCH_ENABLED
14
+
15
+ #import <react/renderer/components/RNAppLovinMAXSpec/ComponentDescriptors.h>
16
+ #import <react/renderer/components/RNAppLovinMAXSpec/EventEmitters.h>
17
+ #import <react/renderer/components/RNAppLovinMAXSpec/Props.h>
18
+ #import <react/renderer/components/RNAppLovinMAXSpec/RCTComponentViewHelpers.h>
19
+ #import <React/RCTConversions.h>
20
+ #import "RCTFabricComponentsPlugins.h"
21
+
22
+ using namespace facebook::react;
23
+
24
+ @interface AppLovinMAXAdView() <RCTAppLovinMAXAdViewViewProtocol>
25
+ #else
26
+ @interface AppLovinMAXAdView()
27
+ #endif
28
+
29
+ @property (nonatomic, strong, nullable) AppLovinMAXAdViewUIComponent *uiComponent; // nil when unmounted
30
+
31
+ // The following properties are updated from RN layer via the view manager
32
+ @property (nonatomic, copy) NSString *adUnitId;
33
+ @property (nonatomic, weak) MAAdFormat *adFormat;
34
+ @property (nonatomic, copy) NSNumber *adViewId;
35
+ @property (nonatomic, copy, nullable) NSString *placement;
36
+ @property (nonatomic, copy, nullable) NSString *customData;
37
+ @property (nonatomic, assign, readonly, getter=isAdaptiveBannerEnabled) BOOL adaptiveBannerEnabled;
38
+ @property (nonatomic, assign, readonly, getter=isAutoRefreshEnabled) BOOL autoRefresh;
39
+ @property (nonatomic, assign, readonly, getter=isLoadOnMount) BOOL loadOnMount;
40
+ @property (nonatomic, copy, nullable) NSArray<NSDictionary<NSString *, id> *> *extraParameters;
41
+ @property (nonatomic, copy, nullable) NSArray<NSDictionary<NSString *, id> *> *localExtraParameters;
42
+
43
+ @end
44
+
45
+ @implementation AppLovinMAXAdView
46
+
47
+ static NSMutableDictionary<NSNumber *, AppLovinMAXAdViewUIComponent *> *uiComponentInstances;
48
+ static NSMutableDictionary<NSNumber *, AppLovinMAXAdViewUIComponent *> *preloadedUIComponentInstances;
49
+
50
+ + (void)initialize
51
+ {
52
+ [super initialize];
53
+ uiComponentInstances = [NSMutableDictionary dictionaryWithCapacity: 2];
54
+ preloadedUIComponentInstances = [NSMutableDictionary dictionaryWithCapacity: 2];
55
+ }
56
+
57
+ // Returns an MAAdView to support Amazon integrations. This method returns the first instance that
58
+ // matches the Ad Unit ID, consistent with the behavior introduced when this feature was first
59
+ // implemented.
60
+ + (nullable MAAdView *)sharedWithAdUnitIdentifier:(NSString *)adUnitIdentifier
61
+ {
62
+ for ( id key in preloadedUIComponentInstances )
63
+ {
64
+ AppLovinMAXAdViewUIComponent *uiComponent = preloadedUIComponentInstances[key];
65
+ if ( [uiComponent.adUnitIdentifier isEqualToString: adUnitIdentifier] )
66
+ {
67
+ return uiComponent.adView;
68
+ }
69
+ }
70
+
71
+ for ( id key in uiComponentInstances )
72
+ {
73
+ AppLovinMAXAdViewUIComponent *uiComponent = uiComponentInstances[key];
74
+ if ( [uiComponent.adUnitIdentifier isEqualToString: adUnitIdentifier] )
75
+ {
76
+ return uiComponent.adView;
77
+ }
78
+ }
79
+
80
+ return nil;
81
+ }
82
+
83
+ + (BOOL)hasPreloadedAdViewForIdentifier:(NSNumber *)adViewId
84
+ {
85
+ return preloadedUIComponentInstances[adViewId];
86
+ }
87
+
88
+ + (void)preloadNativeUIComponentAdView:(NSString *)adUnitIdentifier
89
+ adFormat:(MAAdFormat *)adFormat
90
+ placement:(nullable NSString *)placement
91
+ customData:(nullable NSString *)customData
92
+ extraParameters:(nullable NSDictionary<NSString *, id> *)extraParameters
93
+ localExtraParameters:(nullable NSDictionary<NSString *, id> *)localExtraParameters
94
+ withPromiseResolver:(RCTPromiseResolveBlock)resolve
95
+ withPromiseRejecter:(RCTPromiseRejectBlock)reject
96
+ {
97
+ AppLovinMAXAdViewUIComponent *preloadedUIComponent = [[AppLovinMAXAdViewUIComponent alloc] initWithAdUnitIdentifier: adUnitIdentifier adFormat: adFormat];
98
+ preloadedUIComponentInstances[@(preloadedUIComponent.hash)] = preloadedUIComponent;
99
+
100
+ preloadedUIComponent.placement = placement;
101
+ preloadedUIComponent.customData = customData;
102
+ preloadedUIComponent.extraParameters = extraParameters;
103
+ preloadedUIComponent.localExtraParameters = localExtraParameters;
104
+
105
+ [preloadedUIComponent loadAd];
106
+
107
+ resolve(@(preloadedUIComponent.hash));
108
+ }
109
+
110
+ + (void)destroyNativeUIComponentAdView:(NSNumber *)adViewId
111
+ withPromiseResolver:(RCTPromiseResolveBlock)resolve
112
+ withPromiseRejecter:(RCTPromiseRejectBlock)reject
113
+ {
114
+ AppLovinMAXAdViewUIComponent *preloadedUIComponent = preloadedUIComponentInstances[adViewId];
115
+ if ( !preloadedUIComponent )
116
+ {
117
+ reject(RCTErrorUnspecified, @"No preloaded AdView found to destroy", nil);
118
+ return;
119
+ }
120
+
121
+ if ( [preloadedUIComponent hasContainerView] )
122
+ {
123
+ reject(RCTErrorUnspecified, @"Cannot destroy - the preloaded AdView is currently in use", nil);
124
+ return;
125
+ }
126
+
127
+ [preloadedUIComponentInstances removeObjectForKey: adViewId];
128
+
129
+ [preloadedUIComponent detachAdView];
130
+ [preloadedUIComponent destroy];
131
+
132
+ resolve(nil);
133
+ }
134
+
135
+ #ifdef RCT_NEW_ARCH_ENABLED
136
+
137
+ + (ComponentDescriptorProvider)componentDescriptorProvider
138
+ {
139
+ return concreteComponentDescriptorProvider<AppLovinMAXAdViewComponentDescriptor>();
140
+ }
141
+
142
+ - (instancetype)initWithFrame:(CGRect)frame
143
+ {
144
+ self = [super initWithFrame: frame];
145
+ if ( self )
146
+ {
147
+ static const auto defaultProps = std::make_shared<const AppLovinMAXAdViewProps>();
148
+ _props = defaultProps;
149
+
150
+ const auto &initProps = *std::static_pointer_cast<AppLovinMAXAdViewProps const>(_props);
151
+ _adaptiveBannerEnabled = initProps.adaptiveBannerEnabled;
152
+ _autoRefresh = initProps.autoRefresh;
153
+ _loadOnMount = initProps.loadOnMount;
154
+
155
+ [self setupEventHandlers];
156
+ }
157
+ return self;
158
+ }
159
+
160
+ - (void)setupEventHandlers
161
+ {
162
+ self.onAdLoadedEvent = [self](NSDictionary *event)
163
+ {
164
+ if ( _eventEmitter )
165
+ {
166
+ auto adViewEventEmitter = std::static_pointer_cast<AppLovinMAXAdViewEventEmitter const>(_eventEmitter);
167
+
168
+ AppLovinMAXAdViewEventEmitter::OnAdLoadedEvent result =
169
+ {
170
+ .adUnitId = std::string([event[@"adUnitId"] ?: @"" UTF8String]),
171
+ .adFormat = std::string([event[@"adFormat"] ?: @"" UTF8String]),
172
+ .adViewId = [event[@"adViewId"] doubleValue],
173
+ .networkName = std::string([event[@"networkName"] ?: @"" UTF8String]),
174
+ .networkPlacement = std::string([event[@"networkPlacement"] ?: @"" UTF8String]),
175
+ .creativeId = std::string([event[@"creativeId"] ?: @"" UTF8String]),
176
+ .placement = std::string([event[@"placement"] ?: @"" UTF8String]),
177
+ .revenue = [event[@"revenue"] doubleValue],
178
+ .revenuePrecision = std::string([event[@"revenuePrecision"] ?: @"" UTF8String]),
179
+ .latencyMillis = [event[@"latencyMillis"] doubleValue],
180
+ .dspName = std::string([event[@"dspName"] ?: @"" UTF8String]),
181
+ .size = {
182
+ .width = [event[@"size"][@"width"] doubleValue],
183
+ .height = [event[@"size"][@"height"] doubleValue],
184
+ }
185
+ };
186
+
187
+ adViewEventEmitter->onAdLoadedEvent(result);
188
+ }
189
+ };
190
+
191
+ self.onAdLoadFailedEvent = [self](NSDictionary *event)
192
+ {
193
+ if ( _eventEmitter )
194
+ {
195
+ auto adViewEventEmitter = std::static_pointer_cast<AppLovinMAXAdViewEventEmitter const>(_eventEmitter);
196
+
197
+ AppLovinMAXAdViewEventEmitter::OnAdLoadFailedEvent result =
198
+ {
199
+ .adUnitId = std::string([event[@"adUnitId"] ?: @"" UTF8String]),
200
+ .adViewId = [event[@"adViewId"] doubleValue],
201
+ .code = [event[@"code"] doubleValue],
202
+ .message = std::string([event[@"message"] ?: @"" UTF8String]),
203
+ .mediatedNetworkErrorCode = [event[@"mediatedNetworkErrorCode"] doubleValue],
204
+ .mediatedNetworkErrorMessage = std::string([event[@"mediatedNetworkErrorMessage"] ?: @"" UTF8String]),
205
+ .adLoadFailureInfo = std::string([event[@"adLoadFailureInfo"] ?: @"" UTF8String])
206
+ };
207
+
208
+ adViewEventEmitter->onAdLoadFailedEvent(result);
209
+ }
210
+ };
211
+
212
+ self.onAdDisplayFailedEvent = [self](NSDictionary *event)
213
+ {
214
+ if ( _eventEmitter )
215
+ {
216
+ auto adViewEventEmitter = std::static_pointer_cast<AppLovinMAXAdViewEventEmitter const>(_eventEmitter);
217
+
218
+ AppLovinMAXAdViewEventEmitter::OnAdDisplayFailedEvent result =
219
+ {
220
+ .adUnitId = std::string([event[@"adUnitId"] ?: @"" UTF8String]),
221
+ .adFormat = std::string([event[@"adFormat"] ?: @"" UTF8String]),
222
+ .adViewId = [event[@"adViewId"] doubleValue],
223
+ .networkName = std::string([event[@"networkName"] ?: @"" UTF8String]),
224
+ .networkPlacement = std::string([event[@"networkPlacement"] ?: @"" UTF8String]),
225
+ .creativeId = std::string([event[@"creativeId"] ?: @"" UTF8String]),
226
+ .placement = std::string([event[@"placement"] ?: @"" UTF8String]),
227
+ .revenue = [event[@"revenue"] doubleValue],
228
+ .revenuePrecision = std::string([event[@"revenuePrecision"] ?: @"" UTF8String]),
229
+ .latencyMillis = [event[@"latencyMillis"] doubleValue],
230
+ .code = [event[@"code"] doubleValue],
231
+ .message = std::string([event[@"message"] ?: @"" UTF8String]),
232
+ .mediatedNetworkErrorCode = [event[@"mediatedNetworkErrorCode"] doubleValue],
233
+ .mediatedNetworkErrorMessage = std::string([event[@"mediatedNetworkErrorMessage"] ?: @"" UTF8String]),
234
+ .size = {
235
+ .width = [event[@"size"][@"width"] doubleValue],
236
+ .height = [event[@"size"][@"height"] doubleValue],
237
+ }
238
+ };
239
+
240
+ adViewEventEmitter->onAdDisplayFailedEvent(result);
241
+ }
242
+ };
243
+
244
+ self.onAdClickedEvent = [self](NSDictionary *event)
245
+ {
246
+ if ( _eventEmitter )
247
+ {
248
+ auto adViewEventEmitter = std::static_pointer_cast<AppLovinMAXAdViewEventEmitter const>(_eventEmitter);
249
+
250
+ AppLovinMAXAdViewEventEmitter::OnAdClickedEvent result =
251
+ {
252
+ .adUnitId = std::string([event[@"adUnitId"] ?: @"" UTF8String]),
253
+ .adFormat = std::string([event[@"adFormat"] ?: @"" UTF8String]),
254
+ .adViewId = [event[@"adViewId"] doubleValue],
255
+ .networkName = std::string([event[@"networkName"] ?: @"" UTF8String]),
256
+ .networkPlacement = std::string([event[@"networkPlacement"] ?: @"" UTF8String]),
257
+ .creativeId = std::string([event[@"creativeId"] ?: @"" UTF8String]),
258
+ .placement = std::string([event[@"placement"] ?: @"" UTF8String]),
259
+ .revenue = [event[@"revenue"] doubleValue],
260
+ .revenuePrecision = std::string([event[@"revenuePrecision"] ?: @"" UTF8String]),
261
+ .latencyMillis = [event[@"latencyMillis"] doubleValue],
262
+ .size = {
263
+ .width = [event[@"size"][@"width"] doubleValue],
264
+ .height = [event[@"size"][@"height"] doubleValue],
265
+ }
266
+ };
267
+
268
+ adViewEventEmitter->onAdClickedEvent(result);
269
+ }
270
+ };
271
+
272
+ self.onAdExpandedEvent = [self](NSDictionary *event)
273
+ {
274
+ if ( _eventEmitter )
275
+ {
276
+ auto adViewEventEmitter = std::static_pointer_cast<AppLovinMAXAdViewEventEmitter const>(_eventEmitter);
277
+
278
+ AppLovinMAXAdViewEventEmitter::OnAdExpandedEvent result =
279
+ {
280
+ .adUnitId = std::string([event[@"adUnitId"] ?: @"" UTF8String]),
281
+ .adFormat = std::string([event[@"adFormat"] ?: @"" UTF8String]),
282
+ .adViewId = [event[@"adViewId"] doubleValue],
283
+ .networkName = std::string([event[@"networkName"] ?: @"" UTF8String]),
284
+ .networkPlacement = std::string([event[@"networkPlacement"] ?: @"" UTF8String]),
285
+ .creativeId = std::string([event[@"creativeId"] ?: @"" UTF8String]),
286
+ .placement = std::string([event[@"placement"] ?: @"" UTF8String]),
287
+ .revenue = [event[@"revenue"] doubleValue],
288
+ .revenuePrecision = std::string([event[@"revenuePrecision"] ?: @"" UTF8String]),
289
+ .latencyMillis = [event[@"latencyMillis"] doubleValue],
290
+ .size = {
291
+ .width = [event[@"size"][@"width"] doubleValue],
292
+ .height = [event[@"size"][@"height"] doubleValue],
293
+ }
294
+ };
295
+
296
+ adViewEventEmitter->onAdExpandedEvent(result);
297
+ }
298
+ };
299
+
300
+ self.onAdCollapsedEvent = [self](NSDictionary *event)
301
+ {
302
+ if ( _eventEmitter )
303
+ {
304
+ auto adViewEventEmitter = std::static_pointer_cast<AppLovinMAXAdViewEventEmitter const>(_eventEmitter);
305
+
306
+ AppLovinMAXAdViewEventEmitter::OnAdCollapsedEvent result =
307
+ {
308
+ .adUnitId = std::string([event[@"adUnitId"] ?: @"" UTF8String]),
309
+ .adFormat = std::string([event[@"adFormat"] ?: @"" UTF8String]),
310
+ .adViewId = [event[@"adViewId"] doubleValue],
311
+ .networkName = std::string([event[@"networkName"] ?: @"" UTF8String]),
312
+ .networkPlacement = std::string([event[@"networkPlacement"] ?: @"" UTF8String]),
313
+ .creativeId = std::string([event[@"creativeId"] ?: @"" UTF8String]),
314
+ .placement = std::string([event[@"placement"] ?: @"" UTF8String]),
315
+ .revenue = [event[@"revenue"] doubleValue],
316
+ .revenuePrecision = std::string([event[@"revenuePrecision"] ?: @"" UTF8String]),
317
+ .latencyMillis = [event[@"latencyMillis"] doubleValue],
318
+ .size = {
319
+ .width = [event[@"size"][@"width"] doubleValue],
320
+ .height = [event[@"size"][@"height"] doubleValue],
321
+ }
322
+ };
323
+
324
+ adViewEventEmitter->onAdCollapsedEvent(result);
325
+ }
326
+ };
327
+
328
+ self.onAdRevenuePaidEvent = [self](NSDictionary *event)
329
+ {
330
+ if ( _eventEmitter )
331
+ {
332
+ auto adViewEventEmitter = std::static_pointer_cast<AppLovinMAXAdViewEventEmitter const>(_eventEmitter);
333
+
334
+ AppLovinMAXAdViewEventEmitter::OnAdRevenuePaidEvent result =
335
+ {
336
+ .adUnitId = std::string([event[@"adUnitId"] ?: @"" UTF8String]),
337
+ .adFormat = std::string([event[@"adFormat"] ?: @"" UTF8String]),
338
+ .adViewId = [event[@"adViewId"] doubleValue],
339
+ .networkName = std::string([event[@"networkName"] ?: @"" UTF8String]),
340
+ .networkPlacement = std::string([event[@"networkPlacement"] ?: @"" UTF8String]),
341
+ .creativeId = std::string([event[@"creativeId"] ?: @"" UTF8String]),
342
+ .placement = std::string([event[@"placement"] ?: @"" UTF8String]),
343
+ .revenue = [event[@"revenue"] doubleValue],
344
+ .revenuePrecision = std::string([event[@"revenuePrecision"] ?: @"" UTF8String]),
345
+ .latencyMillis = [event[@"latencyMillis"] doubleValue],
346
+ .size = {
347
+ .width = [event[@"size"][@"width"] doubleValue],
348
+ .height = [event[@"size"][@"height"] doubleValue],
349
+ }
350
+ };
351
+
352
+ adViewEventEmitter->onAdRevenuePaidEvent(result);
353
+ }
354
+ };
355
+ }
356
+
357
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
358
+ {
359
+ const auto &oldViewProps = *std::static_pointer_cast<AppLovinMAXAdViewProps const>(_props);
360
+ const auto &newViewProps = *std::static_pointer_cast<AppLovinMAXAdViewProps const>(props);
361
+
362
+ BOOL isAdUnitIdSet;
363
+
364
+ if ( oldViewProps.adUnitId != newViewProps.adUnitId )
365
+ {
366
+ [self setAdUnitId: RCTNSStringFromString(newViewProps.adUnitId)];
367
+ isAdUnitIdSet = YES;
368
+ }
369
+
370
+ if ( oldViewProps.adFormat != newViewProps.adFormat )
371
+ {
372
+ NSString *adFormatStr = RCTNSStringFromString(newViewProps.adFormat);
373
+
374
+ if ( [@"BANNER" al_isEqualToStringIgnoringCase: adFormatStr] )
375
+ {
376
+ _adFormat = DEVICE_SPECIFIC_ADVIEW_AD_FORMAT;
377
+ }
378
+ else if ( [@"MREC" al_isEqualToStringIgnoringCase: adFormatStr] )
379
+ {
380
+ _adFormat = MAAdFormat.mrec;
381
+ }
382
+ else
383
+ {
384
+ [[AppLovinMAX shared] log: @"Attempting to set an invalid ad format of \"%@\" for %@", adFormatStr, self.adUnitId];
385
+ }
386
+ }
387
+
388
+ if ( oldViewProps.adViewId != newViewProps.adViewId )
389
+ {
390
+ [self setAdViewId: @(newViewProps.adViewId)];
391
+ }
392
+
393
+ if ( oldViewProps.placement != newViewProps.placement )
394
+ {
395
+ [self setPlacement: RCTNSStringFromStringNilIfEmpty(newViewProps.placement)];
396
+ }
397
+
398
+ if ( oldViewProps.customData != newViewProps.customData )
399
+ {
400
+ [self setCustomData: RCTNSStringFromStringNilIfEmpty(newViewProps.customData)];
401
+ }
402
+
403
+ if ( oldViewProps.adaptiveBannerEnabled != newViewProps.adaptiveBannerEnabled )
404
+ {
405
+ [self setAdaptiveBannerEnabled: newViewProps.adaptiveBannerEnabled];
406
+ }
407
+
408
+ if ( oldViewProps.autoRefresh != newViewProps.autoRefresh )
409
+ {
410
+ [self setAutoRefresh: newViewProps.autoRefresh];
411
+ }
412
+
413
+ if ( oldViewProps.loadOnMount != newViewProps.loadOnMount )
414
+ {
415
+ [self setLoadOnMount: newViewProps.loadOnMount];
416
+ }
417
+
418
+ if ( newViewProps.extraParameters.size() > 0 )
419
+ {
420
+ NSMutableArray *extraParameters = [NSMutableArray array];
421
+
422
+ for ( const auto &parameter: newViewProps.extraParameters )
423
+ {
424
+ NSDictionary *dict = @{@"key": RCTNSStringFromString(parameter.key),
425
+ @"value": RCTNSStringFromString(parameter.value)};
426
+ [extraParameters addObject: dict];
427
+ }
428
+
429
+ _extraParameters = extraParameters;
430
+ }
431
+
432
+ if ( newViewProps.strLocalExtraParameters.size() > 0 )
433
+ {
434
+ NSMutableArray *strLocalExtraParameters = [NSMutableArray array];
435
+
436
+ for ( const auto &parameter: newViewProps.strLocalExtraParameters )
437
+ {
438
+ NSDictionary *dict = @{@"key": RCTNSStringFromString(parameter.key),
439
+ @"value": RCTNSStringFromString(parameter.value)};
440
+ [strLocalExtraParameters addObject: dict];
441
+ }
442
+
443
+ [self setStrLocalExtraParameters: strLocalExtraParameters];
444
+ }
445
+
446
+ if ( newViewProps.boolLocalExtraParameters.size() > 0 )
447
+ {
448
+ NSMutableArray *boolLocalExtraParameters = [NSMutableArray array];
449
+
450
+ for ( const auto &parameter: newViewProps.boolLocalExtraParameters )
451
+ {
452
+ NSDictionary *dict = @{@"key": RCTNSStringFromString(parameter.key),
453
+ @"value": @(parameter.value)};
454
+ [boolLocalExtraParameters addObject: dict];
455
+ }
456
+
457
+ [self setBoolLocalExtraParameters: boolLocalExtraParameters];
458
+ }
459
+
460
+ if ( isAdUnitIdSet )
461
+ {
462
+ [self attachAdViewIfNeeded];
463
+ }
464
+
465
+ [super updateProps: props oldProps: oldProps];
466
+ }
467
+
468
+ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
469
+ {
470
+ if ( [commandName isEqualToString: @"loadAd"] )
471
+ {
472
+ [self loadAd];
473
+ }
474
+ }
475
+
476
+ - (void)prepareForRecycle
477
+ {
478
+ [super prepareForRecycle];
479
+
480
+ static const auto defaultProps = std::make_shared<const AppLovinMAXAdViewProps>();
481
+ _props = defaultProps;
482
+
483
+ [self destroyCurrentAdIfNeeded];
484
+ }
485
+
486
+ #endif // RCT_NEW_ARCH_ENABLED
487
+
488
+ - (void)setAdUnitId:(NSString *)adUnitId
489
+ {
490
+ // Ad Unit ID must be set prior to creating MAAdView
491
+ if ( self.uiComponent )
492
+ {
493
+ [[AppLovinMAX shared] log: @"Attempting to set Ad Unit ID %@ after the native UI component is created", adUnitId];
494
+ return;
495
+ }
496
+
497
+ _adUnitId = adUnitId;
498
+ }
499
+
500
+ - (void)setAdFormat:(NSString *)adFormatStr
501
+ {
502
+ // Ad format must be set prior to creating MAAdView
503
+ if ( self.uiComponent )
504
+ {
505
+ [[AppLovinMAX shared] log: @"Attempting to set ad format %@ after the native UI component is created", adFormatStr];
506
+ return;
507
+ }
508
+
509
+ if ( [@"BANNER" al_isEqualToStringIgnoringCase: adFormatStr] )
510
+ {
511
+ _adFormat = DEVICE_SPECIFIC_ADVIEW_AD_FORMAT;
512
+ }
513
+ else if ( [@"MREC" al_isEqualToStringIgnoringCase: adFormatStr] )
514
+ {
515
+ _adFormat = MAAdFormat.mrec;
516
+ }
517
+ else
518
+ {
519
+ [[AppLovinMAX shared] log: @"Attempting to set an invalid ad format of \"%@\" for %@", adFormatStr, self.adUnitId];
520
+ }
521
+ }
522
+
523
+ - (void)setAdViewId:(NSNumber *)adViewId
524
+ {
525
+ _adViewId = adViewId;
526
+ }
527
+
528
+ - (void)setPlacement:(NSString *)placement
529
+ {
530
+ _placement = placement;
531
+
532
+ if ( self.uiComponent )
533
+ {
534
+ self.uiComponent.placement = placement;
535
+ }
536
+ }
537
+
538
+ - (void)setCustomData:(NSString *)customData
539
+ {
540
+ _customData = customData;
541
+
542
+ if ( self.uiComponent )
543
+ {
544
+ self.uiComponent.customData = customData;
545
+ }
546
+ }
547
+
548
+ - (void)setAdaptiveBannerEnabled:(BOOL)adaptiveBannerEnabled
549
+ {
550
+ _adaptiveBannerEnabled = adaptiveBannerEnabled;
551
+
552
+ if ( self.uiComponent )
553
+ {
554
+ self.uiComponent.adaptiveBannerEnabled = adaptiveBannerEnabled;
555
+ }
556
+ }
557
+
558
+ - (void)setAutoRefresh:(BOOL)autoRefresh
559
+ {
560
+ _autoRefresh = autoRefresh;
561
+
562
+ if ( self.uiComponent )
563
+ {
564
+ self.uiComponent.autoRefreshEnabled = autoRefresh;
565
+ }
566
+ }
567
+
568
+ - (void)setLoadOnMount:(BOOL)loadOnMount
569
+ {
570
+ _loadOnMount = loadOnMount;
571
+ }
572
+
573
+ - (void)setStrLocalExtraParameters:(NSArray<NSDictionary<NSString *, id> *> *)strLocalExtraParameters
574
+ {
575
+ if (!self.localExtraParameters)
576
+ {
577
+ self.localExtraParameters = [strLocalExtraParameters copy];
578
+ }
579
+ else
580
+ {
581
+ self.localExtraParameters = [self.localExtraParameters arrayByAddingObjectsFromArray: strLocalExtraParameters];
582
+ }
583
+ }
584
+
585
+ - (void)setBoolLocalExtraParameters:(NSArray<NSDictionary<NSString *, id> *> *)boolLocalExtraParameters
586
+ {
587
+ if (!self.localExtraParameters)
588
+ {
589
+ self.localExtraParameters = [boolLocalExtraParameters copy];
590
+ }
591
+ else
592
+ {
593
+ self.localExtraParameters = [self.localExtraParameters arrayByAddingObjectsFromArray: boolLocalExtraParameters];
594
+ }
595
+ }
596
+
597
+ // Invoked after all the JavaScript properties are set when mounting AdView
598
+ - (void)didSetProps:(NSArray<NSString *> *)changedProps
599
+ {
600
+ [self attachAdViewIfNeeded];
601
+ }
602
+
603
+ - (void)attachAdViewIfNeeded
604
+ {
605
+ // Re-assign in case of race condition
606
+ NSString *adUnitId = self.adUnitId;
607
+ MAAdFormat *adFormat = self.adFormat;
608
+
609
+ dispatch_async(dispatch_get_main_queue(), ^{
610
+
611
+ if ( ![AppLovinMAX shared].sdk )
612
+ {
613
+ [[AppLovinMAX shared] logUninitializedAccessError: @"AppLovinMAXAdView.attachAdViewIfNeeded"];
614
+ return;
615
+ }
616
+
617
+ if ( ![adUnitId al_isValidString] )
618
+ {
619
+ [[AppLovinMAX shared] log: @"Attempting to attach a native UI component without Ad Unit ID"];
620
+ return;
621
+ }
622
+
623
+ if ( !adFormat )
624
+ {
625
+ [[AppLovinMAX shared] log: @"Attempting to attach a native UI component without ad format"];
626
+ return;
627
+ }
628
+
629
+ if ( self.uiComponent )
630
+ {
631
+ [[AppLovinMAX shared] log: @"Attempting to re-attach with existing AdView (%@) for Ad Unit ID %@", @(self.uiComponent.hash), self.adUnitId];
632
+ return;
633
+ }
634
+
635
+ self.uiComponent = preloadedUIComponentInstances[self.adViewId];
636
+ if ( self.uiComponent )
637
+ {
638
+ // Attach the preloaded uiComponent if possible, otherwise create a new one for the same adUnitId
639
+ if ( ![self.uiComponent hasContainerView] )
640
+ {
641
+ [[AppLovinMAX shared] log: @"Mounting the preloaded AdView (%@) for Ad Unit ID %@", self.adViewId, self.adUnitId];
642
+
643
+ self.uiComponent.adaptiveBannerEnabled = [self isAdaptiveBannerEnabled];
644
+ self.uiComponent.autoRefreshEnabled = [self isAutoRefreshEnabled];
645
+ [self.uiComponent attachAdView: self];
646
+ return;
647
+ }
648
+ }
649
+
650
+ self.uiComponent = [[AppLovinMAXAdViewUIComponent alloc] initWithAdUnitIdentifier: adUnitId adFormat: adFormat];
651
+ self.adViewId = @(self.uiComponent.hash);
652
+ uiComponentInstances[self.adViewId] = self.uiComponent;
653
+
654
+ [[AppLovinMAX shared] log: @"Mounting a new AdView (%@) for Ad Unit ID %@", self.adViewId, self.adUnitId];
655
+
656
+ NSMutableDictionary<NSString *, id> *flattenedExtraParameters;
657
+ if ( self.extraParameters )
658
+ {
659
+ flattenedExtraParameters = [NSMutableDictionary dictionary];
660
+ for ( NSDictionary *parameter in self.extraParameters )
661
+ {
662
+ flattenedExtraParameters[parameter[@"key"]] = parameter[@"value"];
663
+ }
664
+ }
665
+
666
+ NSMutableDictionary<NSString *, id> *flattenedLocalExtraParameters;
667
+ if ( self.localExtraParameters )
668
+ {
669
+ flattenedLocalExtraParameters = [NSMutableDictionary dictionary];
670
+ for ( NSDictionary *parameter in self.localExtraParameters )
671
+ {
672
+ flattenedLocalExtraParameters[parameter[@"key"]] = parameter[@"value"];
673
+ }
674
+ }
675
+
676
+ self.uiComponent.placement = self.placement;
677
+ self.uiComponent.customData = self.customData;
678
+ self.uiComponent.extraParameters = flattenedExtraParameters;
679
+ self.uiComponent.localExtraParameters = flattenedLocalExtraParameters;
680
+ self.uiComponent.adaptiveBannerEnabled = [self isAdaptiveBannerEnabled];
681
+ self.uiComponent.autoRefreshEnabled = [self isAutoRefreshEnabled];
682
+
683
+ [self.uiComponent attachAdView: self];
684
+
685
+ if ( [self isLoadOnMount] )
686
+ {
687
+ [self.uiComponent loadAd];
688
+ }
689
+ });
690
+ }
691
+
692
+ - (void)loadAd
693
+ {
694
+ if ( !self.uiComponent )
695
+ {
696
+ [[AppLovinMAX shared] log: @"Attempting to load uninitialized native UI component for %@", self.adUnitId];
697
+ return;
698
+ }
699
+
700
+ [self.uiComponent loadAd];
701
+ }
702
+
703
+ - (void)destroyCurrentAdIfNeeded
704
+ {
705
+ if ( !self.uiComponent ) return;
706
+
707
+ [self.uiComponent detachAdView];
708
+
709
+ AppLovinMAXAdViewUIComponent *preloadedUIComponent = preloadedUIComponentInstances[self.adViewId];
710
+
711
+ if ( self.uiComponent == preloadedUIComponent )
712
+ {
713
+ [[AppLovinMAX shared] log: @"Unmounting the preloaded AdView (%@) for Ad Unit ID %@", self.adViewId, self.adUnitId];
714
+
715
+ self.uiComponent.autoRefreshEnabled = NO;
716
+ }
717
+ else
718
+ {
719
+ [[AppLovinMAX shared] log: @"Unmounting the AdView (%@) to destroy for Ad Unit ID %@", self.adViewId, self.adUnitId];
720
+
721
+ [uiComponentInstances removeObjectForKey: self.adViewId];
722
+ [self.uiComponent destroy];
723
+ }
724
+
725
+ self.uiComponent = nil;
726
+ }
727
+
728
+ - (void)didMoveToWindow
729
+ {
730
+ [super didMoveToWindow];
731
+
732
+ // This view is unmounted
733
+ if ( !self.window )
734
+ {
735
+ [self destroyCurrentAdIfNeeded];
736
+ }
737
+ }
738
+
739
+ @end
740
+
741
+ #ifdef RCT_NEW_ARCH_ENABLED
742
+ Class<RCTComponentViewProtocol> AppLovinMAXAdViewCls(void)
743
+ {
744
+ return [AppLovinMAXAdView class];
745
+ }
746
+ #endif
747
+