From d427c9ed8f2d09c7da83d767df64d01fab9c01a8 Mon Sep 17 00:00:00 2001 From: vakrilov Date: Tue, 4 Apr 2017 17:31:56 +0300 Subject: [PATCH] WebView NavigationType converted to type --- tests/app/ui/web-view/web-view-tests.ts | 18 ------------------ .../ui/web-view/web-view-common.ts | 15 +++------------ .../ui/web-view/web-view.android.ts | 2 +- tns-core-modules/ui/web-view/web-view.d.ts | 12 ++++++------ tns-core-modules/ui/web-view/web-view.ios.ts | 16 ++++++++-------- 5 files changed, 18 insertions(+), 45 deletions(-) diff --git a/tests/app/ui/web-view/web-view-tests.ts b/tests/app/ui/web-view/web-view-tests.ts index f72e009cf..0c40ae9ad 100644 --- a/tests/app/ui/web-view/web-view-tests.ts +++ b/tests/app/ui/web-view/web-view-tests.ts @@ -144,24 +144,6 @@ export class WebViewTest extends testModule.UITest { 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 { diff --git a/tns-core-modules/ui/web-view/web-view-common.ts b/tns-core-modules/ui/web-view/web-view-common.ts index 2b5147886..b7db1ebeb 100644 --- a/tns-core-modules/ui/web-view/web-view-common.ts +++ b/tns-core-modules/ui/web-view/web-view-common.ts @@ -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({ 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 = { eventName: WebViewBase.loadStartedEvent, object: this, diff --git a/tns-core-modules/ui/web-view/web-view.android.ts b/tns-core-modules/ui/web-view/web-view.android.ts index 2d51d2f49..094d00db7 100644 --- a/tns-core-modules/ui/web-view/web-view.android.ts +++ b/tns-core-modules/ui/web-view/web-view.android.ts @@ -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); } } diff --git a/tns-core-modules/ui/web-view/web-view.d.ts b/tns-core-modules/ui/web-view/web-view.d.ts index 4570d11ee..82c0b026a 100644 --- a/tns-core-modules/ui/web-view/web-view.d.ts +++ b/tns-core-modules/ui/web-view/web-view.d.ts @@ -8,6 +8,11 @@ import { View, Property, EventData } from "../core/view"; */ export const urlProperty: Property; +/** + * 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). */ diff --git a/tns-core-modules/ui/web-view/web-view.ios.ts b/tns-core-modules/ui/web-view/web-view.ios.ts index 9b68559a9..54d8dc86d 100644 --- a/tns-core-modules/ui/web-view/web-view.ios.ts +++ b/tns-core-modules/ui/web-view/web-view.ios.ts @@ -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;