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

Commit 9dab2b9

Browse files
AdMob: Cannot read property of addView #1120
1 parent 0493235 commit 9dab2b9

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/admob/admob.android.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,15 @@ export function showBanner(arg: BannerOptions): Promise<any> {
7474
// Wrapping it in a timeout makes sure that when this function is loaded from a Page.loaded event 'frame.topmost()' doesn't resolve to 'undefined'.
7575
// Also, in NativeScript 4+ it may be undefined anyway.. so using the appModule in that case.
7676
setTimeout(() => {
77-
if (topmost() !== undefined) {
78-
topmost().currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter);
79-
} else {
77+
const top = topmost();
78+
if (top !== undefined && top.currentPage && top.currentPage.android && top.currentPage.android.getParent()) {
79+
top.currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter);
80+
} else if (appModule.android && appModule.android.foregroundActivity) {
8081
appModule.android.foregroundActivity.getWindow().getDecorView().addView(adViewLayout, relativeLayoutParamsOuter);
82+
} else {
83+
console.log("Could not find a view to add the banner to");
8184
}
82-
}, 0);
85+
}, 100);
8386
} catch (ex) {
8487
console.log("Error in firebase.admob.showBanner: " + ex);
8588
reject(ex);

0 commit comments

Comments
 (0)