Merge pull request #1689 from vbresults/master

Added Support for WebView Navigation Types
This commit is contained in:
Vladimir Enchev
2016-03-10 09:59:52 +02:00
6 changed files with 73 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
import TKUnit = require("../../TKUnit");
import TKUnit = require("../../TKUnit");
import testModule = require("../../ui-test");
// <snippet module="ui/web-view" title="WebView">
@@ -185,6 +185,24 @@ 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 {

12
ios.d.ts vendored
View File

@@ -27073,12 +27073,12 @@ declare enum UITouchPhase {
UITouchPhaseCancelled
}
declare enum UIWebViewNavigationType {
UIWebViewNavigationTypeLinkClicked,
UIWebViewNavigationTypeFormSubmitted,
UIWebViewNavigationTypeBackForward,
UIWebViewNavigationTypeReload,
UIWebViewNavigationTypeFormResubmitted,
UIWebViewNavigationTypeOther
LinkClicked,
FormSubmitted,
BackForward,
Reload,
FormResubmitted,
Other
}
declare enum UIWebPaginationMode {
UIWebPaginationModeUnpaginated,

View File

@@ -1,4 +1,4 @@
import definition = require("ui/web-view");
import definition = require("ui/web-view");
import view = require("ui/core/view");
import dependencyObservable = require("ui/core/dependency-observable");
import proxy = require("ui/core/proxy");
@@ -76,6 +76,15 @@ export abstract class WebView extends view.View implements definition.WebView {
public static loadStartedEvent = "loadStarted";
public static loadFinishedEvent = "loadFinished";
public static navigationTypes = [
"linkClicked",
"formSubmitted",
"backForward",
"reload",
"formResubmitted",
"other"
];
public static urlProperty = urlProperty;
public static srcProperty = srcProperty;
@@ -111,17 +120,19 @@ export abstract class WebView extends view.View implements definition.WebView {
eventName: WebView.loadFinishedEvent,
object: this,
url: url,
navigationType: undefined,
error: error
};
this.notify(args);
}
public _onLoadStarted(url: string) {
public _onLoadStarted(url: string, navigationType: string) {
var args = <definition.LoadEventData>{
eventName: WebView.loadStartedEvent,
object: this,
url: url,
navigationType: navigationType,
error: undefined
};
@@ -151,4 +162,4 @@ export abstract class WebView extends view.View implements definition.WebView {
abstract goForward(): void;
abstract reload(): void;
}
}

View File

@@ -1,4 +1,4 @@
import common = require("./web-view-common");
import common = require("./web-view-common");
import trace = require("trace");
import * as fileSystemModule from "file-system";
@@ -37,7 +37,7 @@ function ensureWebViewClientClass() {
if (this._view) {
trace.write("WebViewClientClass.onPageStarted(" + url + ", " + favicon + ")", trace.categories.Debug);
this._view._onLoadStarted(url);
this._view._onLoadStarted(url, common.WebView.navigationTypes[common.WebView.navigationTypes.indexOf("linkClicked")]);
}
}

View File

@@ -20,6 +20,11 @@ declare module "ui/web-view" {
*/
public static loadFinishedEvent: string;
/**
* Array of string values used when passing navigation types.
*/
public static navigationTypes: string[];
/**
* Represents the observable property backing the Url property of each WebView instance.
*/
@@ -102,6 +107,10 @@ declare module "ui/web-view" {
* Gets the url of the web-view.
*/
url: string;
/**
* Gets the navigation type of the web-view.
*/
navigationType: string;
/**
* Gets the error (if any).
*/

View File

@@ -1,4 +1,4 @@
import common = require("./web-view-common");
import common = require("./web-view-common");
import trace = require("trace");
global.moduleMerge(common, exports);
@@ -16,9 +16,30 @@ class UIWebViewDelegateImpl extends NSObject implements UIWebViewDelegate {
public webViewShouldStartLoadWithRequestNavigationType(webView: UIWebView, request: NSURLRequest, navigationType: number) {
let owner = this._owner.get();
if (owner && request.URL) {
var navTypeIndex = common.WebView.navigationTypes.indexOf("other");
switch (navigationType) {
case UIWebViewNavigationType.LinkClicked:
navTypeIndex = common.WebView.navigationTypes.indexOf("linkClicked");
break;
case UIWebViewNavigationType.FormSubmitted:
navTypeIndex = common.WebView.navigationTypes.indexOf("formSubmitted");
break;
case UIWebViewNavigationType.BackForward:
navTypeIndex = common.WebView.navigationTypes.indexOf("backForward");
break;
case UIWebViewNavigationType.Reload:
navTypeIndex = common.WebView.navigationTypes.indexOf("reload");
break;
case UIWebViewNavigationType.FormResubmitted:
navTypeIndex = common.WebView.navigationTypes.indexOf("formResubmitted");
break;
}
trace.write("UIWebViewDelegateClass.webViewShouldStartLoadWithRequestNavigationType(" + request.URL.absoluteString + ", " + navigationType + ")", trace.categories.Debug);
owner._onLoadStarted(request.URL.absoluteString);
owner._onLoadStarted(request.URL.absoluteString, common.WebView.navigationTypes[navTypeIndex]);
}
return true;