mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
WebView NavigationType converted to type
This commit is contained in:
@ -144,24 +144,6 @@ export class WebViewTest extends testModule.UITest<webViewModule.WebView> {
|
||||
|
||||
webView.src = targetSrc;
|
||||
}
|
||||
|
||||
public testLoadStartedNavigationTypeExists(done) {
|
||||
let webView = this.testView;
|
||||
let targetSrc = "https://github.com/";
|
||||
|
||||
webView.on(webViewModule.WebView.loadStartedEvent, function (args: webViewModule.LoadEventData) {
|
||||
try {
|
||||
TKUnit.assertNull(args.error, args.error);
|
||||
TKUnit.assertTrue(webViewModule.WebView.navigationTypes.indexOf(args.navigationType) > -1, "navigationTypeExists");
|
||||
done(null);
|
||||
}
|
||||
catch (e) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
|
||||
webView.src = targetSrc;
|
||||
}
|
||||
}
|
||||
|
||||
export function createTestCase(): WebViewTest {
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { WebView as WebViewDefinition, LoadEventData } from ".";
|
||||
import { WebView as WebViewDefinition, LoadEventData, NavigationType } from ".";
|
||||
import { View, Property } from "../core/view";
|
||||
import { isFileOrResourcePath } from "../../utils/utils";
|
||||
import { File, knownFolders, path } from "../../file-system";
|
||||
|
||||
export { File, knownFolders, path };
|
||||
export { File, knownFolders, path, NavigationType };
|
||||
export * from "../core/view";
|
||||
|
||||
export const srcProperty = new Property<WebViewBase, string>({ name: "src" });
|
||||
@ -12,15 +12,6 @@ export abstract class WebViewBase extends View implements WebViewDefinition {
|
||||
public static loadStartedEvent = "loadStarted";
|
||||
public static loadFinishedEvent = "loadFinished";
|
||||
|
||||
public static navigationTypes = [
|
||||
"linkClicked",
|
||||
"formSubmitted",
|
||||
"backForward",
|
||||
"reload",
|
||||
"formResubmitted",
|
||||
"other"
|
||||
];
|
||||
|
||||
public src: string;
|
||||
|
||||
public _onLoadFinished(url: string, error?: string) {
|
||||
@ -35,7 +26,7 @@ export abstract class WebViewBase extends View implements WebViewDefinition {
|
||||
this.notify(args);
|
||||
}
|
||||
|
||||
public _onLoadStarted(url: string, navigationType: string) {
|
||||
public _onLoadStarted(url: string, navigationType: NavigationType) {
|
||||
let args = <LoadEventData>{
|
||||
eventName: WebViewBase.loadStartedEvent,
|
||||
object: this,
|
||||
|
@ -34,7 +34,7 @@ function initializeWebViewClient(): void {
|
||||
if (traceEnabled()) {
|
||||
traceWrite("WebViewClientClass.onPageStarted(" + url + ", " + favicon + ")", traceCategories.Debug);
|
||||
}
|
||||
owner._onLoadStarted(url, WebViewBase.navigationTypes[WebViewBase.navigationTypes.indexOf("linkClicked")]);
|
||||
owner._onLoadStarted(url, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
|
12
tns-core-modules/ui/web-view/web-view.d.ts
vendored
12
tns-core-modules/ui/web-view/web-view.d.ts
vendored
@ -8,6 +8,11 @@ import { View, Property, EventData } from "../core/view";
|
||||
*/
|
||||
export const urlProperty: Property<WebView, string>;
|
||||
|
||||
/**
|
||||
* Represents navigation type
|
||||
*/
|
||||
export type NavigationType = "linkClicked" | "formSubmitted" | "backForward" | "reload" | "formResubmitted" | "other" | undefined;
|
||||
|
||||
/**
|
||||
* Represents a standard WebView widget.
|
||||
*/
|
||||
@ -22,11 +27,6 @@ export class WebView extends View {
|
||||
*/
|
||||
public static loadFinishedEvent: string;
|
||||
|
||||
/**
|
||||
* Array of string values used when passing navigation types.
|
||||
*/
|
||||
public static navigationTypes: string[];
|
||||
|
||||
/**
|
||||
* Gets the native [android widget](http://developer.android.com/reference/android/webkit/WebView.html) that represents the user interface for this component. Valid only when running on Android OS.
|
||||
*/
|
||||
@ -102,7 +102,7 @@ export interface LoadEventData extends EventData {
|
||||
/**
|
||||
* Gets the navigation type of the web-view.
|
||||
*/
|
||||
navigationType: string;
|
||||
navigationType: NavigationType;
|
||||
/**
|
||||
* Gets the error (if any).
|
||||
*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { WebViewBase, knownFolders, traceWrite, traceEnabled, traceCategories } from "./web-view-common";
|
||||
import { WebViewBase, knownFolders, traceWrite, traceEnabled, traceCategories, NavigationType } from "./web-view-common";
|
||||
|
||||
export * from "./web-view-common";
|
||||
|
||||
@ -17,30 +17,30 @@ class UIWebViewDelegateImpl extends NSObject implements UIWebViewDelegate {
|
||||
let owner = this._owner.get();
|
||||
|
||||
if (owner && request.URL) {
|
||||
let navTypeIndex = WebViewBase.navigationTypes.indexOf("other");
|
||||
let navType: NavigationType = "other";
|
||||
|
||||
switch (navigationType) {
|
||||
case UIWebViewNavigationType.LinkClicked:
|
||||
navTypeIndex = WebViewBase.navigationTypes.indexOf("linkClicked");
|
||||
navType = "linkClicked";
|
||||
break;
|
||||
case UIWebViewNavigationType.FormSubmitted:
|
||||
navTypeIndex = WebViewBase.navigationTypes.indexOf("formSubmitted");
|
||||
navType = "formSubmitted";
|
||||
break;
|
||||
case UIWebViewNavigationType.BackForward:
|
||||
navTypeIndex = WebViewBase.navigationTypes.indexOf("backForward");
|
||||
navType = "backForward";
|
||||
break;
|
||||
case UIWebViewNavigationType.Reload:
|
||||
navTypeIndex = WebViewBase.navigationTypes.indexOf("reload");
|
||||
navType = "reload";
|
||||
break;
|
||||
case UIWebViewNavigationType.FormResubmitted:
|
||||
navTypeIndex = WebViewBase.navigationTypes.indexOf("formResubmitted");
|
||||
navType = "formResubmitted";
|
||||
break;
|
||||
}
|
||||
|
||||
if (traceEnabled()) {
|
||||
traceWrite("UIWebViewDelegateClass.webViewShouldStartLoadWithRequestNavigationType(" + request.URL.absoluteString + ", " + navigationType + ")", traceCategories.Debug);
|
||||
}
|
||||
owner._onLoadStarted(request.URL.absoluteString, WebViewBase.navigationTypes[navTypeIndex]);
|
||||
owner._onLoadStarted(request.URL.absoluteString, navType);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user