mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #1689 from vbresults/master
Added Support for WebView Navigation Types
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import TKUnit = require("../../TKUnit");
|
import TKUnit = require("../../TKUnit");
|
||||||
import testModule = require("../../ui-test");
|
import testModule = require("../../ui-test");
|
||||||
|
|
||||||
// <snippet module="ui/web-view" title="WebView">
|
// <snippet module="ui/web-view" title="WebView">
|
||||||
@@ -185,6 +185,24 @@ 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 {
|
||||||
|
|||||||
12
ios.d.ts
vendored
12
ios.d.ts
vendored
@@ -27073,12 +27073,12 @@ declare enum UITouchPhase {
|
|||||||
UITouchPhaseCancelled
|
UITouchPhaseCancelled
|
||||||
}
|
}
|
||||||
declare enum UIWebViewNavigationType {
|
declare enum UIWebViewNavigationType {
|
||||||
UIWebViewNavigationTypeLinkClicked,
|
LinkClicked,
|
||||||
UIWebViewNavigationTypeFormSubmitted,
|
FormSubmitted,
|
||||||
UIWebViewNavigationTypeBackForward,
|
BackForward,
|
||||||
UIWebViewNavigationTypeReload,
|
Reload,
|
||||||
UIWebViewNavigationTypeFormResubmitted,
|
FormResubmitted,
|
||||||
UIWebViewNavigationTypeOther
|
Other
|
||||||
}
|
}
|
||||||
declare enum UIWebPaginationMode {
|
declare enum UIWebPaginationMode {
|
||||||
UIWebPaginationModeUnpaginated,
|
UIWebPaginationModeUnpaginated,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import definition = require("ui/web-view");
|
import definition = require("ui/web-view");
|
||||||
import view = require("ui/core/view");
|
import view = require("ui/core/view");
|
||||||
import dependencyObservable = require("ui/core/dependency-observable");
|
import dependencyObservable = require("ui/core/dependency-observable");
|
||||||
import proxy = require("ui/core/proxy");
|
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 loadStartedEvent = "loadStarted";
|
||||||
public static loadFinishedEvent = "loadFinished";
|
public static loadFinishedEvent = "loadFinished";
|
||||||
|
|
||||||
|
public static navigationTypes = [
|
||||||
|
"linkClicked",
|
||||||
|
"formSubmitted",
|
||||||
|
"backForward",
|
||||||
|
"reload",
|
||||||
|
"formResubmitted",
|
||||||
|
"other"
|
||||||
|
];
|
||||||
|
|
||||||
public static urlProperty = urlProperty;
|
public static urlProperty = urlProperty;
|
||||||
public static srcProperty = srcProperty;
|
public static srcProperty = srcProperty;
|
||||||
|
|
||||||
@@ -111,17 +120,19 @@ export abstract class WebView extends view.View implements definition.WebView {
|
|||||||
eventName: WebView.loadFinishedEvent,
|
eventName: WebView.loadFinishedEvent,
|
||||||
object: this,
|
object: this,
|
||||||
url: url,
|
url: url,
|
||||||
|
navigationType: undefined,
|
||||||
error: error
|
error: error
|
||||||
};
|
};
|
||||||
|
|
||||||
this.notify(args);
|
this.notify(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _onLoadStarted(url: string) {
|
public _onLoadStarted(url: string, navigationType: string) {
|
||||||
var args = <definition.LoadEventData>{
|
var args = <definition.LoadEventData>{
|
||||||
eventName: WebView.loadStartedEvent,
|
eventName: WebView.loadStartedEvent,
|
||||||
object: this,
|
object: this,
|
||||||
url: url,
|
url: url,
|
||||||
|
navigationType: navigationType,
|
||||||
error: undefined
|
error: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import common = require("./web-view-common");
|
import common = require("./web-view-common");
|
||||||
import trace = require("trace");
|
import trace = require("trace");
|
||||||
import * as fileSystemModule from "file-system";
|
import * as fileSystemModule from "file-system";
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ function ensureWebViewClientClass() {
|
|||||||
|
|
||||||
if (this._view) {
|
if (this._view) {
|
||||||
trace.write("WebViewClientClass.onPageStarted(" + url + ", " + favicon + ")", trace.categories.Debug);
|
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")]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
ui/web-view/web-view.d.ts
vendored
9
ui/web-view/web-view.d.ts
vendored
@@ -20,6 +20,11 @@ declare module "ui/web-view" {
|
|||||||
*/
|
*/
|
||||||
public static loadFinishedEvent: string;
|
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.
|
* 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.
|
* Gets the url of the web-view.
|
||||||
*/
|
*/
|
||||||
url: string;
|
url: string;
|
||||||
|
/**
|
||||||
|
* Gets the navigation type of the web-view.
|
||||||
|
*/
|
||||||
|
navigationType: string;
|
||||||
/**
|
/**
|
||||||
* Gets the error (if any).
|
* Gets the error (if any).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import common = require("./web-view-common");
|
import common = require("./web-view-common");
|
||||||
import trace = require("trace");
|
import trace = require("trace");
|
||||||
|
|
||||||
global.moduleMerge(common, exports);
|
global.moduleMerge(common, exports);
|
||||||
@@ -16,9 +16,30 @@ class UIWebViewDelegateImpl extends NSObject implements UIWebViewDelegate {
|
|||||||
|
|
||||||
public webViewShouldStartLoadWithRequestNavigationType(webView: UIWebView, request: NSURLRequest, navigationType: number) {
|
public webViewShouldStartLoadWithRequestNavigationType(webView: UIWebView, request: NSURLRequest, navigationType: number) {
|
||||||
let owner = this._owner.get();
|
let owner = this._owner.get();
|
||||||
|
|
||||||
if (owner && request.URL) {
|
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);
|
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;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user