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

Commit 674d0ae

Browse files
#706 AdMob on Android may fail in NativeScript 4 because frame.topmost() is undefined
1 parent e7ed8b6 commit 674d0ae

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
[Firebase Android SDK Changelog](https://firebase.google.com/support/release-notes/android)
55

66

7+
## 6.0.0 (2018, May 16)
8+
9+
### New
10+
- [#699](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/699) Add ML Kit support
11+
12+
### Fixes
13+
- [#706](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/706) AdMob on Android may fail in NativeScript 4 because frame.topmost() is undefined
14+
15+
716
## 5.3.1 (2018, April 26)
817

918
### Fixes

src/firebase.android.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,10 +641,14 @@ firebase.admob.showBanner = arg => {
641641
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT,
642642
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT);
643643

644-
// wrapping it in a timeout makes sure that when this function is loaded from
645-
// a Page.loaded event 'frame.topmost()' doesn't resolve to 'undefined'
644+
// 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'.
645+
// Also, in NativeScript 4+ it may be undefined anyway.. so using the appModule in that case.
646646
setTimeout(() => {
647-
frame.topmost().currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter);
647+
if (frame.topmost() !== undefined) {
648+
frame.topmost().currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter);
649+
} else {
650+
appModule.android.foregroundActivity.getWindow().getDecorView().addView(adViewLayout, relativeLayoutParamsOuter);
651+
}
648652
}, 0);
649653
} catch (ex) {
650654
console.log("Error in firebase.admob.showBanner: " + ex);
@@ -1670,7 +1674,6 @@ firebase.removeEventListeners = (listeners, path) => {
16701674
const ref = firebase.instance.child(path);
16711675
for (let i = 0; i < listeners.length; i++) {
16721676
const listener = listeners[i];
1673-
console.log("Removing listener at path " + path + ": " + listener);
16741677
ref.removeEventListener(listener);
16751678
}
16761679
resolve();

0 commit comments

Comments
 (0)