UNPKG

@nota/nativescript-webview-ext

Version:

Extended WebView for NativeScript which adds 'x-local' scheme for local-files. events between WebView and native-layer, javascript execution, injecting CSS and JS-files.

163 lines (162 loc) 7.58 kB
import { ContainerView, EventData, Property } from "tns-core-modules/ui/core/view"; export * from "tns-core-modules/ui//core/view"; export declare const androidSDK: number; export declare const useWKWebView: boolean; export declare const autoInjectJSBridgeProperty: Property<WebViewExtBase, boolean>; export declare const builtInZoomControlsProperty: Property<WebViewExtBase, boolean>; export declare const cacheModeProperty: Property<WebViewExtBase, string>; export declare const databaseStorageProperty: Property<WebViewExtBase, boolean>; export declare const domStorageProperty: Property<WebViewExtBase, boolean>; export declare const debugModeProperty: Property<WebViewExtBase, boolean>; export declare const displayZoomControlsProperty: Property<WebViewExtBase, boolean>; export declare const supportZoomProperty: Property<WebViewExtBase, boolean>; export declare const srcProperty: Property<WebViewExtBase, string>; export declare const scrollBounceProperty: Property<WebViewExtBase, boolean>; export declare enum EventNames { LoadFinished = "loadFinished", LoadStarted = "loadStarted", ShouldOverrideUrlLoading = "shouldOverideUrlLoading" } export interface LoadJavaScriptResource { resourceName: string; filepath: string; } export interface LoadStyleSheetResource { resourceName: string; filepath: string; insertBefore?: boolean; } export interface InjectExecuteJavaScript { scriptCode: string; name: string; } export interface LoadEventData extends EventData { object: WebViewExtBase; url: string; navigationType?: NavigationType; error?: string; } export interface LoadStartedEventData extends LoadEventData { eventName: EventNames.LoadStarted; } export interface LoadFinishedEventData extends LoadEventData { eventName: EventNames.LoadFinished; } export interface ShouldOverideUrlLoadEventData extends LoadEventData { eventName: EventNames.ShouldOverrideUrlLoading; httpMethod: string; cancel?: boolean; } export interface WebViewEventData extends EventData { data?: any; } export declare type NavigationType = "linkClicked" | "formSubmitted" | "backForward" | "reload" | "formResubmitted" | "other" | void; export declare class UnsupportSDKError extends Error { constructor(minSdk: number); } export declare class WebViewExtBase extends ContainerView { static isFetchSupported: boolean; static isPromiseSupported: boolean; android: any; ios: any; readonly interceptScheme: string; static readonly loadStartedEvent: EventNames; static readonly loadFinishedEvent: EventNames; static readonly shouldOverrideUrlLoadingEvent: EventNames; readonly isUIWebView: boolean; readonly isWKWebView: boolean; src: string; autoInjectJSBridge: boolean; debugMode: boolean; builtInZoomControls: boolean; displayZoomControls: boolean; databaseStorage: boolean; domStorage: boolean; supportZoom: boolean; scrollBounce: boolean; cacheMode: "default" | "no_cache" | "cache_first" | "cache_only"; protected autoInjectScriptFiles: LoadJavaScriptResource[]; protected autoInjectStyleSheetFiles: LoadStyleSheetResource[]; protected autoInjectJavaScriptBlocks: InjectExecuteJavaScript[]; protected tempSuspendSrcLoading: boolean; _onLoadFinished(url: string, error?: string): Promise<LoadFinishedEventData>; _onLoadStarted(url: string, navigationType?: NavigationType): void; _onShouldOverrideUrlLoading(url: string, httpMethod: string, navigationType?: NavigationType): boolean; _loadUrl(src: string): void; _loadData(src: string): void; stopLoading(): void; readonly canGoBack: boolean; readonly canGoForward: boolean; goBack(): void; goForward(): void; reload(): void; resolveLocalResourceFilePath(filepath: string): string | void; registerLocalResource(name: string, filepath: string): void; unregisterLocalResource(name: string): void; getRegisteredLocalResource(name: string): string; loadUrl(src: string): Promise<LoadFinishedEventData>; loadJavaScriptFile(scriptName: string, filepath?: string): Promise<void>; loadJavaScriptFiles(files: LoadStyleSheetResource[]): Promise<void>; loadStyleSheetFile(stylesheetName: string, filepath: string, insertBefore?: boolean): Promise<void>; loadStyleSheetFiles(files: LoadStyleSheetResource[]): Promise<void>; autoLoadJavaScriptFile(resourceName: string, filepath: string): void; removeAutoLoadJavaScriptFile(resourceName: string): void; autoLoadStyleSheetFile(resourceName: string, filepath: string, insertBefore?: boolean): void; removeAutoLoadStyleSheetFile(resourceName: string): void; autoExecuteJavaScript(scriptCode: string, name: string): void; removeAutoExecuteJavaScript(name: string): void; protected ensureFetchSupport(): Promise<void>; protected loadFetchPolyfill(): Promise<void>; protected ensurePromiseSupport(): Promise<void>; protected loadPromisePolyfill(): Promise<void>; protected ensurePolyfills(): Promise<void>; executeJavaScript<T>(scriptCode: string, stringifyResult?: boolean): Promise<T>; executePromise<T>(scriptCode: string, timeout?: number): Promise<T>; executePromises<T>(scriptCodes: string[], timeout?: number): Promise<T | void>; generateLoadJavaScriptFileScriptCode(scriptHref: string): string; generaateLoadCSSFileScriptCode(stylesheetHref: string, insertBefore?: boolean): string; protected injectWebViewBridge(): Promise<void>; protected parseWebViewJavascriptResult(result: any): any; writeTrace(message: string, type?: number): void; emitToWebView(eventName: string, data: any): void; onWebViewEvent(eventName: string, data: any): void; getTitle(): Promise<string>; onUIWebViewEvent(url: string): void; zoomIn(): boolean; zoomOut(): boolean; zoomBy(zoomFactor: number): void; fixLocalResourceName(resourceName: string): string; } export interface WebViewExtBase { on(eventNames: string, callback: (data: WebViewEventData) => void, thisArg?: any): any; on(event: EventNames.ShouldOverrideUrlLoading, callback: (args: ShouldOverideUrlLoadEventData) => void, thisArg?: any): any; on(event: EventNames.LoadStarted, callback: (args: LoadStartedEventData) => void, thisArg?: any): any; on(event: EventNames.LoadFinished, callback: (args: LoadFinishedEventData) => void, thisArg?: any): any; } export interface IOSWebViewWrapper { owner: WeakRef<WebViewExtBase>; createNativeView(): any; initNativeView(): void; disposeNativeView(): void; onLoaded(): void; onUnloaded(): void; executeJavaScript(scriptCode: string): Promise<any>; registerLocalResourceForNative(resourceName: string, filepath: string): void; unregisterLocalResourceForNative(resourceName: string): void; getRegisteredLocalResourceFromNative(resourceName: string): string; autoLoadStyleSheetFile(resourceName: string, filepath: string, insertBefore?: boolean): void; removeAutoLoadStyleSheetFile(resourceName: string): void; autoLoadJavaScriptFile(resourceName: string, filepath: string): Promise<void>; removeAutoLoadJavaScriptFile(resourceName: string): void; stopLoading(): void; loadUrl(url: string): void; loadData(content: string): void; readonly canGoBack: boolean; readonly canGoForward: boolean; goBack(): void; goForward(): void; reload(): void; readonly shouldInjectWebViewBridge: boolean; enableAutoInject(enable: boolean): void; scrollBounce: boolean; }