react-native-applovin-max 2.3.1 → 2.4.2

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.
@@ -41,8 +41,8 @@ android {
41
41
  defaultConfig {
42
42
  minSdkVersion 16
43
43
  targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
44
- versionCode 2030100
45
- versionName "2.3.1"
44
+ versionCode 2040200
45
+ versionName "2.4.2"
46
46
  }
47
47
 
48
48
  flavorDimensions("default")
@@ -1,84 +1,84 @@
1
- @if "%DEBUG%" == "" @echo off
2
- @rem ##########################################################################
3
- @rem
4
- @rem Gradle startup script for Windows
5
- @rem
6
- @rem ##########################################################################
7
-
8
- @rem Set local scope for the variables with windows NT shell
9
- if "%OS%"=="Windows_NT" setlocal
10
-
11
- set DIRNAME=%~dp0
12
- if "%DIRNAME%" == "" set DIRNAME=.
13
- set APP_BASE_NAME=%~n0
14
- set APP_HOME=%DIRNAME%
15
-
16
- @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17
- set DEFAULT_JVM_OPTS=
18
-
19
- @rem Find java.exe
20
- if defined JAVA_HOME goto findJavaFromJavaHome
21
-
22
- set JAVA_EXE=java.exe
23
- %JAVA_EXE% -version >NUL 2>&1
24
- if "%ERRORLEVEL%" == "0" goto init
25
-
26
- echo.
27
- echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28
- echo.
29
- echo Please set the JAVA_HOME variable in your environment to match the
30
- echo location of your Java installation.
31
-
32
- goto fail
33
-
34
- :findJavaFromJavaHome
35
- set JAVA_HOME=%JAVA_HOME:"=%
36
- set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37
-
38
- if exist "%JAVA_EXE%" goto init
39
-
40
- echo.
41
- echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42
- echo.
43
- echo Please set the JAVA_HOME variable in your environment to match the
44
- echo location of your Java installation.
45
-
46
- goto fail
47
-
48
- :init
49
- @rem Get command-line arguments, handling Windows variants
50
-
51
- if not "%OS%" == "Windows_NT" goto win9xME_args
52
-
53
- :win9xME_args
54
- @rem Slurp the command line arguments.
55
- set CMD_LINE_ARGS=
56
- set _SKIP=2
57
-
58
- :win9xME_args_slurp
59
- if "x%~1" == "x" goto execute
60
-
61
- set CMD_LINE_ARGS=%*
62
-
63
- :execute
64
- @rem Setup the command line
65
-
66
- set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67
-
68
- @rem Execute Gradle
69
- "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70
-
71
- :end
72
- @rem End local scope for the variables with windows NT shell
73
- if "%ERRORLEVEL%"=="0" goto mainEnd
74
-
75
- :fail
76
- rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77
- rem the _cmd.exe /c_ return code!
78
- if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79
- exit /b 1
80
-
81
- :mainEnd
82
- if "%OS%"=="Windows_NT" endlocal
83
-
84
- :omega
1
+ @if "%DEBUG%" == "" @echo off
2
+ @rem ##########################################################################
3
+ @rem
4
+ @rem Gradle startup script for Windows
5
+ @rem
6
+ @rem ##########################################################################
7
+
8
+ @rem Set local scope for the variables with windows NT shell
9
+ if "%OS%"=="Windows_NT" setlocal
10
+
11
+ set DIRNAME=%~dp0
12
+ if "%DIRNAME%" == "" set DIRNAME=.
13
+ set APP_BASE_NAME=%~n0
14
+ set APP_HOME=%DIRNAME%
15
+
16
+ @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17
+ set DEFAULT_JVM_OPTS=
18
+
19
+ @rem Find java.exe
20
+ if defined JAVA_HOME goto findJavaFromJavaHome
21
+
22
+ set JAVA_EXE=java.exe
23
+ %JAVA_EXE% -version >NUL 2>&1
24
+ if "%ERRORLEVEL%" == "0" goto init
25
+
26
+ echo.
27
+ echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28
+ echo.
29
+ echo Please set the JAVA_HOME variable in your environment to match the
30
+ echo location of your Java installation.
31
+
32
+ goto fail
33
+
34
+ :findJavaFromJavaHome
35
+ set JAVA_HOME=%JAVA_HOME:"=%
36
+ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37
+
38
+ if exist "%JAVA_EXE%" goto init
39
+
40
+ echo.
41
+ echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42
+ echo.
43
+ echo Please set the JAVA_HOME variable in your environment to match the
44
+ echo location of your Java installation.
45
+
46
+ goto fail
47
+
48
+ :init
49
+ @rem Get command-line arguments, handling Windows variants
50
+
51
+ if not "%OS%" == "Windows_NT" goto win9xME_args
52
+
53
+ :win9xME_args
54
+ @rem Slurp the command line arguments.
55
+ set CMD_LINE_ARGS=
56
+ set _SKIP=2
57
+
58
+ :win9xME_args_slurp
59
+ if "x%~1" == "x" goto execute
60
+
61
+ set CMD_LINE_ARGS=%*
62
+
63
+ :execute
64
+ @rem Setup the command line
65
+
66
+ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67
+
68
+ @rem Execute Gradle
69
+ "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70
+
71
+ :end
72
+ @rem End local scope for the variables with windows NT shell
73
+ if "%ERRORLEVEL%"=="0" goto mainEnd
74
+
75
+ :fail
76
+ rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77
+ rem the _cmd.exe /c_ return code!
78
+ if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79
+ exit /b 1
80
+
81
+ :mainEnd
82
+ if "%OS%"=="Windows_NT" endlocal
83
+
84
+ :omega
@@ -2,16 +2,15 @@ package com.applovin.reactnative;
2
2
 
3
3
  import android.app.Activity;
4
4
  import android.content.Context;
5
- import android.graphics.Point;
6
5
  import android.text.TextUtils;
7
- import android.view.ViewGroup;
8
- import android.view.ViewParent;
9
6
 
10
7
  import com.applovin.mediation.MaxAdFormat;
11
8
  import com.applovin.mediation.ads.MaxAdView;
12
9
  import com.facebook.react.uimanager.ThemedReactContext;
13
10
  import com.facebook.react.views.view.ReactViewGroup;
14
11
 
12
+ import androidx.annotation.Nullable;
13
+
15
14
  /**
16
15
  * Created by Thomas So on September 27 2020
17
16
  */
@@ -69,9 +68,15 @@ class AppLovinMAXAdView
69
68
  }
70
69
  }
71
70
 
72
- public void maybeAttachAdView(final String adUnitId, final MaxAdFormat adFormat)
71
+ @Nullable
72
+ protected MaxAdView getAdView()
73
+ {
74
+ return adView;
75
+ }
76
+
77
+ public void maybeAttachAdView(final String placement, final String adaptiveBannerEnabledStr, final String adUnitId, final MaxAdFormat adFormat)
73
78
  {
74
- Activity currentActivity = reactContext.getCurrentActivity();
79
+ final Activity currentActivity = reactContext.getCurrentActivity();
75
80
  if ( currentActivity == null )
76
81
  {
77
82
  AppLovinMAXModule.e( "Unable to attach AdView - no current Activity found" );
@@ -87,19 +92,24 @@ class AppLovinMAXAdView
87
92
  // If ad unit id and format has been set - create and attach AdView
88
93
  if ( !TextUtils.isEmpty( adUnitId ) && adFormat != null )
89
94
  {
90
- adView = AppLovinMAXModule.getInstance().retrieveAdView( adUnitId, adFormat, "", new Point( 0, 0 ) );
91
- adView.loadAd();
95
+ adView = new MaxAdView( adUnitId, adFormat, AppLovinMAXModule.getInstance().getSdk(), currentActivity );
96
+ adView.setListener( AppLovinMAXModule.getInstance() );
92
97
 
93
- currentWidthPx = getWidth();
94
- currentHeightPx = getHeight();
98
+ if ( placement != null )
99
+ {
100
+ adView.setPlacement( placement );
101
+ }
95
102
 
96
- // Handle fast refresh cases of re-adding adView
97
- ViewParent parent = adView.getParent();
98
- if ( parent instanceof ViewGroup )
103
+ if ( adaptiveBannerEnabledStr != null )
99
104
  {
100
- ( (ViewGroup) parent ).removeView( adView );
105
+ adView.setExtraParameter( "adaptive_banner", adaptiveBannerEnabledStr );
101
106
  }
102
107
 
108
+ adView.loadAd();
109
+
110
+ currentWidthPx = getWidth();
111
+ currentHeightPx = getHeight();
112
+
103
113
  addView( adView );
104
114
  }
105
115
  }
@@ -1,6 +1,7 @@
1
1
  package com.applovin.reactnative;
2
2
 
3
3
  import com.applovin.mediation.MaxAdFormat;
4
+ import com.applovin.mediation.ads.MaxAdView;
4
5
  import com.facebook.react.bridge.ReactApplicationContext;
5
6
  import com.facebook.react.bridge.ReadableArray;
6
7
  import com.facebook.react.uimanager.SimpleViewManager;
@@ -28,6 +29,10 @@ class AppLovinMAXAdViewManager
28
29
  private final Map<AppLovinMAXAdView, String> adUnitIdRegistry = new HashMap<>();
29
30
  private final Map<AppLovinMAXAdView, MaxAdFormat> adFormatRegistry = new HashMap<>();
30
31
 
32
+ // Storage for placement and extra parameters if set before the MAAdView is created
33
+ private final Map<AppLovinMAXAdView, String> placementRegistry = new HashMap<>();
34
+ private final Map<AppLovinMAXAdView, String> adaptiveBannerEnabledRegistry = new HashMap<>();
35
+
31
36
  public AppLovinMAXAdViewManager(final ReactApplicationContext reactApplicationContext)
32
37
  {
33
38
  this.reactApplicationContext = reactApplicationContext;
@@ -49,13 +54,26 @@ class AppLovinMAXAdViewManager
49
54
  @Override
50
55
  public void receiveCommand(@NonNull AppLovinMAXAdView view, String commandId, @Nullable ReadableArray args)
51
56
  {
52
- if ( "setAdUnitId".equals( commandId ) && args != null )
57
+ if ( args == null ) return;
58
+
59
+ String arg = args.getString( 0 );
60
+ if ( arg == null ) return;
61
+
62
+ if ( "setPlacement".equals( commandId ) )
63
+ {
64
+ setPlacement( view, arg );
65
+ }
66
+ else if ( "setAdaptiveBannerEnabled".equals( commandId ) )
53
67
  {
54
- setAdUnitId( view, args.getString( 0 ) );
68
+ setAdaptiveBannerEnabled( view, arg );
55
69
  }
56
- else if ( "setAdFormat".equals( commandId ) && args != null )
70
+ else if ( "setAdUnitId".equals( commandId ) )
57
71
  {
58
- setAdFormat( view, args.getString( 0 ) );
72
+ setAdUnitId( view, arg );
73
+ }
74
+ else if ( "setAdFormat".equals( commandId ) )
75
+ {
76
+ setAdFormat( view, arg );
59
77
  }
60
78
  else
61
79
  {
@@ -63,11 +81,44 @@ class AppLovinMAXAdViewManager
63
81
  }
64
82
  }
65
83
 
84
+ public void setPlacement(final AppLovinMAXAdView view, final String placement)
85
+ {
86
+ // Post to main thread to avoid race condition with actual creation of MaxAdView in maybeAttachAdView()
87
+ view.post( () -> {
88
+
89
+ MaxAdView adView = view.getAdView();
90
+ if ( adView != null )
91
+ {
92
+ adView.setPlacement( placement );
93
+ }
94
+ else
95
+ {
96
+ placementRegistry.put( view, placement );
97
+ }
98
+ } );
99
+ }
100
+
101
+ public void setAdaptiveBannerEnabled(final AppLovinMAXAdView view, final String enabledStr)
102
+ {
103
+ // Post to main thread to avoid race condition with actual creation of MaxAdView in maybeAttachAdView()
104
+ view.post( () -> {
105
+
106
+ MaxAdView adView = view.getAdView();
107
+ if ( adView != null )
108
+ {
109
+ adView.setExtraParameter( "adaptive_banner", enabledStr );
110
+ }
111
+ else
112
+ {
113
+ adaptiveBannerEnabledRegistry.put( view, enabledStr );
114
+ }
115
+ } );
116
+ }
117
+
66
118
  public void setAdUnitId(final AppLovinMAXAdView view, final String adUnitId)
67
119
  {
68
120
  adUnitIdRegistry.put( view, adUnitId );
69
-
70
- view.maybeAttachAdView( adUnitIdRegistry.get( view ), adFormatRegistry.get( view ) );
121
+ maybeAttachAdView( view );
71
122
  }
72
123
 
73
124
  public void setAdFormat(final AppLovinMAXAdView view, final String adFormatStr)
@@ -81,7 +132,18 @@ class AppLovinMAXAdViewManager
81
132
  adFormatRegistry.put( view, MaxAdFormat.MREC );
82
133
  }
83
134
 
84
- view.maybeAttachAdView( adUnitIdRegistry.get( view ), adFormatRegistry.get( view ) );
135
+ maybeAttachAdView( view );
136
+ }
137
+
138
+ private void maybeAttachAdView(final AppLovinMAXAdView view)
139
+ {
140
+ String placement = placementRegistry.remove( view );
141
+ String adaptiveBannerEnabledStr = adaptiveBannerEnabledRegistry.remove( view );
142
+
143
+ view.maybeAttachAdView( placement,
144
+ adaptiveBannerEnabledStr,
145
+ adUnitIdRegistry.get( view ),
146
+ adFormatRegistry.get( view ) );
85
147
  }
86
148
 
87
149
  @Override
@@ -103,6 +103,11 @@ public class AppLovinMAXModule
103
103
  return instance;
104
104
  }
105
105
 
106
+ public AppLovinSdk getSdk()
107
+ {
108
+ return sdk;
109
+ }
110
+
106
111
  public AppLovinMAXModule(final ReactApplicationContext reactContext)
107
112
  {
108
113
  super( reactContext );
@@ -1203,7 +1208,7 @@ public class AppLovinMAXModule
1203
1208
  return retrieveAdView( adUnitId, adFormat, null, DEFAULT_AD_VIEW_OFFSET );
1204
1209
  }
1205
1210
 
1206
- public MaxAdView retrieveAdView(String adUnitId, MaxAdFormat adFormat, String adViewPosition, Point adViewOffsetPixels)
1211
+ private MaxAdView retrieveAdView(String adUnitId, MaxAdFormat adFormat, String adViewPosition, Point adViewOffsetPixels)
1207
1212
  {
1208
1213
  MaxAdView result = mAdViews.get( adUnitId );
1209
1214
  if ( result == null && adViewPosition != null && adViewOffsetPixels != null )
@@ -1233,13 +1238,10 @@ public class AppLovinMAXModule
1233
1238
  return;
1234
1239
  }
1235
1240
 
1236
- final RelativeLayout relativeLayout = (RelativeLayout) adView.getParent();
1237
- if ( relativeLayout == null )
1238
- {
1239
- e( adFormat.getLabel() + "'s parent does not exist" );
1240
- return;
1241
- }
1241
+ final ViewParent parent = adView.getParent();
1242
+ if ( !( parent instanceof RelativeLayout ) ) return;
1242
1243
 
1244
+ final RelativeLayout relativeLayout = (RelativeLayout) parent;
1243
1245
  final Rect windowRect = new Rect();
1244
1246
  relativeLayout.getWindowVisibleDisplayFrame( windowRect );
1245
1247
 
package/ios/AppLovinMAX.h CHANGED
@@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
19
19
  /**
20
20
  * The primary bridge between JS <-> native code for the AppLovin MAX React Native module.
21
21
  */
22
- @interface AppLovinMAX : RCTEventEmitter<RCTBridgeModule>
22
+ @interface AppLovinMAX : RCTEventEmitter<RCTBridgeModule, MAAdDelegate, MARewardedAdDelegate, MAAdViewAdDelegate>
23
23
 
24
24
  /**
25
25
  * Shared instance of this bridge module.
@@ -27,13 +27,9 @@ NS_ASSUME_NONNULL_BEGIN
27
27
  @property (nonatomic, strong, readonly, class) AppLovinMAX *shared;
28
28
 
29
29
  /**
30
- * Dedicated method for retrieving a MAAdView.
30
+ * The instance of the AppLovin SDK the module is using.
31
31
  */
32
- - (MAAdView *)retrieveAdViewForAdUnitIdentifier:(NSString *)adUnitIdentifier
33
- adFormat:(MAAdFormat *)adFormat
34
- atPosition:(NSString *)adViewPosition
35
- withOffset:(CGPoint)offset
36
- attach:(BOOL)attach;
32
+ @property (nonatomic, weak, readonly) ALSdk *sdk;
37
33
 
38
34
  @end
39
35
 
package/ios/AppLovinMAX.m CHANGED
@@ -27,7 +27,7 @@
27
27
  @property (nonatomic, assign, readonly, getter=al_isValidString) BOOL al_validString;
28
28
  @end
29
29
 
30
- @interface AppLovinMAX()<MAAdDelegate, MAAdViewAdDelegate, MARewardedAdDelegate>
30
+ @interface AppLovinMAX()
31
31
 
32
32
  // Parent Fields
33
33
  @property (nonatomic, weak) ALSdk *sdk;
@@ -802,7 +802,7 @@ RCT_EXPORT_METHOD(setRewardedAdExtraParameter:(NSString *)adUnitIdentifier :(NSS
802
802
  MAAdView *adView = [self retrieveAdViewForAdUnitIdentifier: adUnitIdentifier adFormat: adFormat];
803
803
  [adView setExtraParameterForKey: key value: value];
804
804
 
805
- if ( [@"force_banner" isEqualToString: key] && MAAdFormat.mrec != adFormat )
805
+ if ( [@"force_banner" isEqualToString: key] && MAAdFormat.mrec != adFormat )
806
806
  {
807
807
  // Handle local changes as needed
808
808
  MAAdFormat *adFormat;
@@ -942,11 +942,6 @@ RCT_EXPORT_METHOD(setRewardedAdExtraParameter:(NSString *)adUnitIdentifier :(NSS
942
942
  }
943
943
 
944
944
  - (MAAdView *)retrieveAdViewForAdUnitIdentifier:(NSString *)adUnitIdentifier adFormat:(MAAdFormat *)adFormat atPosition:(NSString *)adViewPosition withOffset:(CGPoint)offset
945
- {
946
- return [self retrieveAdViewForAdUnitIdentifier: adUnitIdentifier adFormat: adFormat atPosition: adViewPosition withOffset: offset attach: YES];
947
- }
948
-
949
- - (MAAdView *)retrieveAdViewForAdUnitIdentifier:(NSString *)adUnitIdentifier adFormat:(MAAdFormat *)adFormat atPosition:(NSString *)adViewPosition withOffset:(CGPoint)offset attach:(BOOL)attach
950
945
  {
951
946
  MAAdView *result = self.adViews[adUnitIdentifier];
952
947
  if ( !result && adViewPosition )
@@ -957,14 +952,9 @@ RCT_EXPORT_METHOD(setRewardedAdExtraParameter:(NSString *)adUnitIdentifier :(NSS
957
952
  result.translatesAutoresizingMaskIntoConstraints = NO;
958
953
 
959
954
  self.adViews[adUnitIdentifier] = result;
960
-
961
- // If this is programmatic (non native RN)
962
- if ( attach )
963
- {
964
- self.adViewPositions[adUnitIdentifier] = adViewPosition;
965
- self.adViewOffsets[adUnitIdentifier] = [NSValue valueWithCGPoint: offset];
966
- [ROOT_VIEW_CONTROLLER.view addSubview: result];
967
- }
955
+ self.adViewPositions[adUnitIdentifier] = adViewPosition;
956
+ self.adViewOffsets[adUnitIdentifier] = [NSValue valueWithCGPoint: offset];
957
+ [ROOT_VIEW_CONTROLLER.view addSubview: result];
968
958
  }
969
959
 
970
960
  return result;
@@ -23,6 +23,10 @@
23
23
  @property (nonatomic, strong) NSMutableDictionary<NSNumber *, NSString *> *adUnitIdRegistry;
24
24
  @property (nonatomic, strong) NSMutableDictionary<NSNumber *, MAAdFormat *> *adFormatRegistry;
25
25
 
26
+ // Storage for placement and extra parameters if set before the MAAdView is created
27
+ @property (nonatomic, strong) NSMutableDictionary<NSNumber *, NSString *> *placementRegistry;
28
+ @property (nonatomic, strong) NSMutableDictionary<NSNumber *, NSString *> *adaptiveBannerEnabledRegistry;
29
+
26
30
  @end
27
31
 
28
32
  @implementation AppLovinMAXAdViewManager
@@ -41,6 +45,8 @@ RCT_EXPORT_MODULE(AppLovinMAXAdView)
41
45
  {
42
46
  self.adUnitIdRegistry = [NSMutableDictionary dictionary];
43
47
  self.adFormatRegistry = [NSMutableDictionary dictionary];
48
+ self.placementRegistry = [NSMutableDictionary dictionary];
49
+ self.adaptiveBannerEnabledRegistry = [NSMutableDictionary dictionary];
44
50
  }
45
51
  return self;
46
52
  }
@@ -52,7 +58,7 @@ RCT_EXPORT_MODULE(AppLovinMAXAdView)
52
58
  }
53
59
 
54
60
  // NOTE: `nonnull` must be annotated here for this RN export to work at runtime
55
- RCT_EXPORT_METHOD(setAdUnitId:(nonnull NSNumber *)viewTag toAdUnitId:(NSString *)adUnitId)
61
+ RCT_EXPORT_METHOD(setPlacement:(nonnull NSNumber *)viewTag toPlacement:(NSString *)placement)
56
62
  {
57
63
  [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
58
64
 
@@ -63,17 +69,68 @@ RCT_EXPORT_METHOD(setAdUnitId:(nonnull NSNumber *)viewTag toAdUnitId:(NSString *
63
69
  RCTLogError(@"Cannot find UIView with tag %@", viewTag);
64
70
  return;
65
71
  }
72
+
73
+ MAAdView *adView = [self adViewFromContainerView: view];
74
+ if ( adView )
75
+ {
76
+ adView.placement = placement;
77
+ }
78
+ else
79
+ {
80
+ self.placementRegistry[viewTag] = placement;
81
+ }
82
+ }];
83
+ }
66
84
 
85
+ // NOTE: `nonnull` must be annotated here for this RN export to work at runtime
86
+ RCT_EXPORT_METHOD(setAdaptiveBannerEnabled:(nonnull NSNumber *)viewTag toEnabled:(NSString *)enabledStr)
87
+ {
88
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
89
+
90
+ // NOTE: iOS caches the native view via `viewTag` when you remove it from screen (unlike Android)
91
+ UIView *view = viewRegistry[viewTag];
92
+ if ( !view )
93
+ {
94
+ RCTLogError(@"Cannot find UIView with tag %@", viewTag);
95
+ return;
96
+ }
97
+
98
+ MAAdView *adView = [self adViewFromContainerView: view];
99
+ if ( adView )
100
+ {
101
+ [adView setExtraParameterForKey: @"adaptive_banner" value: enabledStr];
102
+ }
103
+ else
104
+ {
105
+ self.adaptiveBannerEnabledRegistry[viewTag] = enabledStr;
106
+ }
107
+ }];
108
+ }
109
+
110
+ // NOTE: `nonnull` must be annotated here for this RN export to work at runtime
111
+ RCT_EXPORT_METHOD(setAdUnitId:(nonnull NSNumber *)viewTag toAdUnitId:(NSString *)adUnitId)
112
+ {
113
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
114
+
115
+ // NOTE: iOS caches the native view via `viewTag` when you remove it from screen (unlike Android)
116
+ UIView *view = viewRegistry[viewTag];
117
+ if ( !view )
118
+ {
119
+ RCTLogError(@"Cannot find UIView with tag %@", viewTag);
120
+ return;
121
+ }
122
+
67
123
  self.adUnitIdRegistry[viewTag] = adUnitId;
68
124
 
69
- [self attachAdViewIfNeededForAdUnitIdentifier: self.adUnitIdRegistry[viewTag]
70
- adFormat: self.adFormatRegistry[viewTag]
71
- containerView: view];
125
+ [self attachAdViewIfNeededForViewTag: viewTag
126
+ adUnitIdentifier: self.adUnitIdRegistry[viewTag]
127
+ adFormat: self.adFormatRegistry[viewTag]
128
+ containerView: view];
72
129
  }];
73
130
  }
74
131
 
75
132
  // NOTE: `nonnull` must be annotated here for this RN export to work at runtime
76
- RCT_EXPORT_METHOD(setAdFormat:(nonnull NSNumber *)viewTag toAdFormat:(NSString *)adFormatString)
133
+ RCT_EXPORT_METHOD(setAdFormat:(nonnull NSNumber *)viewTag toAdFormat:(NSString *)adFormatStr)
77
134
  {
78
135
  [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
79
136
 
@@ -85,22 +142,23 @@ RCT_EXPORT_METHOD(setAdFormat:(nonnull NSNumber *)viewTag toAdFormat:(NSString *
85
142
  return;
86
143
  }
87
144
 
88
- if ( [@"banner" isEqualToString: adFormatString] )
145
+ if ( [@"banner" isEqualToString: adFormatStr] )
89
146
  {
90
147
  self.adFormatRegistry[viewTag] = DEVICE_SPECIFIC_ADVIEW_AD_FORMAT;
91
148
  }
92
- else if ( [@"mrec" isEqualToString: adFormatString] )
149
+ else if ( [@"mrec" isEqualToString: adFormatStr] )
93
150
  {
94
151
  self.adFormatRegistry[viewTag] = MAAdFormat.mrec;
95
152
  }
96
-
97
- [self attachAdViewIfNeededForAdUnitIdentifier: self.adUnitIdRegistry[viewTag]
98
- adFormat: self.adFormatRegistry[viewTag]
99
- containerView: view];
153
+
154
+ [self attachAdViewIfNeededForViewTag: viewTag
155
+ adUnitIdentifier: self.adUnitIdRegistry[viewTag]
156
+ adFormat: self.adFormatRegistry[viewTag]
157
+ containerView: view];
100
158
  }];
101
159
  }
102
160
 
103
- - (void)attachAdViewIfNeededForAdUnitIdentifier:(NSString *)adUnitIdentifier adFormat:(MAAdFormat *)adFormat containerView:(UIView *)containerView
161
+ - (void)attachAdViewIfNeededForViewTag:(NSNumber *)viewTag adUnitIdentifier:(NSString *)adUnitIdentifier adFormat:(MAAdFormat *)adFormat containerView:(UIView *)containerView
104
162
  {
105
163
  // Run after delay to ensure SDK is attached to main module first
106
164
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@@ -108,7 +166,8 @@ RCT_EXPORT_METHOD(setAdFormat:(nonnull NSNumber *)viewTag toAdFormat:(NSString *
108
166
  // If ad unit id and format has been set - create and attach AdView
109
167
  if ( [adUnitIdentifier al_isValidString] && adFormat )
110
168
  {
111
- MAAdView *adView = [self getMAAdViewFromContainerView: containerView];
169
+ MAAdView *adView = [self adViewFromContainerView: containerView];
170
+
112
171
  // Check if there's a previously-attached AdView
113
172
  if ( adView )
114
173
  {
@@ -118,11 +177,24 @@ RCT_EXPORT_METHOD(setAdFormat:(nonnull NSNumber *)viewTag toAdFormat:(NSString *
118
177
  adView = nil;
119
178
  }
120
179
 
121
- adView = [AppLovinMAX.shared retrieveAdViewForAdUnitIdentifier: adUnitIdentifier
122
- adFormat: adFormat
123
- atPosition: @""
124
- withOffset: CGPointZero
125
- attach: NO];
180
+ adView = [[MAAdView alloc] initWithAdUnitIdentifier: adUnitIdentifier adFormat: adFormat sdk: AppLovinMAX.shared.sdk];
181
+ adView.frame = (CGRect) { CGPointZero, adFormat.size };
182
+ adView.delegate = AppLovinMAX.shared; // Go through core class for callback forwarding to React Native layer
183
+
184
+ NSString *placement = self.placementRegistry[viewTag];
185
+ if ( placement )
186
+ {
187
+ [self.placementRegistry removeObjectForKey: viewTag];
188
+ adView.placement = placement;
189
+ }
190
+
191
+ NSString *adaptiveBannerEnabledStr = self.adaptiveBannerEnabledRegistry[viewTag];
192
+ if ( [adaptiveBannerEnabledStr al_isValidString] )
193
+ {
194
+ [self.adaptiveBannerEnabledRegistry removeObjectForKey: viewTag];
195
+ [adView setExtraParameterForKey: @"adaptive_banner" value: adaptiveBannerEnabledStr];
196
+ }
197
+
126
198
  [adView loadAd];
127
199
 
128
200
  [containerView addSubview: adView];
@@ -138,7 +210,7 @@ RCT_EXPORT_METHOD(setAdFormat:(nonnull NSNumber *)viewTag toAdFormat:(NSString *
138
210
 
139
211
  // MARK: - Helper Functions
140
212
 
141
- - (nullable MAAdView *)getMAAdViewFromContainerView:(UIView *)view
213
+ - (nullable MAAdView *)adViewFromContainerView:(UIView *)view
142
214
  {
143
215
  return view.subviews.count > 0 ? ((MAAdView *) view.subviews.lastObject) : nil;
144
216
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-applovin-max",
3
3
  "author": "AppLovin Corporation",
4
- "version": "2.3.1",
4
+ "version": "2.4.2",
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_2_3_1" }
14
+ s.source = { :git => "https://github.com/AppLovin/AppLovin-MAX-React-Native.git", :tag => "release_2_4_2" }
15
15
 
16
16
  s.source_files = "ios/AppLovinMAX*.{h,m}"
17
17
 
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/src.iml" filepath="$PROJECT_DIR$/.idea/src.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5
+ </component>
6
+ </project>
@@ -87,11 +87,11 @@ class AdView extends React.Component {
87
87
  // If the ad unit id or ad format are unset, we can't set the placement.
88
88
  if (adUnitId == null || adFormat == null) return;
89
89
 
90
- if (adFormat === AppLovinMAX.AdFormat.BANNER) {
91
- AppLovinMAX.setBannerPlacement(adUnitId, placement);
92
- } else if (adFormat === AppLovinMAX.AdFormat.MREC) {
93
- AppLovinMAX.setMRecPlacement(adUnitId, placement);
94
- }
90
+ UIManager.dispatchViewManagerCommand(
91
+ findNodeHandle(this),
92
+ Platform.OS === 'android' ? "setPlacement" : UIManager.getViewManagerConfig("AppLovinMAXAdView").Commands.setPlacement,
93
+ [placement]
94
+ );
95
95
  }
96
96
 
97
97
  setAdaptiveBannerEnabled(enabled) {
@@ -103,7 +103,11 @@ class AdView extends React.Component {
103
103
 
104
104
  if (adFormat === AppLovinMAX.AdFormat.BANNER) {
105
105
  if (enabled === true || enabled === false) {
106
- AppLovinMAX.setBannerExtraParameter(adUnitId, "adaptive_banner", enabled ? "true" : "false");
106
+ UIManager.dispatchViewManagerCommand(
107
+ findNodeHandle(this),
108
+ Platform.OS === 'android' ? "setAdaptiveBannerEnabled" : UIManager.getViewManagerConfig("AppLovinMAXAdView").Commands.setAdaptiveBannerEnabled,
109
+ [enabled ? "true" : "false"]
110
+ );
107
111
  }
108
112
  }
109
113
  }
package/src/index.js CHANGED
@@ -3,7 +3,7 @@ import AdView from "./AppLovinMAXAdView";
3
3
 
4
4
  const { AppLovinMAX } = NativeModules;
5
5
 
6
- const VERSION = "2.3.1";
6
+ const VERSION = "2.4.2";
7
7
 
8
8
  /**
9
9
  * This enum represents whether or not the consent dialog should be shown for this user.
@@ -76,14 +76,6 @@ export default {
76
76
  initialize(sdkKey, callback) {
77
77
  AppLovinMAX.initialize(VERSION, sdkKey, callback); // Inject VERSION into native code
78
78
  },
79
- // Support for showing ad without placement
80
- showInterstitial(adUnitId) {
81
- AppLovinMAX.showInterstitial(adUnitId, "");
82
- },
83
- // Support for showing ad without placement
84
- showRewardedAd(adUnitId) {
85
- AppLovinMAX.showRewardedAd(adUnitId, "");
86
- },
87
79
 
88
80
  /*----------------------*/
89
81
  /** AUTO-DECLARED APIs **/
package/CHANGELOG.md DELETED
@@ -1,66 +0,0 @@
1
- ## Versions
2
-
3
- ## 2.3.1
4
- * Fix NPE in `positionAdView()`.
5
- ## 2.3.0
6
- * Enable adaptive banners by default.
7
- * Add support for native ad placements. Docs can be found [here](https://dash.applovin.com/documentation/mediation/react-native/getting-started/advanced-settings#banners-/-mrecs-(native-ui-component-method)).
8
- * Fix thread warning with native component AdViews.
9
- ## 2.2.0
10
- * Allow for multiple native `AppLovinMAX.AdView`s at once on a screen (e.g. a banner and a mrec).
11
- ## 2.1.3
12
- * Add support for latest SDKs v10.3.1 with new callbacks.
13
- ## 2.1.2
14
- * Fix banners and MRECs native UI components not clicking if not styled by parent dom.
15
- ## 2.1.1
16
- * Fix iOS projects not building.
17
- ## 2.1.0
18
- * Add API for passing in `errorInfo` for ad load failure callbacks with parameters "code", "message", and "adLoadFailureInfo".
19
- * Add API for passing in `errorInfo` for ad display failure callbacks with parameters "code" and "message".
20
- * Add API for creating and updating banner X and Y offsets. For example, to offset banner 50px from a bottom center position: `AppLovinMAX.createBannerWithOffsets(adUnitId, AppLovinMAX.AdViewPosition.BOTTOM_CENTER, 0, 50);`.
21
- ## 2.0.6
22
- * Add support for latest SDKs v10.3.0 with new callbacks.
23
- ## 2.0.5
24
- * Fallback to SDK key in Android Manifest and Info.plist if not passed programmatically.
25
- * Add support for setting banner width.
26
- ## 2.0.4
27
- * Pass `"countryCode"` in initialization callback.
28
- ## 2.0.3
29
- * Fix ad callbacks not returning.
30
- ## 2.0.2
31
- * Remove `getAdInfo(adUnitId)` API in lieu of ad callbacks.
32
- * Return more data in ad callbacks in addition to `ad.adUnitId` (e.g. `adInfo.creativeId`, `adInfo.networkName`, `adInfo.placement`, `adInfo.revenue`).
33
- ## 2.0.1
34
- * Ensure exported iOS methods are invoked on the main queue.
35
- ## 2.0.0
36
- * Initial support for MAX consent flow. Please see our documentation for instructions on enabling it.
37
- * Add `AppLovinMAX.setCreativeDebuggerEnabled()` API to enable the creative debugger button.
38
- * Revert from using the hardcoded SDK value of 10.1.1 to using +.
39
- * Fix MRec ad expanded event not working on Android.
40
- ## 1.1.10
41
- * Hardcode Android SDK version to 10.1.1.
42
- ## 1.1.9
43
- * Fix React Native version not being passed through to native SDKs.
44
- ## 1.1.8
45
- * Remove need to define Android product flavors in `build.gradle`.
46
- ## 1.1.7
47
- * Fix Android native UI banners rendering issues when mounting / unmounting.
48
- * Add support for setting test device(s) using the advertising identifier (GAID / IDFA) printed in the initialization logs.
49
- ## 1.1.6
50
- * Attempt fix for `loadInterstitial()` or `loadRewardedAd()` due to current Activity being null.
51
- ## 1.1.5
52
- * Fix `removeEventListener()` not working by explicitly calling `remove()`.
53
- ## 1.1.4
54
- * Fix Android banners not working for fast refreshes.
55
- * FIx iOS module's podspec pointing to invalid tag.
56
- ## 1.1.3
57
- * Ensure values such as user id is set before initializing SDK.
58
- * Add workaround for `getCurrentActivity()` returning `null`.
59
- ## 1.1.2
60
- * Fix `ConsentDialogState.UNKNOWN` being returned for `getConsentDialogState()` on iOS.
61
- ## 1.1.1
62
- * Fix `AppLovinMAX.removeEventListener()` crash.
63
- ## 1.1.0
64
- * Add support for native banner / MREC UI components via `<AppLovinMAX.AdView adUnitId={...} adFormat={...} />`.
65
- ## 1.0.0
66
- * Initial release with support for interstitials, rewarded ads, banners, and MRECs.
@@ -1,23 +0,0 @@
1
-
2
- *.iml
3
-
4
- *.apk
5
-
6
- *.hprof
7
-
8
-
9
- /local.properties
10
- .idea
11
- .gradle
12
-
13
- .DS_Store
14
-
15
- /build
16
- /captures
17
- /target
18
- /release
19
-
20
- .externalNativeBuild
21
- .DS_Store
22
-
23
- sdk_keys.local
package/ios/.DS_Store DELETED
Binary file
package/ios/.gitignore DELETED
@@ -1 +0,0 @@
1
- /Pods
@@ -1,24 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Bucket
3
- uuid = "3CE74096-E37E-4931-B9DE-06D2340266D0"
4
- type = "0"
5
- version = "2.0">
6
- <Breakpoints>
7
- <BreakpointProxy
8
- BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
9
- <BreakpointContent
10
- uuid = "4F7E6675-4074-44B2-A62C-1962AA9296C7"
11
- shouldBeEnabled = "Yes"
12
- ignoreCount = "0"
13
- continueAfterRunningActions = "No"
14
- filePath = "AppLovinMAXAdViewManager.m"
15
- startingColumnNumber = "9223372036854775807"
16
- endingColumnNumber = "9223372036854775807"
17
- startingLineNumber = "90"
18
- endingLineNumber = "90"
19
- landmarkName = "-attachAdViewIfNeededForAdUnitIdentifier:adFormat:"
20
- landmarkType = "7">
21
- </BreakpointContent>
22
- </BreakpointProxy>
23
- </Breakpoints>
24
- </Bucket>
package/src/.DS_Store DELETED
Binary file