Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): potentially improves mediation performance for banners #527

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading