Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending a view property will place ad in that view #41

Open
wants to merge 15 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
10 changes: 0 additions & 10 deletions .gitignore

This file was deleted.

19 changes: 0 additions & 19 deletions LICENSE

This file was deleted.

197 changes: 0 additions & 197 deletions README.md

This file was deleted.

File renamed without changes.
File renamed without changes.
29 changes: 17 additions & 12 deletions src/admob.android.js → admob.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ admob.createBanner = function (arg) {
if (admob.adView !== null && admob.adView !== undefined) {
var parent = admob.adView.getParent();
if (parent !== null) {
parent.removeView(admob.adView);
// Uncommenting this so multiple ads can be shown on the same page.
// parent.removeView(admob.adView);
}
}
var settings = admob.merge(arg, admob.defaults);
Expand Down Expand Up @@ -138,18 +139,22 @@ admob.createBanner = function (arg) {
// 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(function () {
var topmost = frame.topmost();
if (topmost !== undefined) {
topmost.currentPage &&
topmost.currentPage.android &&
topmost.currentPage.android.getParent() &&
topmost.currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter);
if (arg.view !== null && arg.view !== undefined) {
arg.view.addView(adViewLayout, relativeLayoutParamsOuter);
} else {
application.android &&
application.android.foregroundActivity &&
application.android.foregroundActivity.getWindow() &&
application.android.foregroundActivity.getWindow().getDecorView() &&
application.android.foregroundActivity.getWindow().getDecorView().addView(adViewLayout, relativeLayoutParamsOuter);
var topmost = frame.topmost();
if (topmost !== undefined) {
topmost.currentPage &&
topmost.currentPage.android &&
topmost.currentPage.android.getParent() &&
topmost.currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter);
} else {
application.android &&
application.android.foregroundActivity &&
application.android.foregroundActivity.getWindow() &&
application.android.foregroundActivity.getWindow().getDecorView() &&
application.android.foregroundActivity.getWindow().getDecorView().addView(adViewLayout, relativeLayoutParamsOuter);
}
}
}, 0);

Expand Down
15 changes: 10 additions & 5 deletions src/admob.ios.js → admob.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@ admob._getBannerType = function (size) {
admob.createBanner = function (arg) {
return new Promise(function (resolve, reject) {
try {
if (admob.adView !== null && admob.adView !== undefined) {
admob.adView.removeFromSuperview();
admob.adView = null;
// With this removed we can add multiple ads to the app.
// if (admob.adView !== null && admob.adView !== undefined) {
// admob.adView.removeFromSuperview();
// admob.adView = null;
// }

// If args doesn't have a view we add the advertisement to the view of the root ViewController.
if (arg.view === null || arg.view === undefined) {
admob.defaults.view = utils.ios.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController.view;
}

admob.defaults.view = utils.ios.getter(UIApplication, UIApplication.sharedApplication).keyWindow.rootViewController.view;

var settings = admob.merge(arg, admob.defaults);
var view = settings.view;
var bannerType = admob._getBannerType(settings.size);
Expand Down
9 changes: 0 additions & 9 deletions demo/app/App_Resources/Android/app.gradle

This file was deleted.

45 changes: 0 additions & 45 deletions demo/app/App_Resources/Android/src/main/AndroidManifest.xml

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

23 changes: 0 additions & 23 deletions demo/app/App_Resources/Android/src/main/res/values-v21/styles.xml

This file was deleted.

Loading