WebView NavigationType converted to type

This commit is contained in:
vakrilov
2017-04-04 17:31:56 +03:00
parent 59e34f0bfc
commit d427c9ed8f
5 changed files with 18 additions and 45 deletions

View File

@ -144,24 +144,6 @@ export class WebViewTest extends testModule.UITest<webViewModule.WebView> {
webView.src = targetSrc; 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 { export function createTestCase(): WebViewTest {

View File

@ -1,9 +1,9 @@
import { WebView as WebViewDefinition, LoadEventData } from "."; import { WebView as WebViewDefinition, LoadEventData, NavigationType } from ".";
import { View, Property } from "../core/view"; import { View, Property } from "../core/view";
import { isFileOrResourcePath } from "../../utils/utils"; import { isFileOrResourcePath } from "../../utils/utils";
import { File, knownFolders, path } from "../../file-system"; import { File, knownFolders, path } from "../../file-system";
export { File, knownFolders, path }; export { File, knownFolders, path, NavigationType };
export * from "../core/view"; export * from "../core/view";
export const srcProperty = new Property<WebViewBase, string>({ name: "src" }); 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 loadStartedEvent = "loadStarted";
public static loadFinishedEvent = "loadFinished"; public static loadFinishedEvent = "loadFinished";
public static navigationTypes = [
"linkClicked",
"formSubmitted",
"backForward",
"reload",
"formResubmitted",
"other"
];
public src: string; public src: string;
public _onLoadFinished(url: string, error?: string) { public _onLoadFinished(url: string, error?: string) {
@ -35,7 +26,7 @@ export abstract class WebViewBase extends View implements WebViewDefinition {
this.notify(args); this.notify(args);
} }
public _onLoadStarted(url: string, navigationType: string) { public _onLoadStarted(url: string, navigationType: NavigationType) {
let args = <LoadEventData>{ let args = <LoadEventData>{
eventName: WebViewBase.loadStartedEvent, eventName: WebViewBase.loadStartedEvent,
object: this, object: this,

View File

@ -34,7 +34,7 @@ function initializeWebViewClient(): void {
if (traceEnabled()) { if (traceEnabled()) {
traceWrite("WebViewClientClass.onPageStarted(" + url + ", " + favicon + ")", traceCategories.Debug); traceWrite("WebViewClientClass.onPageStarted(" + url + ", " + favicon + ")", traceCategories.Debug);
} }
owner._onLoadStarted(url, WebViewBase.navigationTypes[WebViewBase.navigationTypes.indexOf("linkClicked")]); owner._onLoadStarted(url, undefined);
} }
} }

View File

@ -8,6 +8,11 @@ import { View, Property, EventData } from "../core/view";
*/ */
export const urlProperty: Property<WebView, string>; export const urlProperty: Property<WebView, string>;
/**
* Represents navigation type
*/
export type NavigationType = "linkClicked" | "formSubmitted" | "backForward" | "reload" | "formResubmitted" | "other" | undefined;
/** /**
* Represents a standard WebView widget. * Represents a standard WebView widget.
*/ */
@ -22,11 +27,6 @@ export class WebView extends View {
*/ */
public static loadFinishedEvent: string; 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. * 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. * Gets the navigation type of the web-view.
*/ */
navigationType: string; navigationType: NavigationType;
/** /**
* Gets the error (if any). * Gets the error (if any).
*/ */

View File

@ -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"; export * from "./web-view-common";
@ -17,30 +17,30 @@ class UIWebViewDelegateImpl extends NSObject implements UIWebViewDelegate {
let owner = this._owner.get(); let owner = this._owner.get();
if (owner && request.URL) { if (owner && request.URL) {
let navTypeIndex = WebViewBase.navigationTypes.indexOf("other"); let navType: NavigationType = "other";
switch (navigationType) { switch (navigationType) {
case UIWebViewNavigationType.LinkClicked: case UIWebViewNavigationType.LinkClicked:
navTypeIndex = WebViewBase.navigationTypes.indexOf("linkClicked"); navType = "linkClicked";
break; break;
case UIWebViewNavigationType.FormSubmitted: case UIWebViewNavigationType.FormSubmitted:
navTypeIndex = WebViewBase.navigationTypes.indexOf("formSubmitted"); navType = "formSubmitted";
break; break;
case UIWebViewNavigationType.BackForward: case UIWebViewNavigationType.BackForward:
navTypeIndex = WebViewBase.navigationTypes.indexOf("backForward"); navType = "backForward";
break; break;
case UIWebViewNavigationType.Reload: case UIWebViewNavigationType.Reload:
navTypeIndex = WebViewBase.navigationTypes.indexOf("reload"); navType = "reload";
break; break;
case UIWebViewNavigationType.FormResubmitted: case UIWebViewNavigationType.FormResubmitted:
navTypeIndex = WebViewBase.navigationTypes.indexOf("formResubmitted"); navType = "formResubmitted";
break; break;
} }
if (traceEnabled()) { if (traceEnabled()) {
traceWrite("UIWebViewDelegateClass.webViewShouldStartLoadWithRequestNavigationType(" + request.URL.absoluteString + ", " + navigationType + ")", traceCategories.Debug); 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; return true;