react-native-applovin-max 6.2.2 → 6.2.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.
@@ -35,8 +35,8 @@ android {
35
35
  defaultConfig {
36
36
  minSdkVersion 16
37
37
  targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
38
- versionCode 6020200
39
- versionName "6.2.2"
38
+ versionCode 6020300
39
+ versionName "6.2.3"
40
40
  }
41
41
 
42
42
  flavorDimensions("default")
@@ -43,6 +43,7 @@ class AppLovinMAXAdView
43
43
  private String customData;
44
44
  private boolean adaptiveBannerEnabled;
45
45
  private boolean autoRefresh;
46
+ private boolean loadOnMount;
46
47
  @Nullable
47
48
  private Map<String, Object> extraParameters;
48
49
  @Nullable
@@ -146,6 +147,11 @@ class AppLovinMAXAdView
146
147
  }
147
148
  }
148
149
 
150
+ public void setLoadOnMount(final boolean enabled)
151
+ {
152
+ loadOnMount = enabled;
153
+ }
154
+
149
155
  public void setExtraParameters(@Nullable final ReadableMap readableMap)
150
156
  {
151
157
  if ( readableMap != null )
@@ -273,7 +279,10 @@ class AppLovinMAXAdView
273
279
  adView.stopAutoRefresh();
274
280
  }
275
281
 
276
- adView.loadAd();
282
+ if ( loadOnMount )
283
+ {
284
+ adView.loadAd();
285
+ }
277
286
 
278
287
  addView( adView );
279
288
 
@@ -281,6 +290,17 @@ class AppLovinMAXAdView
281
290
  }, 250 );
282
291
  }
283
292
 
293
+ public void loadAd()
294
+ {
295
+ if ( adView == null )
296
+ {
297
+ AppLovinMAXModule.e( "Attempting to load uninitialized MaxAdView for " + adUnitId );
298
+ return;
299
+ }
300
+
301
+ adView.loadAd();
302
+ }
303
+
284
304
  public void destroy()
285
305
  {
286
306
  if ( adView != null )
@@ -1,6 +1,7 @@
1
1
  package com.applovin.reactnative;
2
2
 
3
3
  import com.facebook.react.bridge.ReactApplicationContext;
4
+ import com.facebook.react.bridge.ReadableArray;
4
5
  import com.facebook.react.bridge.ReadableMap;
5
6
  import com.facebook.react.common.MapBuilder;
6
7
  import com.facebook.react.uimanager.SimpleViewManager;
@@ -9,6 +10,7 @@ import com.facebook.react.uimanager.annotations.ReactProp;
9
10
 
10
11
  import java.util.Map;
11
12
 
13
+ import androidx.annotation.NonNull;
12
14
  import androidx.annotation.Nullable;
13
15
 
14
16
  /**
@@ -17,6 +19,8 @@ import androidx.annotation.Nullable;
17
19
  class AppLovinMAXAdViewManager
18
20
  extends SimpleViewManager<AppLovinMAXAdView>
19
21
  {
22
+ private static final int COMMAND_LOAD_AD = 1;
23
+
20
24
  public AppLovinMAXAdViewManager(final ReactApplicationContext reactApplicationContext) { }
21
25
 
22
26
  @Override
@@ -41,6 +45,26 @@ class AppLovinMAXAdViewManager
41
45
  .build();
42
46
  }
43
47
 
48
+ @Nullable
49
+ @Override
50
+ public Map<String, Integer> getCommandsMap()
51
+ {
52
+ return MapBuilder.of(
53
+ "loadAd", COMMAND_LOAD_AD
54
+ );
55
+ }
56
+
57
+ @Override
58
+ public void receiveCommand(@NonNull final AppLovinMAXAdView view, final int commandId, @Nullable final ReadableArray args)
59
+ {
60
+ switch ( commandId )
61
+ {
62
+ case COMMAND_LOAD_AD:
63
+ view.loadAd();
64
+ break;
65
+ }
66
+ }
67
+
44
68
  @Override
45
69
  protected AppLovinMAXAdView createViewInstance(final ThemedReactContext reactContext)
46
70
  {
@@ -84,6 +108,12 @@ class AppLovinMAXAdViewManager
84
108
  view.setAutoRefresh( enabled );
85
109
  }
86
110
 
111
+ @ReactProp(name = "loadOnMount")
112
+ public void setLoadOnMount(final AppLovinMAXAdView view, final boolean enabled)
113
+ {
114
+ view.setLoadOnMount( enabled );
115
+ }
116
+
87
117
  @ReactProp(name = "extraParameters")
88
118
  public void setExtraParameters(final AppLovinMAXAdView view, @Nullable final ReadableMap value)
89
119
  {
@@ -2747,6 +2747,11 @@ public class AppLovinMAXModule
2747
2747
  setAmazonResult( result, adUnitId, MaxAdFormat.INTERSTITIAL );
2748
2748
  }
2749
2749
 
2750
+ public void setAmazonRewardedResult(final Object result, final String adUnitId)
2751
+ {
2752
+ setAmazonResult( result, adUnitId, MaxAdFormat.REWARDED );
2753
+ }
2754
+
2750
2755
  private void setAmazonResult(final Object result, final String adUnitId, final MaxAdFormat adFormat)
2751
2756
  {
2752
2757
  if ( sdk == null )
package/ios/AppLovinMAX.m CHANGED
@@ -2292,6 +2292,11 @@ RCT_EXPORT_METHOD(setAppOpenAdLocalExtraParameter:(NSString *)adUnitIdentifier :
2292
2292
  [self setAmazonResult: result forAdUnitIdentifier: adUnitIdentifier adFormat: MAAdFormat.interstitial];
2293
2293
  }
2294
2294
 
2295
+ - (void)setAmazonResult:(id)result forRewardedAdUnitIdentifier:(NSString *)adUnitIdentifier
2296
+ {
2297
+ [self setAmazonResult: result forAdUnitIdentifier: adUnitIdentifier adFormat: MAAdFormat.rewarded];
2298
+ }
2299
+
2295
2300
  - (void)setAmazonResult:(id /* DTBAdResponse or DTBAdErrorInfo */)result forAdUnitIdentifier:(NSString *)adUnitIdentifier adFormat:(MAAdFormat *)adFormat
2296
2301
  {
2297
2302
  if ( !self.sdk )
@@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
15
15
 
16
16
  + (MAAdView *)sharedWithAdUnitIdentifier:(NSString *)adUnitIdentifier;
17
17
 
18
+ - (void)loadAd;
19
+
18
20
  @end
19
21
 
20
22
  NS_ASSUME_NONNULL_END
@@ -20,6 +20,7 @@
20
20
  @property (nonatomic, copy, nullable) NSString *customData;
21
21
  @property (nonatomic, assign, readonly, getter=isAdaptiveBannerEnabled) BOOL adaptiveBannerEnabled;
22
22
  @property (nonatomic, assign, readonly, getter=isAutoRefresh) BOOL autoRefresh;
23
+ @property (nonatomic, assign, readonly, getter=isLoadOnMount) BOOL loadOnMount;
23
24
  @property (nonatomic, copy, nullable) NSDictionary *extraParameters;
24
25
  @property (nonatomic, copy, nullable) NSDictionary *localExtraParameters;
25
26
 
@@ -135,6 +136,11 @@ static NSMutableDictionary<NSString *, MAAdView *> *adViewInstances;
135
136
  }
136
137
  }
137
138
 
139
+ - (void)setLoadOnMount:(BOOL)loadOnMount
140
+ {
141
+ _loadOnMount = loadOnMount;
142
+ }
143
+
138
144
  - (void)attachAdViewIfNeeded
139
145
  {
140
146
  // Re-assign in case of race condition
@@ -202,7 +208,10 @@ static NSMutableDictionary<NSString *, MAAdView *> *adViewInstances;
202
208
  [self.adView stopAutoRefresh];
203
209
  }
204
210
 
205
- [self.adView loadAd];
211
+ if ( [self isLoadOnMount] )
212
+ {
213
+ [self.adView loadAd];
214
+ }
206
215
 
207
216
  [self addSubview: self.adView];
208
217
 
@@ -215,6 +224,17 @@ static NSMutableDictionary<NSString *, MAAdView *> *adViewInstances;
215
224
  });
216
225
  }
217
226
 
227
+ - (void)loadAd
228
+ {
229
+ if ( !self.adView )
230
+ {
231
+ [[AppLovinMAX shared] log: @"Attempting to load uninitialized MAAdView for %@", self.adUnitId];
232
+ return;
233
+ }
234
+
235
+ [self.adView loadAd];
236
+ }
237
+
218
238
  - (void)didMoveToWindow
219
239
  {
220
240
  [super didMoveToWindow];
@@ -6,6 +6,7 @@
6
6
  // Copyright © 2020 AppLovin. All rights reserved.
7
7
  //
8
8
 
9
+ #import "AppLovinMAX.h"
9
10
  #import "AppLovinMAXAdViewManager.h"
10
11
  #import "AppLovinMAXAdview.h"
11
12
 
@@ -19,6 +20,7 @@ RCT_EXPORT_VIEW_PROPERTY(placement, NSString)
19
20
  RCT_EXPORT_VIEW_PROPERTY(customData, NSString)
20
21
  RCT_EXPORT_VIEW_PROPERTY(adaptiveBannerEnabled, BOOL)
21
22
  RCT_EXPORT_VIEW_PROPERTY(autoRefresh, BOOL)
23
+ RCT_EXPORT_VIEW_PROPERTY(loadOnMount, BOOL)
22
24
  RCT_EXPORT_VIEW_PROPERTY(extraParameters, NSDictionary)
23
25
  RCT_EXPORT_VIEW_PROPERTY(localExtraParameters, NSDictionary)
24
26
 
@@ -40,4 +42,20 @@ RCT_EXPORT_VIEW_PROPERTY(onAdRevenuePaidEvent, RCTDirectEventBlock)
40
42
  return [[AppLovinMAXAdView alloc] init];
41
43
  }
42
44
 
45
+ RCT_EXPORT_METHOD(loadAd:(nonnull NSNumber *)viewTag)
46
+ {
47
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
48
+
49
+ UIView *view = viewRegistry[viewTag];
50
+ if ( ![view isKindOfClass: [AppLovinMAXAdView class]] )
51
+ {
52
+ [[AppLovinMAX shared] log: @"Cannot find AppLovinMAXAdView with tag %@", viewTag];
53
+ return;
54
+ }
55
+
56
+ AppLovinMAXAdView *adView = (AppLovinMAXAdView *) view;
57
+ [adView loadAd];
58
+ }];
59
+ }
60
+
43
61
  @end
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-applovin-max",
3
3
  "author": "AppLovin Corporation",
4
- "version": "6.2.2",
4
+ "version": "6.2.3",
5
5
  "description": "AppLovin MAX React Native Plugin for Android and iOS",
6
6
  "homepage": "https://github.com/AppLovin/AppLovin-MAX-React-Native",
7
7
  "license": "MIT",
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.authors = package["author"]
12
12
 
13
13
  s.platforms = { :ios => "10.0" }
14
- s.source = { :git => "https://github.com/AppLovin/AppLovin-MAX-React-Native.git", :tag => "release_6_2_2" }
14
+ s.source = { :git => "https://github.com/AppLovin/AppLovin-MAX-React-Native.git", :tag => "release_6_2_3" }
15
15
 
16
16
  s.source_files = "ios/AppLovinMAX*.{h,m}"
17
17
 
package/src/AdView.tsx CHANGED
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
- import { useEffect, useState } from 'react';
3
- import { NativeModules, requireNativeComponent, StyleSheet } from 'react-native';
4
- import type { ViewProps, ViewStyle, StyleProp } from 'react-native';
2
+ import { useEffect, useState, useRef, useCallback, useImperativeHandle, forwardRef } from 'react';
3
+ import { NativeModules, requireNativeComponent, StyleSheet, UIManager, findNodeHandle } from 'react-native';
4
+ import type { ViewProps, ViewStyle, StyleProp, NativeMethods } from 'react-native';
5
5
  import type { AdDisplayFailedInfo, AdInfo, AdLoadFailedInfo, AdRevenueInfo } from './types/AdInfo';
6
6
  import type { AdNativeEvent } from './types/AdEvent';
7
- import type { AdViewProps } from './types/AdViewProps';
7
+ import type { AdViewProps, AdViewHandler } from './types/AdViewProps';
8
8
 
9
9
  const { AppLovinMAX } = NativeModules;
10
10
 
@@ -65,6 +65,8 @@ type AdViewNativeEvents = {
65
65
 
66
66
  const AdViewComponent = requireNativeComponent<AdViewProps & ViewProps & AdViewNativeEvents>('AppLovinMAXAdView');
67
67
 
68
+ type AdViewType = React.Component<AdViewProps> & NativeMethods;
69
+
68
70
  const ADVIEW_SIZE = {
69
71
  banner: { width: 320, height: 50 },
70
72
  leader: { width: 728, height: 90 },
@@ -161,28 +163,51 @@ const sizeAdViewDimensions = (
161
163
  * />
162
164
  * ```
163
165
  */
164
- export const AdView = ({
165
- adUnitId,
166
- adFormat,
167
- placement,
168
- customData,
169
- adaptiveBannerEnabled = true,
170
- autoRefresh = true,
171
- extraParameters,
172
- localExtraParameters,
173
- onAdLoaded,
174
- onAdLoadFailed,
175
- onAdDisplayFailed,
176
- onAdClicked,
177
- onAdExpanded,
178
- onAdCollapsed,
179
- onAdRevenuePaid,
180
- style,
181
- ...otherProps
182
- }: AdViewProps & ViewProps) => {
166
+ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(function AdView(
167
+ {
168
+ adUnitId,
169
+ adFormat,
170
+ placement,
171
+ customData,
172
+ adaptiveBannerEnabled = true,
173
+ autoRefresh = true,
174
+ loadOnMount = true,
175
+ extraParameters,
176
+ localExtraParameters,
177
+ onAdLoaded,
178
+ onAdLoadFailed,
179
+ onAdDisplayFailed,
180
+ onAdClicked,
181
+ onAdExpanded,
182
+ onAdCollapsed,
183
+ onAdRevenuePaid,
184
+ style,
185
+ ...otherProps
186
+ },
187
+ ref
188
+ ) {
189
+ const adViewRef = useRef<AdViewType | null>(null);
183
190
  const [isInitialized, setIsInitialized] = useState<boolean>(false);
184
191
  const [dimensions, setDimensions] = useState({});
185
192
 
193
+ const loadAd = () => {
194
+ if (adViewRef.current) {
195
+ UIManager.dispatchViewManagerCommand(
196
+ findNodeHandle(adViewRef.current),
197
+ UIManager.getViewManagerConfig('AppLovinMAXAdView').Commands.loadAd,
198
+ undefined
199
+ );
200
+ }
201
+ };
202
+
203
+ useImperativeHandle(ref, () => ({ loadAd }), []);
204
+
205
+ const saveElement = useCallback((element: AdViewType | null) => {
206
+ if (element) {
207
+ adViewRef.current = element;
208
+ }
209
+ }, []);
210
+
186
211
  useEffect(() => {
187
212
  AppLovinMAX.isInitialized().then((result: boolean) => {
188
213
  setIsInitialized(result);
@@ -244,12 +269,14 @@ export const AdView = ({
244
269
 
245
270
  return (
246
271
  <AdViewComponent
272
+ ref={saveElement}
247
273
  adUnitId={adUnitId}
248
274
  adFormat={adFormat}
249
275
  placement={placement}
250
276
  customData={customData}
251
277
  adaptiveBannerEnabled={adaptiveBannerEnabled}
252
278
  autoRefresh={autoRefresh}
279
+ loadOnMount={loadOnMount}
253
280
  extraParameters={extraParameters}
254
281
  localExtraParameters={localExtraParameters}
255
282
  onAdLoadedEvent={onAdLoadedEvent}
@@ -263,4 +290,4 @@ export const AdView = ({
263
290
  {...otherProps}
264
291
  />
265
292
  );
266
- };
293
+ });
@@ -4,7 +4,7 @@ import type { Configuration } from './types/Configuration';
4
4
 
5
5
  const NativeAppLovinMAX = NativeModules.AppLovinMAX;
6
6
 
7
- const VERSION = '6.2.2';
7
+ const VERSION = '6.2.3';
8
8
 
9
9
  /**
10
10
  * This enum represents the user's geography used to determine the type of consent flow shown to the
@@ -2,6 +2,16 @@ import type { AdProps } from './AdProps';
2
2
  import type { AdInfo } from './AdInfo';
3
3
  import type { AdFormat } from '../AdView';
4
4
 
5
+ /**
6
+ * A handler of {@link AdView}.
7
+ */
8
+ export type AdViewHandler = {
9
+ /**
10
+ * If the {@link loadOnMount} attribute is set to false, you can call this API to start loading ads in this AdView.
11
+ */
12
+ loadAd(): void;
13
+ };
14
+
5
15
  /**
6
16
  * Represents an {@link AdView} - Banner / MREC.
7
17
  */
@@ -23,6 +33,12 @@ export type AdViewProps = AdProps & {
23
33
  */
24
34
  autoRefresh?: boolean;
25
35
 
36
+ /**
37
+ * A boolean value representing whether or not to load an ad as soon as {@link AdView} is
38
+ * mounted. Note that the default value is true.
39
+ */
40
+ loadOnMount?: boolean;
41
+
26
42
  /**
27
43
  * A callback fuction that {@link AdView} fires when it expands the ad.
28
44
  */