Skip to content

Commit d427c9e

Browse files
author
vakrilov
committed
WebView NavigationType converted to type
1 parent 59e34f0 commit d427c9e

File tree

5 files changed

+18
-45
lines changed

5 files changed

+18
-45
lines changed

tests/app/ui/web-view/web-view-tests.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,6 @@ export class WebViewTest extends testModule.UITest<webViewModule.WebView> {
144144

145145
webView.src = targetSrc;
146146
}
147-
148-
public testLoadStartedNavigationTypeExists(done) {
149-
let webView = this.testView;
150-
let targetSrc = "https://github.com/";
151-
152-
webView.on(webViewModule.WebView.loadStartedEvent, function (args: webViewModule.LoadEventData) {
153-
try {
154-
TKUnit.assertNull(args.error, args.error);
155-
TKUnit.assertTrue(webViewModule.WebView.navigationTypes.indexOf(args.navigationType) > -1, "navigationTypeExists");
156-
done(null);
157-
}
158-
catch (e) {
159-
done(e);
160-
}
161-
});
162-
163-
webView.src = targetSrc;
164-
}
165147
}
166148

167149
export function createTestCase(): WebViewTest {

tns-core-modules/ui/web-view/web-view-common.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { WebView as WebViewDefinition, LoadEventData } from ".";
1+
import { WebView as WebViewDefinition, LoadEventData, NavigationType } from ".";
22
import { View, Property } from "../core/view";
33
import { isFileOrResourcePath } from "../../utils/utils";
44
import { File, knownFolders, path } from "../../file-system";
55

6-
export { File, knownFolders, path };
6+
export { File, knownFolders, path, NavigationType };
77
export * from "../core/view";
88

99
export const srcProperty = new Property<WebViewBase, string>({ name: "src" });
@@ -12,15 +12,6 @@ export abstract class WebViewBase extends View implements WebViewDefinition {
1212
public static loadStartedEvent = "loadStarted";
1313
public static loadFinishedEvent = "loadFinished";
1414

15-
public static navigationTypes = [
16-
"linkClicked",
17-
"formSubmitted",
18-
"backForward",
19-
"reload",
20-
"formResubmitted",
21-
"other"
22-
];
23-
2415
public src: string;
2516

2617
public _onLoadFinished(url: string, error?: string) {
@@ -35,7 +26,7 @@ export abstract class WebViewBase extends View implements WebViewDefinition {
3526
this.notify(args);
3627
}
3728

38-
public _onLoadStarted(url: string, navigationType: string) {
29+
public _onLoadStarted(url: string, navigationType: NavigationType) {
3930
let args = <LoadEventData>{
4031
eventName: WebViewBase.loadStartedEvent,
4132
object: this,

tns-core-modules/ui/web-view/web-view.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function initializeWebViewClient(): void {
3434
if (traceEnabled()) {
3535
traceWrite("WebViewClientClass.onPageStarted(" + url + ", " + favicon + ")", traceCategories.Debug);
3636
}
37-
owner._onLoadStarted(url, WebViewBase.navigationTypes[WebViewBase.navigationTypes.indexOf("linkClicked")]);
37+
owner._onLoadStarted(url, undefined);
3838
}
3939
}
4040

tns-core-modules/ui/web-view/web-view.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { View, Property, EventData } from "../core/view";
88
*/
99
export const urlProperty: Property<WebView, string>;
1010

11+
/**
12+
* Represents navigation type
13+
*/
14+
export type NavigationType = "linkClicked" | "formSubmitted" | "backForward" | "reload" | "formResubmitted" | "other" | undefined;
15+
1116
/**
1217
* Represents a standard WebView widget.
1318
*/
@@ -22,11 +27,6 @@ export class WebView extends View {
2227
*/
2328
public static loadFinishedEvent: string;
2429

25-
/**
26-
* Array of string values used when passing navigation types.
27-
*/
28-
public static navigationTypes: string[];
29-
3030
/**
3131
* 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.
3232
*/
@@ -102,7 +102,7 @@ export interface LoadEventData extends EventData {
102102
/**
103103
* Gets the navigation type of the web-view.
104104
*/
105-
navigationType: string;
105+
navigationType: NavigationType;
106106
/**
107107
* Gets the error (if any).
108108
*/

tns-core-modules/ui/web-view/web-view.ios.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { WebViewBase, knownFolders, traceWrite, traceEnabled, traceCategories } from "./web-view-common";
1+
import { WebViewBase, knownFolders, traceWrite, traceEnabled, traceCategories, NavigationType } from "./web-view-common";
22

33
export * from "./web-view-common";
44

@@ -17,30 +17,30 @@ class UIWebViewDelegateImpl extends NSObject implements UIWebViewDelegate {
1717
let owner = this._owner.get();
1818

1919
if (owner && request.URL) {
20-
let navTypeIndex = WebViewBase.navigationTypes.indexOf("other");
20+
let navType: NavigationType = "other";
2121

2222
switch (navigationType) {
2323
case UIWebViewNavigationType.LinkClicked:
24-
navTypeIndex = WebViewBase.navigationTypes.indexOf("linkClicked");
24+
navType = "linkClicked";
2525
break;
2626
case UIWebViewNavigationType.FormSubmitted:
27-
navTypeIndex = WebViewBase.navigationTypes.indexOf("formSubmitted");
27+
navType = "formSubmitted";
2828
break;
2929
case UIWebViewNavigationType.BackForward:
30-
navTypeIndex = WebViewBase.navigationTypes.indexOf("backForward");
30+
navType = "backForward";
3131
break;
3232
case UIWebViewNavigationType.Reload:
33-
navTypeIndex = WebViewBase.navigationTypes.indexOf("reload");
33+
navType = "reload";
3434
break;
3535
case UIWebViewNavigationType.FormResubmitted:
36-
navTypeIndex = WebViewBase.navigationTypes.indexOf("formResubmitted");
36+
navType = "formResubmitted";
3737
break;
3838
}
3939

4040
if (traceEnabled()) {
4141
traceWrite("UIWebViewDelegateClass.webViewShouldStartLoadWithRequestNavigationType(" + request.URL.absoluteString + ", " + navigationType + ")", traceCategories.Debug);
4242
}
43-
owner._onLoadStarted(request.URL.absoluteString, WebViewBase.navigationTypes[navTypeIndex]);
43+
owner._onLoadStarted(request.URL.absoluteString, navType);
4444
}
4545

4646
return true;

0 commit comments

Comments
 (0)