react-native-applovin-max 4.1.7 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ import android.view.ViewGroup;
7
7
  import android.widget.ImageView;
8
8
 
9
9
  import com.applovin.mediation.MaxAd;
10
+ import com.applovin.mediation.MaxAdRevenueListener;
10
11
  import com.applovin.mediation.MaxError;
11
12
  import com.applovin.mediation.nativeAds.MaxNativeAd;
12
13
  import com.applovin.mediation.nativeAds.MaxNativeAd.MaxNativeAdImage;
@@ -31,7 +32,7 @@ import static com.applovin.sdk.AppLovinSdkUtils.runOnUiThreadDelayed;
31
32
 
32
33
  public class AppLovinMAXNativeAdView
33
34
  extends ReactViewGroup
34
- implements View.OnLayoutChangeListener
35
+ implements MaxAdRevenueListener, View.OnLayoutChangeListener
35
36
  {
36
37
  private final ReactContext reactContext;
37
38
  @Nullable
@@ -53,6 +54,8 @@ public class AppLovinMAXNativeAdView
53
54
  private String customData;
54
55
  @Nullable
55
56
  private Map<String, Object> extraParameters;
57
+ @Nullable
58
+ private Map<String, Object> localExtraParameters;
56
59
 
57
60
  // TODO: Allow publisher to select which views are clickable and which isn't via prop
58
61
  private final List<View> clickableViews = new ArrayList<>();
@@ -102,8 +105,22 @@ public class AppLovinMAXNativeAdView
102
105
  }
103
106
  }
104
107
 
108
+ public void setLocalExtraParameters(@Nullable final ReadableMap readableMap)
109
+ {
110
+ if ( readableMap != null )
111
+ {
112
+ localExtraParameters = readableMap.toHashMap();
113
+ }
114
+ }
115
+
105
116
  public void loadAd()
106
117
  {
118
+ if ( AppLovinMAXModule.getInstance().getSdk() == null )
119
+ {
120
+ AppLovinMAXModule.logUninitializedAccessError( "AppLovinMAXNativeAdView.loadAd" );
121
+ return;
122
+ }
123
+
107
124
  if ( isLoading.compareAndSet( false, true ) )
108
125
  {
109
126
  AppLovinMAXModule.d( "Loading a native ad for Ad Unit ID: " + adUnitId + "..." );
@@ -111,7 +128,7 @@ public class AppLovinMAXNativeAdView
111
128
  if ( adLoader == null || !adUnitId.equals( adLoader.getAdUnitId() ) )
112
129
  {
113
130
  adLoader = new MaxNativeAdLoader( adUnitId, AppLovinMAXModule.getInstance().getSdk(), reactContext );
114
- adLoader.setRevenueListener( AppLovinMAXModule.getInstance() );
131
+ adLoader.setRevenueListener( this );
115
132
  adLoader.setNativeAdListener( new NativeAdListener() );
116
133
  }
117
134
 
@@ -126,6 +143,14 @@ public class AppLovinMAXNativeAdView
126
143
  }
127
144
  }
128
145
 
146
+ if ( localExtraParameters != null )
147
+ {
148
+ for ( Map.Entry<String, Object> entry : localExtraParameters.entrySet() )
149
+ {
150
+ adLoader.setLocalExtraParameter( entry.getKey(), (String) entry.getValue() );
151
+ }
152
+ }
153
+
129
154
  adLoader.loadAd();
130
155
  }
131
156
  else
@@ -200,24 +225,27 @@ public class AppLovinMAXNativeAdView
200
225
  clickableViews.add( view );
201
226
  }
202
227
 
203
- public void setMediaView(final int tag)
228
+ public void setIconView(final int tag)
204
229
  {
205
- mediaView = nativeAd.getNativeAd().getMediaView();
206
- if ( mediaView == null ) return;
207
-
208
- ViewGroup view = findViewById( tag );
230
+ ImageView view = findViewById( tag );
209
231
  if ( view == null )
210
232
  {
211
- AppLovinMAXModule.e( "Cannot find a media view with tag \"" + tag + "\" for " + adUnitId );
233
+ AppLovinMAXModule.e( "Cannot find an icon image with tag \"" + tag + "\" for " + adUnitId );
212
234
  return;
213
235
  }
214
236
 
237
+ view.setClickable( true );
215
238
  clickableViews.add( view );
216
239
 
217
- view.addOnLayoutChangeListener( this );
218
- view.addView( mediaView );
219
-
220
- sizeToFit( mediaView, view );
240
+ MaxNativeAdImage icon = nativeAd.getNativeAd().getIcon();
241
+ if ( icon != null )
242
+ {
243
+ // Check if "URL" was missing and therefore need to set the image data
244
+ if ( icon.getUri() == null && icon.getDrawable() != null )
245
+ {
246
+ view.setImageDrawable( icon.getDrawable() );
247
+ }
248
+ }
221
249
  }
222
250
 
223
251
  public void setOptionsView(final int tag)
@@ -238,34 +266,37 @@ public class AppLovinMAXNativeAdView
238
266
  sizeToFit( optionsView, view );
239
267
  }
240
268
 
241
- public void setIconView(final int tag)
269
+ public void setMediaView(final int tag)
242
270
  {
243
- ImageView view = findViewById( tag );
271
+ mediaView = nativeAd.getNativeAd().getMediaView();
272
+ if ( mediaView == null ) return;
273
+
274
+ ViewGroup view = findViewById( tag );
244
275
  if ( view == null )
245
276
  {
246
- AppLovinMAXModule.e( "Cannot find an icon image with tag \"" + tag + "\" for " + adUnitId );
277
+ AppLovinMAXModule.e( "Cannot find a media view with tag \"" + tag + "\" for " + adUnitId );
247
278
  return;
248
279
  }
249
280
 
250
- view.setClickable( true );
251
281
  clickableViews.add( view );
252
282
 
253
- MaxNativeAdImage icon = nativeAd.getNativeAd().getIcon();
254
- if ( icon != null )
255
- {
256
- // Check if "URL" was missing and therefore need to set the image data
257
- if ( icon.getUri() == null && icon.getDrawable() != null )
258
- {
259
- view.setImageDrawable( icon.getDrawable() );
260
- }
261
- }
283
+ view.addOnLayoutChangeListener( this );
284
+ view.addView( mediaView );
285
+
286
+ sizeToFit( mediaView, view );
262
287
  }
263
288
 
264
289
  @Override
265
290
  public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
266
291
  {
267
- sizeToFit( mediaView, view );
268
- sizeToFit( optionsView, view );
292
+ if ( view == mediaView.getParent() )
293
+ {
294
+ sizeToFit( mediaView, view );
295
+ }
296
+ else if ( view == optionsView.getParent() )
297
+ {
298
+ sizeToFit( optionsView, view );
299
+ }
269
300
  }
270
301
 
271
302
  private void sizeToFit(final @Nullable View view, final View parentView)
@@ -278,6 +309,15 @@ public class AppLovinMAXNativeAdView
278
309
  }
279
310
  }
280
311
 
312
+ /// Ad Revenue Callback
313
+
314
+ @Override
315
+ public void onAdRevenuePaid(final MaxAd ad)
316
+ {
317
+ WritableMap adRevenueInfo = AppLovinMAXModule.getInstance().getAdRevenueInfo( ad );
318
+ reactContext.getJSModule( RCTEventEmitter.class ).receiveEvent( getId(), "onAdRevenuePaidEvent", adRevenueInfo );
319
+ }
320
+
281
321
  /// Ad Loader Callback
282
322
 
283
323
  class NativeAdListener
@@ -294,7 +334,8 @@ public class AppLovinMAXNativeAdView
294
334
  isLoading.set( false );
295
335
 
296
336
  AppLovinMAXModule.e( "Native ad is of template type, failing ad load..." );
297
- AppLovinMAXModule.getInstance().sendReactNativeEventForAdLoadFailed( "OnNativeAdLoadFailedEvent", adUnitId, null );
337
+ WritableMap loadFailedInfo = AppLovinMAXModule.getInstance().getAdLoadFailedInfo( adUnitId, null );
338
+ reactContext.getJSModule( RCTEventEmitter.class ).receiveEvent( getId(), "onAdLoadFailedEvent", loadFailedInfo );
298
339
 
299
340
  return;
300
341
  }
@@ -308,8 +349,6 @@ public class AppLovinMAXNativeAdView
308
349
 
309
350
  // After notifying the RN layer - have slight delay to let views bind to this layer in `clickableViews` before registering
310
351
  runOnUiThreadDelayed( () -> {
311
- // Notify publisher
312
- AppLovinMAXModule.getInstance().onAdLoaded( ad );
313
352
 
314
353
  // Loader can be null when the user hides before the properties are fully set
315
354
  if ( adLoader != null )
@@ -330,18 +369,46 @@ public class AppLovinMAXNativeAdView
330
369
  AppLovinMAXModule.e( "Failed to load native ad for Ad Unit ID " + adUnitId + " with error: " + error );
331
370
 
332
371
  // Notify publisher
333
- AppLovinMAXModule.getInstance().sendReactNativeEventForAdLoadFailed( "OnNativeAdLoadFailedEvent", adUnitId, error );
372
+ WritableMap loadFailedInfo = AppLovinMAXModule.getInstance().getAdLoadFailedInfo( adUnitId, error );
373
+ reactContext.getJSModule( RCTEventEmitter.class ).receiveEvent( getId(), "onAdLoadFailedEvent", loadFailedInfo );
334
374
  }
335
375
 
336
376
  @Override
337
377
  public void onNativeAdClicked(final MaxAd ad)
338
378
  {
339
- AppLovinMAXModule.getInstance().onAdClicked( ad );
379
+ WritableMap adInfo = AppLovinMAXModule.getInstance().getAdInfo( ad );
380
+ reactContext.getJSModule( RCTEventEmitter.class ).receiveEvent( getId(), "onAdClickedEvent", adInfo );
340
381
  }
341
382
  }
342
383
 
343
384
  private void sendAdLoadedReactNativeEventForAd(final MaxNativeAd ad)
344
385
  {
386
+ // 1. AdInfo for publisher to be notified via `onAdLoaded`
387
+
388
+ WritableMap nativeAdInfo = Arguments.createMap();
389
+ float aspectRatio = ad.getMediaContentAspectRatio();
390
+ if ( !Float.isNaN( aspectRatio ) )
391
+ {
392
+ // The aspect ratio can be 0.0f when it is not provided by the network.
393
+ if ( Math.signum( aspectRatio ) == 0 )
394
+ {
395
+ nativeAdInfo.putDouble( "mediaContentAspectRatio", 1.0 );
396
+ }
397
+ else
398
+ {
399
+ nativeAdInfo.putDouble( "mediaContentAspectRatio", aspectRatio );
400
+ }
401
+ }
402
+ else
403
+ {
404
+ nativeAdInfo.putDouble( "mediaContentAspectRatio", 1.0 );
405
+ }
406
+
407
+ WritableMap adInfo = AppLovinMAXModule.getInstance().getAdInfo( nativeAd );
408
+ adInfo.putMap( "nativeAd", nativeAdInfo );
409
+
410
+ // 2. NativeAd for `AppLovinNativeAdView.js` to render the views
411
+
345
412
  WritableMap jsNativeAd = Arguments.createMap();
346
413
 
347
414
  jsNativeAd.putString( "title", ad.getTitle() );
@@ -371,14 +438,15 @@ public class AppLovinMAXNativeAdView
371
438
  }
372
439
  }
373
440
 
374
- float aspectRatio = ad.getMediaContentAspectRatio();
375
- if ( !Float.isNaN( aspectRatio ) )
376
- {
377
- jsNativeAd.putDouble( "mediaContentAspectRatio", aspectRatio );
378
- }
441
+ jsNativeAd.putBoolean( "isOptionsViewAvailable", ( ad.getOptionsView() != null ) );
442
+ jsNativeAd.putBoolean( "isMediaViewAvailable", ( ad.getMediaView() != null ) );
443
+
444
+ WritableMap arg = Arguments.createMap();
445
+ arg.putMap( "adInfo", adInfo );
446
+ arg.putMap( "nativeAd", jsNativeAd );
379
447
 
380
- // Send to `AppLovinNativeAdView.js` to render the views
381
- reactContext.getJSModule( RCTEventEmitter.class ).receiveEvent( getId(), "onAdLoaded", jsNativeAd );
448
+ // Send to `AppLovinNativeAdView.js`
449
+ reactContext.getJSModule( RCTEventEmitter.class ).receiveEvent( getId(), "onAdLoadedEvent", arg );
382
450
  }
383
451
 
384
452
  private void maybeDestroyCurrentAd()
@@ -42,8 +42,12 @@ public class AppLovinMAXNativeAdViewManager
42
42
  @Override
43
43
  public Map<String, Object> getExportedCustomDirectEventTypeConstants()
44
44
  {
45
+ // mapping Android events to JavaScript events
45
46
  return MapBuilder.<String, Object>builder()
46
- .put( "onAdLoaded", MapBuilder.of( "registrationName", "onAdLoaded" ) )
47
+ .put( "onAdLoadedEvent", MapBuilder.of( "registrationName", "onAdLoadedEvent" ) )
48
+ .put( "onAdLoadFailedEvent", MapBuilder.of( "registrationName", "onAdLoadFailedEvent" ) )
49
+ .put( "onAdClickedEvent", MapBuilder.of( "registrationName", "onAdClickedEvent" ) )
50
+ .put( "onAdRevenuePaidEvent", MapBuilder.of( "registrationName", "onAdRevenuePaidEvent" ) )
47
51
  .build();
48
52
  }
49
53
 
@@ -96,6 +100,12 @@ public class AppLovinMAXNativeAdViewManager
96
100
  view.setExtraParameters( value );
97
101
  }
98
102
 
103
+ @ReactProp(name = "localExtraParameters")
104
+ public void setLocalExtraParameters(final AppLovinMAXNativeAdView view, @Nullable final ReadableMap value)
105
+ {
106
+ view.setLocalExtraParameters( value );
107
+ }
108
+
99
109
  @ReactProp(name = "titleView")
100
110
  public void setTitleView(final AppLovinMAXNativeAdView view, final int value)
101
111
  {
@@ -120,10 +130,10 @@ public class AppLovinMAXNativeAdViewManager
120
130
  view.setCallToActionView( value );
121
131
  }
122
132
 
123
- @ReactProp(name = "mediaView")
124
- public void setMediaView(final AppLovinMAXNativeAdView view, final int value)
133
+ @ReactProp(name = "iconView")
134
+ public void setIconView(final AppLovinMAXNativeAdView view, final int value)
125
135
  {
126
- view.setMediaView( value );
136
+ view.setIconView( value );
127
137
  }
128
138
 
129
139
  @ReactProp(name = "optionsView")
@@ -132,10 +142,10 @@ public class AppLovinMAXNativeAdViewManager
132
142
  view.setOptionsView( value );
133
143
  }
134
144
 
135
- @ReactProp(name = "iconView")
136
- public void setIconView(final AppLovinMAXNativeAdView view, final int value)
145
+ @ReactProp(name = "mediaView")
146
+ public void setMediaView(final AppLovinMAXNativeAdView view, final int value)
137
147
  {
138
- view.setIconView( value );
148
+ view.setMediaView( value );
139
149
  }
140
150
 
141
151
  @Override
package/ios/AppLovinMAX.h CHANGED
@@ -37,9 +37,29 @@ NS_ASSUME_NONNULL_BEGIN
37
37
  - (void)log:(NSString *)format, ...;
38
38
 
39
39
  /**
40
- * Convenience method for invoking an ad load failure event.
40
+ * Convenience method for logging of access to the calling method before initialization.
41
41
  */
42
- - (void)sendReactNativeEventForAdLoadFailed:(NSString *)name forAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(nullable MAError *)error;
42
+ - (void)logUninitializedAccessError:(NSString *)callingMethod;
43
+
44
+ /**
45
+ * Returns a dictionay value of adInfo for the specified ad.
46
+ */
47
+ - (NSDictionary<NSString *, id> *)adInfoForAd:(MAAd *)ad;
48
+
49
+ /**
50
+ * Returns a dictionay value of adLoadFailedInfo for the specified error.
51
+ */
52
+ - (NSDictionary<NSString *, id> *)adLoadFailedInfoForAd:(NSString *)adUnitIdentifier withError:(MAError *)error;
53
+
54
+ /**
55
+ * Returns a dictionay value of adDisplayFailedInfo for the specified ad and error.
56
+ */
57
+ - (NSDictionary<NSString *, id> *)adDisplayFailedInfoForAd:(MAAd *)ad withError:(MAError *)error;
58
+
59
+ /**
60
+ * Returns a dictionay value of adRevenuInfo for the specified ad.
61
+ */
62
+ - (NSDictionary<NSString *, id> *)adRevenueInfoForAd:(MAAd *)ad;
43
63
 
44
64
  @end
45
65