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

Commit

Permalink
#706 AdMob on Android may fail in NativeScript 4 because frame.topmos…
Browse files Browse the repository at this point in the history
…t() is undefined
  • Loading branch information
EddyVerbruggen committed May 16, 2018
1 parent e7ed8b6 commit 674d0ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
[Firebase Android SDK Changelog](https://firebase.google.com/support/release-notes/android)


## 6.0.0 (2018, May 16)

### New
- [#699](https:/EddyVerbruggen/nativescript-plugin-firebase/issues/699) Add ML Kit support

### Fixes
- [#706](https:/EddyVerbruggen/nativescript-plugin-firebase/issues/706) AdMob on Android may fail in NativeScript 4 because frame.topmost() is undefined


## 5.3.1 (2018, April 26)

### Fixes
Expand Down
11 changes: 7 additions & 4 deletions src/firebase.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,14 @@ firebase.admob.showBanner = arg => {
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.topmost()' doesn't resolve to 'undefined'
// 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'.
// Also, in NativeScript 4+ it may be undefined anyway.. so using the appModule in that case.
setTimeout(() => {
frame.topmost().currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter);
if (frame.topmost() !== undefined) {
frame.topmost().currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter);
} else {
appModule.android.foregroundActivity.getWindow().getDecorView().addView(adViewLayout, relativeLayoutParamsOuter);
}
}, 0);
} catch (ex) {
console.log("Error in firebase.admob.showBanner: " + ex);
Expand Down Expand Up @@ -1670,7 +1674,6 @@ firebase.removeEventListeners = (listeners, path) => {
const ref = firebase.instance.child(path);
for (let i = 0; i < listeners.length; i++) {
const listener = listeners[i];
console.log("Removing listener at path " + path + ": " + listener);
ref.removeEventListener(listener);
}
resolve();
Expand Down

0 comments on commit 674d0ae

Please sign in to comment.