react-native-applovin-max 6.1.0 → 6.1.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.
@@ -151,6 +151,7 @@ public class AppLovinMAXModule
151
151
  // Store these values if pub attempts to set it before initializing
152
152
  private List<String> initializationAdUnitIdsToSet;
153
153
  private String userIdToSet;
154
+ private Boolean mutedToSet;
154
155
  private List<String> testDeviceAdvertisingIdsToSet;
155
156
  private Boolean verboseLoggingToSet;
156
157
  private Boolean creativeDebuggerEnabledToSet;
@@ -331,6 +332,13 @@ public class AppLovinMAXModule
331
332
  debugUserGeographyToSet = null;
332
333
  }
333
334
 
335
+ // Set muted if needed
336
+ if ( mutedToSet != null )
337
+ {
338
+ settings.setMuted( mutedToSet );
339
+ mutedToSet = null;
340
+ }
341
+
334
342
  // Set test device ids if needed
335
343
  if ( testDeviceAdvertisingIdsToSet != null )
336
344
  {
@@ -531,9 +539,15 @@ public class AppLovinMAXModule
531
539
  @ReactMethod
532
540
  public void setMuted(final boolean muted)
533
541
  {
534
- if ( !isPluginInitialized ) return;
535
-
536
- sdk.getSettings().setMuted( muted );
542
+ if ( isPluginInitialized )
543
+ {
544
+ sdk.getSettings().setMuted( muted );
545
+ mutedToSet = null;
546
+ }
547
+ else
548
+ {
549
+ mutedToSet = muted;
550
+ }
537
551
  }
538
552
 
539
553
  @ReactMethod
@@ -1,6 +1,8 @@
1
1
  package com.applovin.reactnative;
2
2
 
3
3
  import android.content.Context;
4
+ import android.os.Handler;
5
+ import android.os.Looper;
4
6
  import android.text.TextUtils;
5
7
  import android.view.View;
6
8
  import android.view.ViewGroup;
@@ -29,8 +31,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
29
31
 
30
32
  import androidx.annotation.Nullable;
31
33
 
32
- import static com.applovin.sdk.AppLovinSdkUtils.runOnUiThreadDelayed;
33
-
34
34
  public class AppLovinMAXNativeAdView
35
35
  extends ReactViewGroup
36
36
  implements MaxAdRevenueListener, View.OnLayoutChangeListener, ViewGroup.OnHierarchyChangeListener
@@ -42,12 +42,15 @@ public class AppLovinMAXNativeAdView
42
42
  private static final int CALL_TO_ACTION_VIEW_TAG = 5;
43
43
  private static final int ADVERTISER_VIEW_TAG = 8;
44
44
 
45
- private final ReactContext reactContext;
45
+ private final ReactContext reactContext;
46
46
  @Nullable
47
- private MaxNativeAdLoader adLoader;
47
+ private MaxNativeAdLoader adLoader;
48
48
  @Nullable
49
- private MaxAd nativeAd;
50
- private final AtomicBoolean isLoading = new AtomicBoolean(); // Guard against repeated ad loads
49
+ private MaxAd nativeAd;
50
+ private final AtomicBoolean isLoading = new AtomicBoolean(); // Guard against repeated ad loads
51
+ private final AtomicBoolean isAdUnitIdSet = new AtomicBoolean();
52
+ private final Handler renderNativeAdHandler = new Handler( Looper.getMainLooper() );
53
+ private final RenderNativeAdTask renderNativeAdTask = new RenderNativeAdTask( this );
51
54
 
52
55
  @Nullable
53
56
  private View mediaView;
@@ -91,8 +94,7 @@ public class AppLovinMAXNativeAdView
91
94
 
92
95
  adUnitId = value;
93
96
 
94
- // Explicitly invoke ad load now that Ad Unit ID is set, but do so after 0.25s to allow other props to set
95
- postDelayed( this::loadAd, 250 );
97
+ isAdUnitIdSet.set( true );
96
98
  }
97
99
 
98
100
  public void setPlacement(@Nullable final String value)
@@ -197,25 +199,7 @@ public class AppLovinMAXNativeAdView
197
199
  // Notify `AppLovinNativeAdView.js`
198
200
  sendAdLoadedReactNativeEventForAd( ad.getNativeAd() );
199
201
 
200
- // After notifying the RN layer - have slight delay to let views bind to this layer in `clickableViews` before registering
201
- runOnUiThreadDelayed( () -> {
202
-
203
- // Loader can be null when the user hides before the properties are fully set
204
- if ( adLoader != null )
205
- {
206
- adLoader.a( clickableViews, AppLovinMAXNativeAdView.this, ad );
207
- adLoader.b( ad );
208
- }
209
-
210
- // Reassure the size of `mediaView` and its children for the networks, such as
211
- // LINE, where the actual ad contents are loaded after `mediaView` is sized.
212
- if ( mediaView != null && mediaView.getParent() != null )
213
- {
214
- sizeToFit( mediaView, (View) mediaView.getParent() );
215
- }
216
-
217
- isLoading.set( false );
218
- }, 500L );
202
+ isLoading.set( false );
219
203
  }
220
204
 
221
205
  @Override
@@ -421,6 +405,48 @@ public class AppLovinMAXNativeAdView
421
405
  }
422
406
  }
423
407
 
408
+ static class RenderNativeAdTask
409
+ implements Runnable
410
+ {
411
+ private AppLovinMAXNativeAdView nativeAdView;
412
+
413
+ RenderNativeAdTask(AppLovinMAXNativeAdView nativeAdView) { this.nativeAdView = nativeAdView; }
414
+
415
+ @Override
416
+ public void run()
417
+ {
418
+ if ( nativeAdView.adLoader == null ) return;
419
+
420
+ nativeAdView.adLoader.a( nativeAdView.clickableViews, nativeAdView, nativeAdView.nativeAd );
421
+ nativeAdView.adLoader.b( nativeAdView.nativeAd );
422
+
423
+ // LINE needs to be sized a while after its mediaView is attached to the React Native
424
+ if ( nativeAdView.mediaView != null && nativeAdView.mediaView.getParent() != null )
425
+ {
426
+ nativeAdView.renderNativeAdHandler.postDelayed( () -> sizeToFit( nativeAdView.mediaView, (View) nativeAdView.mediaView.getParent() ), 500 );
427
+ }
428
+ }
429
+ }
430
+
431
+ /**
432
+ * Invoked via ViewManager.onAfterUpdateTransaction():
433
+ * 1. after all the JavaScript properties are set when mounting NativeAdView
434
+ * 2. every time one of the asset views is mounted, following the 1st event
435
+ */
436
+ public void onSetProps()
437
+ {
438
+ if ( isAdUnitIdSet.compareAndSet( true, false ) )
439
+ {
440
+ loadAd();
441
+ }
442
+ else
443
+ {
444
+ // Renders the ad only after the last asset view is set
445
+ renderNativeAdHandler.removeCallbacksAndMessages( null );
446
+ renderNativeAdHandler.postDelayed( renderNativeAdTask, 1 );
447
+ }
448
+ }
449
+
424
450
  @Override
425
451
  public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
426
452
  {
@@ -148,6 +148,14 @@ public class AppLovinMAXNativeAdViewManager
148
148
  view.setMediaView( value );
149
149
  }
150
150
 
151
+ @Override
152
+ public void onAfterUpdateTransaction(final AppLovinMAXNativeAdView view)
153
+ {
154
+ super.onAfterUpdateTransaction( view );
155
+
156
+ view.onSetProps();
157
+ }
158
+
151
159
  @Override
152
160
  public void onDropViewInstance(@NonNull final AppLovinMAXNativeAdView view)
153
161
  {
package/ios/AppLovinMAX.m CHANGED
@@ -39,6 +39,7 @@
39
39
  // Store these values if pub attempts to set it before initializing
40
40
  @property (nonatomic, strong, nullable) NSArray<NSString *> *initializationAdUnitIdentifiersToSet;
41
41
  @property (nonatomic, copy, nullable) NSString *userIdentifierToSet;
42
+ @property (nonatomic, strong, nullable) NSNumber *mutedToSet;
42
43
  @property (nonatomic, strong, nullable) NSArray<NSString *> *testDeviceIdentifiersToSet;
43
44
  @property (nonatomic, strong, nullable) NSNumber *verboseLoggingToSet;
44
45
  @property (nonatomic, strong, nullable) NSNumber *creativeDebuggerEnabledToSet;
@@ -277,6 +278,13 @@ RCT_EXPORT_METHOD(initialize:(NSString *)pluginVersion :(NSString *)sdkKey :(RCT
277
278
  }
278
279
  }
279
280
 
281
+ // Set muted if needed
282
+ if ( self.mutedToSet )
283
+ {
284
+ settings.muted = self.mutedToSet;
285
+ self.mutedToSet = nil;
286
+ }
287
+
280
288
  // Set test device ids if needed
281
289
  if ( self.testDeviceIdentifiersToSet )
282
290
  {
@@ -438,9 +446,15 @@ RCT_EXPORT_METHOD(setUserId:(NSString *)userId)
438
446
 
439
447
  RCT_EXPORT_METHOD(setMuted:(BOOL)muted)
440
448
  {
441
- if ( ![self isPluginInitialized] ) return;
442
-
443
- self.sdk.settings.muted = muted;
449
+ if ( [self isPluginInitialized] )
450
+ {
451
+ self.sdk.settings.muted = muted;
452
+ self.mutedToSet = nil;
453
+ }
454
+ else
455
+ {
456
+ self.mutedToSet = @(muted);
457
+ }
444
458
  }
445
459
 
446
460
  RCT_EXPORT_METHOD(isMuted:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject)
@@ -31,6 +31,7 @@
31
31
  @property (nonatomic, strong, nullable) MANativeAdLoader *adLoader;
32
32
  @property (nonatomic, strong, nullable) MAAd *nativeAd;
33
33
  @property (nonatomic, strong) ALAtomicBoolean *isLoading; // Guard against repeated ad loads
34
+ @property (nonatomic, strong) ALAtomicBoolean *isAdUnitIdSet;
34
35
 
35
36
  // JavaScript properties
36
37
  @property (nonatomic, copy) NSString *adUnitId;
@@ -59,6 +60,7 @@
59
60
  {
60
61
  self.bridge = bridge;
61
62
  self.isLoading = [[ALAtomicBoolean alloc] init];
63
+ self.isAdUnitIdSet = [[ALAtomicBoolean alloc] init];
62
64
  self.clickableViews = [NSMutableArray array];
63
65
  }
64
66
  return self;
@@ -95,10 +97,7 @@
95
97
 
96
98
  _adUnitId = adUnitId;
97
99
 
98
- // Explicitly invoke ad load now that Ad Unit ID is set, but do so after 0.25s to allow other props to set
99
- dispatchOnMainQueueAfter(0.25, ^{
100
- [self loadAd];
101
- });
100
+ [self.isAdUnitIdSet set: YES];
102
101
  }
103
102
 
104
103
  // Called when Ad Unit ID is set, and via RN layer
@@ -267,6 +266,26 @@
267
266
  [self.nativeAd.nativeAd.mediaView al_pinToSuperview];
268
267
  }
269
268
 
269
+ /**
270
+ * Invoked:
271
+ * 1. after all the JavaScript properties are set when mounting NativeAdView
272
+ * 2. after all the user's asset views are mounted, following the 1st event
273
+ */
274
+ - (void)didSetProps:(NSArray<NSString *> *)changedProps
275
+ {
276
+ if ( [self.isAdUnitIdSet compareAndSet:YES update: NO] )
277
+ {
278
+ [self loadAd];
279
+ }
280
+ else
281
+ {
282
+ if ( !self.adLoader ) return;
283
+
284
+ [self.adLoader registerClickableViews: self.clickableViews withContainer: self forAd: self.nativeAd];
285
+ [self.adLoader handleNativeAdViewRenderedForAd: self.nativeAd];
286
+ }
287
+ }
288
+
270
289
  #pragma mark - Ad Loader Delegate
271
290
 
272
291
  - (void)didLoadNativeAd:(nullable MANativeAdView *)nativeAdView forAd:(MAAd *)ad
@@ -291,14 +310,7 @@
291
310
  // Notify `AppLovinNativeAdView.js`
292
311
  [self sendAdLoadedReactNativeEventForAd: ad.nativeAd];
293
312
 
294
- // After notifying the RN layer - have slight delay to let views bind to this layer in `clickableViews` before registering
295
- dispatchOnMainQueueAfter(0.5, ^{
296
-
297
- [self.adLoader registerClickableViews: self.clickableViews withContainer: self forAd: ad];
298
- [self.adLoader handleNativeAdViewRenderedForAd: ad];
299
-
300
- [self.isLoading set: NO];
301
- });
313
+ [self.isLoading set: NO];
302
314
  }
303
315
 
304
316
  - (void)sendAdLoadedReactNativeEventForAd:(MANativeAd *)ad
package/ios/Podfile CHANGED
@@ -35,6 +35,6 @@ target 'AppLovinMAX' do
35
35
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
36
36
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
37
37
 
38
- pod 'AppLovinSDK', '12.0.0'
38
+ pod 'AppLovinSDK', '12.1.0'
39
39
 
40
40
  end
package/ios/Podfile.lock CHANGED
@@ -1,5 +1,5 @@
1
1
  PODS:
2
- - AppLovinSDK (12.0.0)
2
+ - AppLovinSDK (12.1.0)
3
3
  - boost-for-react-native (1.63.0)
4
4
  - DoubleConversion (1.1.6)
5
5
  - FBLazyVector (0.63.5)
@@ -249,7 +249,7 @@ PODS:
249
249
  - Yoga (1.14.0)
250
250
 
251
251
  DEPENDENCIES:
252
- - AppLovinSDK (= 12.0.0)
252
+ - AppLovinSDK (= 12.1.0)
253
253
  - DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
254
254
  - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
255
255
  - FBReactNativeSpec (from `../node_modules/react-native/Libraries/FBReactNativeSpec`)
@@ -339,7 +339,7 @@ EXTERNAL SOURCES:
339
339
  :path: "../node_modules/react-native/ReactCommon/yoga"
340
340
 
341
341
  SPEC CHECKSUMS:
342
- AppLovinSDK: 15679e9f576a4d8662e1dc537c9a4ed47d3292a5
342
+ AppLovinSDK: 179d509c258e01a3a77eb8416f0ba843a12ed322
343
343
  boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
344
344
  DoubleConversion: cde416483dac037923206447da6e1454df403714
345
345
  FBLazyVector: 352a8ca9bbc8e2f097d680747a8c97ecef12d469
@@ -368,6 +368,6 @@ SPEC CHECKSUMS:
368
368
  ReactCommon: b9ff54b6dd22ba4a776eda22d7f83ec27544ca35
369
369
  Yoga: 0276e9f20976c8568e107cfc1163a8629051adc0
370
370
 
371
- PODFILE CHECKSUM: dc95f857ab3004d6fc04e845d974091e28859c7b
371
+ PODFILE CHECKSUM: d7248805481768209533def6ca165110984d9914
372
372
 
373
373
  COCOAPODS: 1.11.3
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.1.0",
4
+ "version": "6.1.1",
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,10 +11,10 @@ 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_1_0" }
14
+ s.source = { :git => "https://github.com/AppLovin/AppLovin-MAX-React-Native.git", :tag => "release_6_1_1" }
15
15
 
16
16
  s.source_files = "ios/AppLovinMAX*.{h,m}"
17
17
 
18
18
  s.dependency "React"
19
- s.dependency "AppLovinSDK", "12.0.0"
19
+ s.dependency "AppLovinSDK", "12.1.0"
20
20
  end
@@ -4,7 +4,7 @@ import type { Configuration } from './types/Configuration';
4
4
 
5
5
  const NativeAppLovinMAX = NativeModules.AppLovinMAX;
6
6
 
7
- const VERSION = '6.1.0';
7
+ const VERSION = '6.1.1';
8
8
 
9
9
  const initialize = async (sdkKey: string): Promise<Configuration> => {
10
10
  return NativeAppLovinMAX.initialize(VERSION, sdkKey);