Skip to content

Commit

Permalink
bug/temp_fix_for_stop_autorefresh_autorefresh (#49)
Browse files Browse the repository at this point in the history
* bug/temp_fix_for_stop_autorefresh_autorefresh

* Update CHANGELOG.md
  • Loading branch information
thomasmso authored Dec 14, 2021
1 parent 063299e commit 5b6080f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Versions

## x.x.x
* Stop auto-refresh for native AdViews that have been removed from screen on Android.
## 2.5.0
* Update APIs for showing interstitials and rewarded ads. To show _without_ a placement, use `AppLovinMAX.showInterstitial(<Ad Unit ID>)` and `AppLovinMAX.showRewardedAd(<Ad Unit ID>)`. To show _with_ a placement, use `AppLovinMAX.showInterstitialWithPlacement(<Ad Unit ID>, <Placement>)` and `AppLovinMAX.showRewardedAdWithPlacement(<Ad Unit ID>, <Placement>)`.
## 2.4.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ public void onDropViewInstance(@NotNull AppLovinMAXAdView view)
// NOTE: Android destroys the native MaxAdView and calls this method while iOS caches it when you remove it from screen
adUnitIdRegistry.remove( view );

// HACK ALERT: Since current SDK does not respect auto-refresh APIs until _after_ `onAdLoaded()`, explicitly expose view validity to the main module
MaxAdView adView = view.getAdView();
if ( adView != null )
{
AppLovinMAXModule.sAdViewsToRemove.put( adView.getAdUnitId(), adView );
}

super.onDropViewInstance( view );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.facebook.react.bridge.WritableMap;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -98,6 +99,9 @@ public class AppLovinMAXModule
private final List<String> mAdUnitIdsToShowAfterCreate = new ArrayList<>( 2 );
private final Set<String> mDisabledAdaptiveBannerAdUnitIds = new HashSet<>( 2 );

// TODO: Remove when v11.0.0 SDKs are released
public final static Map<String, MaxAdView> sAdViewsToRemove = Collections.synchronizedMap( new HashMap<>() );

public static AppLovinMAXModule getInstance()
{
return instance;
Expand Down Expand Up @@ -660,6 +664,12 @@ public void onAdLoaded(MaxAd ad)
{
adView.stopAutoRefresh();
}

adView = sAdViewsToRemove.remove( ad.getAdUnitId() );
if ( adView != null )
{
adView.stopAutoRefresh();
}
}
else if ( MaxAdFormat.INTERSTITIAL == adFormat )
{
Expand Down Expand Up @@ -1503,8 +1513,8 @@ private void sendReactNativeEvent(final String name, @Nullable final WritableMap
.emit( name, params );
}

@Override
@Nullable public Map<String, Object> getConstants()
@Override @Nullable
public Map<String, Object> getConstants()
{
return super.getConstants();
}
Expand Down

0 comments on commit 5b6080f

Please sign in to comment.