Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Fix #1683 NS7+Ng10 Admob Smartbanner error: Invalid ad width or height: (0, 0) on v11.0.0 #1687

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
23 changes: 16 additions & 7 deletions src/admob/admob.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export function showBanner(arg: BannerOptions): Promise<any> {
firebase.admob.adView.loadAd(ad);

const density = Utils.layout.getDisplayDensity(),
top = settings.margins.top * density,
bottom = settings.margins.bottom * density;
top = settings.margins.top * density,
bottom = settings.margins.bottom * density;

const relativeLayoutParams = new android.widget.RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT,
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);

if (bottom > -1) {
relativeLayoutParams.bottomMargin = bottom;
Expand All @@ -73,8 +73,8 @@ export function showBanner(arg: BannerOptions): Promise<any> {
adViewLayout.addView(firebase.admob.adView, relativeLayoutParams);

const relativeLayoutParamsOuter = new android.widget.RelativeLayout.LayoutParams(
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT,
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT);
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT,
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT);

// Wrapping it in a timeout makes sure that when this function is loaded from a Page.loaded event 'frame.Frame.topmost()' doesn't resolve to 'undefined'.
// Also, in NativeScript 4+ it may be undefined anyway.. so using the appModule in that case.
Expand Down Expand Up @@ -192,7 +192,16 @@ export function preloadRewardedVideoAd(arg: PreloadRewardedVideoAdOptions): Prom
const settings = firebase.merge(arg, BANNER_DEFAULTS);
const activity = Application.android.foregroundActivity || Application.android.startActivity;
firebase.admob.rewardedAdVideoView = com.google.android.gms.ads.MobileAds.getRewardedVideoAdInstance(activity);


if (firebase.admob.rewardedAdVideoView) {
//https://developers.google.com/admob/android/ssv#ssv_callback_parameters
if (settings.userId) {
firebase.admob.rewardedAdVideoView.setUserId(settings.userId);
}
if (settings.customData) {
firebase.admob.rewardedAdVideoView.setCustomData(settings.customData);
}
}
rewardedVideoCallbacks.onLoaded = resolve;
rewardedVideoCallbacks.onFailedToLoad = reject;

Expand Down
8 changes: 8 additions & 0 deletions src/admob/admob.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ export interface InterstitialOptions extends AdLifeCycleEvents {
}

export interface PreloadRewardedVideoAdOptions {
/**
* for user_id of https://developers.google.com/admob/ios/ssv#ssv_callback_parameters or https://developers.google.com/admob/android/ssv#ssv_callback_parameters
*/
userId?:string;
/**
* for custom_data of https://developers.google.com/admob/ios/ssv#ssv_callback_parameters or https://developers.google.com/admob/android/ssv#ssv_callback_parameters
*/
customData?:string;
/**
* When true you'll use googles testing iosAdPlacementId and androidAdPlacementId.
*/
Expand Down
25 changes: 22 additions & 3 deletions src/admob/admob.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ export function showBanner(arg: BannerOptions): Promise<any> {

const originX = (view.frame.size.width - adWidth) / 2;
const originY = settings.margins.top > -1 ? settings.margins.top : (settings.margins.bottom > -1 ? view.frame.size.height - adHeight - settings.margins.bottom : 0.0);
const origin = CGPointMake(originX, originY);
firebase.admob.adView = GADBannerView.alloc().initWithAdSizeOrigin(bannerType, origin);

//Fix for the smart banner size on NS7.0+, due to issue with initWithAdSizeOrigin response "Invalid ad width or height: (0, 0)"
if (settings.size === AD_SIZE.SMART_BANNER) {
const adFrameRec = CGRectMake(originX, originY, adWidth, Math.max(adHeight, 50)); // minimum height should be 50 for a ad banner
firebase.admob.adView = GADBannerView.alloc().initWithFrame(adFrameRec)
} else {
const origin = CGPointMake(originX, originY);
firebase.admob.adView = GADBannerView.alloc().initWithAdSizeOrigin(bannerType, origin);
}
firebase.admob.adView.adUnitID = settings.iosBannerId;

const adRequest = GADRequest.request();
Expand Down Expand Up @@ -218,10 +224,23 @@ export function preloadRewardedVideoAd(arg: PreloadRewardedVideoAdOptions): Prom

firebase.admob.rewardedAdVideoView = GADRewardBasedVideoAd.sharedInstance();
firebase.admob.rewardedAdVideoView.delegate = _rewardBasedVideoAdDelegate;


const settings = firebase.merge(arg, BANNER_DEFAULTS);
const adRequest = GADRequest.request();


if (firebase.admob.rewardedAdVideoView) {
//https://developers.google.com/admob/ios/ssv#ssv_callback_parameters
if (settings.userId) {
firebase.admob.rewardedAdVideoView.userIdentifier = settings.userId;
}
if (settings.customData) {
firebase.admob.rewardedAdVideoView.customRewardString = settings.customData;
}
}

const adRequest = GADRequest.request();

if (settings.testing) {
let testDevices: any = [];
try {
Expand Down
Empty file modified src/firebase.ios.ts
100755 → 100644
Empty file.