nativescript-xz-ad-generation
Version:
NativeScript AdGeneration Plugin
64 lines (63 loc) • 2.21 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var xz_ad_controller_1 = require("../../xz-ad-controller");
var banner_base_1 = require("./banner-base");
var platform_1 = require("tns-core-modules/platform");
var mainScreen = platform_1.screen.mainScreen;
var Banner = (function (_super) {
__extends(Banner, _super);
function Banner() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(Banner.prototype, "android", {
get: function () {
return this._adg;
},
enumerable: true,
configurable: true
});
Banner.prototype.createNativeView = function () {
this._adg = new com.socdm.d.adgeneration.ADG(this._context);
return this._adg;
};
Banner.prototype.disposeNativeView = function () {
this._adg = null;
if (this._adController) {
this._adController.off("fail", this.onFail, this);
this._adController.dispose();
}
};
Banner.prototype.loadAd = function () {
if (!this.width || this.width.toString() === "auto") {
this.width = mainScreen.widthDIPs;
}
var viewWidth = +this.width;
var adScale = viewWidth / this._bannerWidth;
var viewHeight = this._bannerHeight * adScale;
this.height = viewHeight;
this._adController = new xz_ad_controller_1.XzAdController({
type: "banner",
locationId: this._locationId,
height: this._bannerHeight,
width: this._bannerWidth
}).initWithView(this._adg, viewHeight, viewWidth, adScale);
if (this._adController) {
this._adController.on("fail", this.onFail, this);
}
this._initialized = true;
};
Banner.prototype.onFail = function () {
this.width = 0;
this.height = 0;
};
Banner.prototype.updateAd = function () {
if (this._initialized) {
return;
}
if (this._locationId && this._bannerHeight && this._bannerWidth) {
this.loadAd();
}
};
return Banner;
}(banner_base_1.BannerBase));
exports.Banner = Banner;