Skip to content

Commit 2efb9e6

Browse files
committed
fix(admob): NativeAdImage
feat: NativeAdImage image returns ImageSource
1 parent bc64aa9 commit 2efb9e6

File tree

7 files changed

+21
-10
lines changed

7 files changed

+21
-10
lines changed

packages/firebase-admob/nativead/index.android.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,18 +562,18 @@ export class MediaView extends MediaViewBase {
562562
}
563563

564564
export class NativeAdImage implements INativeAdImage {
565-
#native: com.google.android.gms.ads.formats.NativeAd.Image;
566-
static fromNative(image: com.google.android.gms.ads.formats.NativeAd.Image) {
567-
if (image instanceof com.google.android.gms.ads.formats.NativeAd.Image) {
565+
#native: com.google.android.gms.ads.nativead.NativeAd.Image;
566+
static fromNative(image: com.google.android.gms.ads.nativead.NativeAd.Image) {
567+
if (image instanceof com.google.android.gms.ads.nativead.NativeAd.Image) {
568568
const nativeAdImage = new NativeAdImage();
569569
nativeAdImage.#native = image;
570570
return nativeAdImage;
571571
}
572572
return null;
573573
}
574574

575-
get image(): any {
576-
return this.native?.getDrawable?.();
575+
get image() {
576+
return new ImageSource(org.nativescript.firebase.admob.FirebaseAdmob.getBitmap(this.native?.getDrawable?.() || null));
577577
}
578578

579579
get url(): string {

packages/firebase-admob/nativead/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export declare class MediaView extends MediaViewBase {
123123
}
124124

125125
export declare class NativeAdImage implements INativeAdImage {
126-
readonly image: any;
126+
readonly image: ImageSource;
127127

128128
readonly url: string;
129129

packages/firebase-admob/nativead/index.ios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ export class NativeAdImage implements INativeAdImage {
610610
return null;
611611
}
612612

613-
get image(): any {
614-
return this.native?.image;
613+
get image() {
614+
return new ImageSource(this.native?.image);
615615
}
616616

617617
get url(): string {
362 Bytes
Binary file not shown.

packages/firebase-admob/src-native/android/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/firebase-admob/src-native/android/admob/src/main/java/org/nativescript/firebase/admob/FirebaseAdmob.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ package org.nativescript.firebase.admob
22

33
import android.app.Activity
44
import android.content.Context
5+
import android.graphics.Bitmap
6+
import android.graphics.BitmapFactory
7+
import android.graphics.drawable.BitmapDrawable
8+
import android.graphics.drawable.Drawable
59
import android.location.Location
610
import android.os.Bundle
711
import android.os.Handler
812
import android.os.Looper
913
import android.util.Log
14+
import androidx.core.graphics.drawable.toBitmap
1015
import com.google.ads.mediation.admob.AdMobAdapter
1116
import com.google.android.gms.ads.*
1217
import com.google.android.gms.ads.admanager.AdManagerAdRequest
@@ -103,7 +108,7 @@ private const val AD_CLOSED_EVENT = "adClosed"
103108
private const val AD_FAILED_TO_LOAD_EVENT = "adFailedToLoad"
104109
private const val AD_LOADED_EVENT = "adLoaded"
105110
private const val AD_OPENED_EVENT = "adOpened"
106-
private const val AD_IMPRESSION_EVENT = "adImpression"
111+
private const val AD_IMPRESSION_EVENT = "adImpression"
107112
private const val AD_FAILED_TO_SHOW_FULL_SCREEN_CONTENT = " adFailedToShowFullScreenContent"
108113

109114

@@ -665,6 +670,11 @@ class FirebaseAdmob {
665670

666671
companion object {
667672

673+
@JvmStatic
674+
fun getBitmap(drawable: Drawable?): Bitmap? {
675+
return drawable?.toBitmap()
676+
}
677+
668678
@JvmStatic
669679
fun setRequestConfiguration(configuration: String) {
670680
try {

packages/firebase-admob/typings/org.nativescript.firebase.admob.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ declare module org {
2626
public static setRequestConfiguration(param0: string): void;
2727
public static getExecutorsCount(): number;
2828
public static setExecutorsCount(param0: number): void;
29+
public static getBitmap(param0: globalAndroid.graphics.drawable.Drawable): globalAndroid.graphics.Bitmap;
2930
}
3031
export module FirebaseAdmob {
3132
export class AdCallback {

0 commit comments

Comments
 (0)