@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.
94 lines (93 loc) • 4.44 kB
TypeScript
import { EventData, Property, View } from "tns-core-modules/ui/core/view";
export { File, knownFolders, path } from "tns-core-modules/file-system";
export * from "tns-core-modules/ui//core/view";
export declare const srcProperty: Property<WebViewExtBase, string>;
export declare const autoInjectJSBridgeProperty: Property<WebViewExtBase, boolean>;
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 {
url: string;
navigationType: NavigationType;
error: string;
}
export interface LoadStartedEventData extends LoadEventData {
eventName: 'loadStarted';
}
export interface LoadFinishedEventData extends LoadEventData {
eventName: 'loadFinished';
}
export interface WebViewEventData extends EventData {
data?: any;
}
export declare type NavigationType = "linkClicked" | "formSubmitted" | "backForward" | "reload" | "formResubmitted" | "other" | void;
export declare type urlOverrideHandlerFn = (url: String) => boolean;
export declare class WebViewExtBase extends View {
android: any;
ios: any;
readonly interceptScheme: string;
static readonly loadStartedEvent: 'loadStarted';
static readonly loadFinishedEvent: 'loadFinished';
isUIWebView: boolean;
isWKWebView: boolean;
src: string;
autoInjectJSBridge: boolean;
protected autoInjectScriptFiles: LoadJavaScriptResource[];
protected autoInjectStyleSheetFiles: LoadStyleSheetResource[];
protected autoInjectJavaScriptBlocks: InjectExecuteJavaScript[];
protected _tmpStopLoading: boolean;
_onLoadFinished(url: string, error?: string): Promise<LoadFinishedEventData>;
_onLoadStarted(url: string, navigationType: NavigationType): void;
_loadUrl(src: string): void;
_loadData(src: string): void;
stopLoading(): void;
readonly canGoBack: boolean;
readonly canGoForward: boolean;
goBack(): void;
goForward(): void;
reload(): void;
urlOverrideHandler: urlOverrideHandlerFn;
protected resolveLocalResourceFilePath(filepath: string): string | void;
registerLocalResource(name: string, filepath: string): void;
unregisterLocalResource(name: string): void;
getRegistretLocalResource(name: string): void;
loadUrl(src: string): Promise<LoadFinishedEventData>;
loadJavaScriptFile(scriptName: string, filepath?: string): Promise<any>;
loadJavaScriptFiles(files: LoadStyleSheetResource[]): Promise<any>;
loadStyleSheetFile(stylesheetName: string, filepath: string, insertBefore?: boolean): Promise<any>;
loadStyleSheetFiles(files: LoadStyleSheetResource[]): Promise<any>;
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;
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>;
protected generateLoadJavaScriptFileScriptCode(scriptHref: string): string;
protected generaateLoadCSSFileScriptCode(stylesheetHref: string, insertBefore?: boolean): string;
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;
protected fixLocalResourceName(resourceName: string): string;
}
export interface WebViewExtBase {
on(eventNames: string, callback: (data: WebViewEventData) => void, thisArg?: any): any;
on(event: "loadFinished", callback: (args: LoadFinishedEventData) => void, thisArg?: any): any;
on(event: "loadStarted", callback: (args: LoadStartedEventData) => void, thisArg?: any): any;
}