UNPKG

@finanzritter/nativescript-pdf-view

Version:

A basic PDF viewer plugin for NativeScript, to display PDF documents on iOS and Android.

70 lines 2.08 kB
import { PDFViewCommon, srcProperty } from './pdf-view.common'; var PDFViewDelegate = /** @class */ (function (_super) { __extends(PDFViewDelegate, _super); function PDFViewDelegate() { return _super !== null && _super.apply(this, arguments) || this; } PDFViewDelegate.initWithOwner = function (owner) { var delegate = PDFViewDelegate.new(); delegate.owner = owner; return delegate; }; PDFViewDelegate.prototype.webViewDidFinishNavigation = function (webView) { PDFViewCommon.notifyOfEvent(PDFViewCommon.loadEvent, this.owner); }; PDFViewDelegate.ObjCProtocols = [WKNavigationDelegate]; return PDFViewDelegate; }(NSObject)); export class PDFView extends PDFViewCommon { constructor() { super(); this.init(); } get ios() { return this.nativeView; } set ios(value) { this.nativeView = value; } [srcProperty.setNative](value) { this.loadPDF(value); } onLoaded() { super.onLoaded(); this.ios.navigationDelegate = this.delegate; } onUnloaded() { this.ios.navigationDelegate = void 0; super.onUnloaded(); } loadPDF(src) { if (!src) { return; } let url; if (src.indexOf('://') === -1) { url = NSURL.fileURLWithPath(src); this.ios.loadFileURLAllowingReadAccessToURL(url, url); } else { url = NSURL.URLWithString(src); const urlRequest = NSURLRequest.requestWithURL(url); this.ios.loadRequest(urlRequest); } } init() { this.delegate = PDFViewDelegate.initWithOwner(new WeakRef(this)); this.ios = new WKWebView({ configuration: WKWebViewConfiguration.new(), frame: this.mainScreen.bounds, }); this.ios.opaque = false; this.ios.autoresizingMask = 2 | 16; } get mainScreen() { return UIScreen.mainScreen; } } //# sourceMappingURL=pdf-view.ios.js.map