UNPKG

nativescript-xz-ad-generation

Version:
78 lines (77 loc) 2.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var view_1 = require("tns-core-modules/ui/core/view"); var banner_base_1 = require("./banner-base"); var xz_ad_controller_1 = require("../../xz-ad-controller"); 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, "ios", { get: function () { return this._ios; }, enumerable: true, configurable: true }); Banner.prototype.createNativeView = function () { var uiview = UIView.alloc().init(); uiview.contentMode = 1; this._ios = uiview; return this._ios; }; Banner.prototype.onLoaded = function () { _super.prototype.onLoaded.call(this); this.updateAd(); }; Banner.prototype.disposeNativeView = function () { this._ios = 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; this._adScale = viewWidth / this._bannerWidth; this._viewHeight = this._bannerHeight * this._adScale; this._viewWidth = viewWidth; this.height = this._viewHeight; this._ios.frame = CGRectMake(0, 0, this._viewWidth, this._viewHeight); this._adController = new xz_ad_controller_1.XzAdController({ type: "banner", locationId: this._locationId, height: this._bannerHeight, width: this._bannerWidth }).initWithView(this._ios, this._viewHeight, this._viewWidth, this._adScale); if (this._adController) { this._adController.on("fail", this.onFail, this); } }; Banner.prototype.onFail = function (args) { this.width = 0; this.height = 0; }; Banner.prototype.updateAd = function () { if (this._adController) { this._adController.resumeAd(); return; } if (this._locationId && this._bannerHeight && this._bannerWidth) { this.loadAd(); } }; Banner.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) { var width = view_1.layout.getMeasureSpecSize(widthMeasureSpec); var height = view_1.layout.getMeasureSpecSize(heightMeasureSpec); this.setMeasuredDimension(width, height); }; return Banner; }(banner_base_1.BannerBase)); exports.Banner = Banner;