Skip to content

Commit

Permalink
feat(android): potentially improves mediation performance for banners (
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed Feb 19, 2024
1 parent 8353cbc commit 32f550a
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,18 @@ private BaseAdView initAdView(ReactNativeAdView reactViewGroup) {
oldAdView.destroy();
reactViewGroup.removeView(oldAdView);
}
BaseAdView adView;
if (ReactNativeGoogleMobileAdsCommon.isAdManagerUnit(reactViewGroup.getUnitId())) {
Activity currentActivity = ((ReactContext) reactViewGroup.getContext()).getCurrentActivity();
if (currentActivity != null) {
// in order to display the debug menu for GAM ads we need the activity context
// https://github.com/invertase/react-native-google-mobile-ads/issues/188
adView = new AdManagerAdView(currentActivity);
} else {
return null;
}
} else {
adView = new AdView(reactViewGroup.getContext());
}

// For optimal mediation performance ad objects should be initialized with
// activity, rather than just context:
// https://developers.google.com/admob/android/mediation#initialize_your_ad_object_with_an_activity_instance
Activity currentActivity = ((ReactContext) reactViewGroup.getContext()).getCurrentActivity();
if (currentActivity == null) return null;

BaseAdView adView =
ReactNativeGoogleMobileAdsCommon.isAdManagerUnit(reactViewGroup.getUnitId())
? new AdManagerAdView(currentActivity)
: new AdView(currentActivity);

adView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
adView.setOnPaidEventListener(
new OnPaidEventListener() {
Expand Down

0 comments on commit 32f550a

Please sign in to comment.