react-native-applovin-max 8.2.0 → 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.
- package/android/build.gradle +13 -2
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdView.java +33 -26
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewManagerImpl.java +110 -0
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewUiComponent.java +15 -13
- package/android/src/main/java/com/applovin/reactnative/{AppLovinMAXModule.java → AppLovinMAXModuleImpl.java} +107 -168
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdView.java +84 -56
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManagerImpl.java +101 -0
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXPackage.java +44 -11
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXUtils.java +56 -0
- package/android/src/newarch/com/applovin/reactnative/AppLovinMAXAdViewManager.java +151 -0
- package/android/src/newarch/com/applovin/reactnative/AppLovinMAXModule.java +453 -0
- package/android/src/newarch/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +130 -0
- package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXAdViewManager.java +128 -0
- package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXModule.java +453 -0
- package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +93 -0
- package/ios/AppLovinMAX.h +8 -3
- package/ios/{AppLovinMAX.m → AppLovinMAX.mm} +66 -53
- package/ios/AppLovinMAXAdView.h +7 -2
- package/ios/AppLovinMAXAdView.mm +747 -0
- package/ios/{AppLovinMAXAdViewManager.m → AppLovinMAXAdViewManager.mm} +3 -2
- package/ios/{AppLovinMAXAdViewUIComponent.m → AppLovinMAXAdViewUIComponent.mm} +2 -1
- package/ios/AppLovinMAXNativeAdView.h +15 -4
- package/ios/AppLovinMAXNativeAdView.mm +745 -0
- package/ios/AppLovinMAXNativeAdViewManager.mm +116 -0
- package/lib/commonjs/AdView.js +61 -85
- package/lib/commonjs/AdView.js.map +1 -1
- package/lib/commonjs/AppLovinMAX.js +11 -10
- package/lib/commonjs/AppLovinMAX.js.map +1 -1
- package/lib/commonjs/AppOpenAd.js +8 -10
- package/lib/commonjs/AppOpenAd.js.map +1 -1
- package/lib/commonjs/BannerAd.js +19 -21
- package/lib/commonjs/BannerAd.js.map +1 -1
- package/lib/commonjs/ErrorCode.js +3 -5
- package/lib/commonjs/ErrorCode.js.map +1 -1
- package/lib/commonjs/EventEmitter.js +3 -5
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/InterstitialAd.js +8 -10
- package/lib/commonjs/InterstitialAd.js.map +1 -1
- package/lib/commonjs/MRecAd.js +14 -16
- package/lib/commonjs/MRecAd.js.map +1 -1
- package/lib/commonjs/Privacy.js +3 -5
- package/lib/commonjs/Privacy.js.map +1 -1
- package/lib/commonjs/RewardedAd.js +8 -10
- package/lib/commonjs/RewardedAd.js.map +1 -1
- package/lib/commonjs/Utils.js +25 -0
- package/lib/commonjs/Utils.js.map +1 -0
- package/lib/commonjs/nativeAd/NativeAdView.js +65 -42
- package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdViewComponents.js +51 -47
- package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdViewProvider.js +38 -8
- package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
- package/lib/commonjs/nativeAd/img/blank_icon.png +0 -0
- package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js +14 -0
- package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js +14 -0
- package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/NativeAppLovinMAXModule.js +9 -0
- package/lib/commonjs/specs/NativeAppLovinMAXModule.js.map +1 -0
- package/lib/module/AdView.js +56 -81
- package/lib/module/AdView.js.map +1 -1
- package/lib/module/AppLovinMAX.js +7 -7
- package/lib/module/AppLovinMAX.js.map +1 -1
- package/lib/module/AppOpenAd.js +1 -4
- package/lib/module/AppOpenAd.js.map +1 -1
- package/lib/module/BannerAd.js +1 -4
- package/lib/module/BannerAd.js.map +1 -1
- package/lib/module/ErrorCode.js +1 -4
- package/lib/module/ErrorCode.js.map +1 -1
- package/lib/module/EventEmitter.js +2 -4
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/InterstitialAd.js +2 -5
- package/lib/module/InterstitialAd.js.map +1 -1
- package/lib/module/MRecAd.js +1 -4
- package/lib/module/MRecAd.js.map +1 -1
- package/lib/module/Privacy.js +1 -4
- package/lib/module/Privacy.js.map +1 -1
- package/lib/module/RewardedAd.js +2 -5
- package/lib/module/RewardedAd.js.map +1 -1
- package/lib/module/Utils.js +17 -0
- package/lib/module/Utils.js.map +1 -0
- package/lib/module/nativeAd/NativeAdView.js +63 -40
- package/lib/module/nativeAd/NativeAdView.js.map +1 -1
- package/lib/module/nativeAd/NativeAdViewComponents.js +53 -49
- package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
- package/lib/module/nativeAd/NativeAdViewProvider.js +39 -9
- package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
- package/lib/module/nativeAd/img/blank_icon.png +0 -0
- package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js +7 -0
- package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -0
- package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js +7 -0
- package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -0
- package/lib/module/specs/NativeAppLovinMAXModule.js +3 -0
- package/lib/module/specs/NativeAppLovinMAXModule.js.map +1 -0
- package/lib/typescript/src/AdView.d.ts +11 -11
- package/lib/typescript/src/AdView.d.ts.map +1 -1
- package/lib/typescript/src/AppLovinMAX.d.ts.map +1 -1
- package/lib/typescript/src/AppOpenAd.d.ts.map +1 -1
- package/lib/typescript/src/BannerAd.d.ts.map +1 -1
- package/lib/typescript/src/ErrorCode.d.ts.map +1 -1
- package/lib/typescript/src/EventEmitter.d.ts.map +1 -1
- package/lib/typescript/src/InterstitialAd.d.ts.map +1 -1
- package/lib/typescript/src/MRecAd.d.ts.map +1 -1
- package/lib/typescript/src/Privacy.d.ts.map +1 -1
- package/lib/typescript/src/RewardedAd.d.ts.map +1 -1
- package/lib/typescript/src/Utils.d.ts +16 -0
- package/lib/typescript/src/Utils.d.ts.map +1 -0
- package/lib/typescript/src/nativeAd/NativeAdView.d.ts.map +1 -1
- package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
- package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts +14 -5
- package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
- package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts +86 -0
- package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts +80 -0
- package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts +132 -0
- package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts.map +1 -0
- package/lib/typescript/src/types/AdInfo.d.ts +1 -1
- package/lib/typescript/src/types/AdInfo.d.ts.map +1 -1
- package/lib/typescript/src/types/AdProps.d.ts +2 -2
- package/lib/typescript/src/types/AdProps.d.ts.map +1 -1
- package/lib/typescript/src/types/NativeAd.d.ts +4 -0
- package/lib/typescript/src/types/NativeAd.d.ts.map +1 -1
- package/package.json +9 -1
- package/react-native-applovin-max.podspec +2 -2
- package/src/AdView.tsx +56 -121
- package/src/AppLovinMAX.ts +7 -8
- package/src/AppOpenAd.ts +1 -3
- package/src/BannerAd.ts +1 -3
- package/src/ErrorCode.ts +1 -3
- package/src/EventEmitter.ts +2 -3
- package/src/InterstitialAd.ts +2 -4
- package/src/MRecAd.ts +1 -3
- package/src/Privacy.ts +1 -3
- package/src/RewardedAd.ts +2 -4
- package/src/Utils.ts +26 -0
- package/src/nativeAd/NativeAdView.tsx +65 -65
- package/src/nativeAd/NativeAdViewComponents.tsx +32 -60
- package/src/nativeAd/NativeAdViewProvider.tsx +37 -12
- package/src/nativeAd/img/blank_icon.png +0 -0
- package/src/specs/AppLovinMAXAdViewNativeComponent.ts +96 -0
- package/src/specs/AppLovinMAXNativeAdViewNativeComponent.ts +89 -0
- package/src/specs/NativeAppLovinMAXModule.ts +208 -0
- package/src/types/AdInfo.ts +1 -1
- package/src/types/AdProps.ts +2 -2
- package/src/types/NativeAd.ts +5 -0
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewManager.java +0 -149
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +0 -163
- package/ios/AppLovinMAXAdView.m +0 -325
- package/ios/AppLovinMAXNativeAdView.m +0 -432
- 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 ¶meter: 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 ¶meter: 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 ¶meter: 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
|
+
|