From e452aff6580aa36d7d428d08a230881e4294c70b Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Mon, 1 Feb 2016 16:55:31 +0200 Subject: [PATCH 1/6] Detect JSON response in XHR and auto-parse the response. - Part of the XMLHttpRequest level 2 API. - Fixes a crash with the Angular2 Http service. --- apps/tests/xhr-tests.ts | 39 +++++++++++++++++++++++++++ xhr/xhr.ts | 58 +++++++++++++++++++++++++++-------------- 2 files changed, 77 insertions(+), 20 deletions(-) diff --git a/apps/tests/xhr-tests.ts b/apps/tests/xhr-tests.ts index 2663b72ee..d60c167f3 100644 --- a/apps/tests/xhr-tests.ts +++ b/apps/tests/xhr-tests.ts @@ -124,6 +124,7 @@ export var test_XMLHttpRequest_contentSentAndReceivedProperly = function (done) // try { TKUnit.assert(result["json"]["MyVariableOne"] === "ValueOne" && result["json"]["MyVariableTwo"] === "ValueTwo", "Content not sent/received properly!"); + TKUnit.assert(xhr.response.json.MyVariableOne === "ValueOne" && xhr.response.json.MyVariableTwo === "ValueTwo", "Response content not parsed properly!"); done(null); } catch (err) { @@ -255,6 +256,44 @@ export function test_xhr_events() { TKUnit.assertEqual(errorEventData, 'error data'); } +export function test_xhr_responseType_text() { + const xhr = new XMLHttpRequest(); + const response = { + statusCode: 200, + content: { + toString: function(){ return this.raw }, + raw: 'response body' + }, + headers: { + "Content-Type": "text/plain" + } + + } + xhr._loadResponse(response); + + TKUnit.assertEqual(xhr.responseType, "text"); + TKUnit.assertEqual(xhr.response, 'response body'); +} + +export function test_xhr_responseType_switched_to_JSON_if_header_present() { + const xhr = new XMLHttpRequest(); + const response = { + statusCode: 200, + content: { + toString: function(){ return this.raw }, + raw: '{"data": 42}' + }, + headers: { + "Content-Type": "application/json" + } + + } + xhr._loadResponse(response); + + TKUnit.assertEqual(xhr.responseType, "json"); + TKUnit.assertEqual(xhr.response.data, 42); +} + export function test_sets_status_and_statusText(done) { let xhr = new XMLHttpRequest(); xhr.onreadystatechange = () => { diff --git a/xhr/xhr.ts b/xhr/xhr.ts index bd07470c1..8f5d95d96 100644 --- a/xhr/xhr.ts +++ b/xhr/xhr.ts @@ -21,7 +21,7 @@ export class XMLHttpRequest { private _readyState: number; private _status: number; private _response: any; - private _responseText: Function; + private _responseTextReader: Function; private _headers: any; private _errorFlag: boolean; private _responseType: string = ""; @@ -53,7 +53,7 @@ export class XMLHttpRequest { this._errorFlag = true; this._response = null; - this._responseText = null; + this._responseTextReader = null; this._headers = null; this._status = null; @@ -67,7 +67,7 @@ export class XMLHttpRequest { public send(data?: any) { this._errorFlag = false; this._response = null; - this._responseText = null; + this._responseTextReader = null; this._headers = null; this._status = null; @@ -83,21 +83,7 @@ export class XMLHttpRequest { http.request(this._options).then(r=> { if (!this._errorFlag) { - this._status = r.statusCode; - this._response = r.content.raw; - - this._headers = r.headers; - this._setReadyState(this.HEADERS_RECEIVED); - - this._setReadyState(this.LOADING); - - if (this.responseType === XMLHttpRequestResponseType.empty || - this.responseType === XMLHttpRequestResponseType.text || - this.responseType === XMLHttpRequestResponseType.json) { - this._responseText = r.content.toString; - } - - this._setReadyState(this.DONE); + this._loadResponse(r); } }).catch(e => { @@ -107,6 +93,38 @@ export class XMLHttpRequest { } } + private _loadResponse(r) { + this._status = r.statusCode; + this._response = r.content.raw; + + this._headers = r.headers; + this._setReadyState(this.HEADERS_RECEIVED); + + this._setReadyState(this.LOADING); + + this._setResponseType(); + + if (this.responseType === XMLHttpRequestResponseType.json) { + this._responseTextReader = () => r.content.toString(); + this._response = JSON.parse(this.responseText); + } else if (this.responseType === XMLHttpRequestResponseType.empty || + this.responseType === XMLHttpRequestResponseType.text) { + this._responseTextReader = () => r.content.toString(); + } + + this._setReadyState(this.DONE); + } + + private _setResponseType() { + const contentType = this.getResponseHeader('Content-Type').toLowerCase(); + + if (contentType === 'application/json') { + this.responseType = XMLHttpRequestResponseType.json; + } else if (contentType === 'text/plain') { + this.responseType = XMLHttpRequestResponseType.text; + } + } + private _listeners: Map> = new Map>(); public addEventListener(eventName: string, handler: Function) { @@ -211,8 +229,8 @@ export class XMLHttpRequest { } get responseText(): string { - if (types.isFunction(this._responseText)) { - return this._responseText(); + if (types.isFunction(this._responseTextReader)) { + return this._responseTextReader(); } return ""; From c3b4d40d0b5e97e514bb989b619c93d8d1ac2de2 Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Mon, 1 Feb 2016 17:00:20 +0200 Subject: [PATCH 2/6] Run tslint only once :-) Two grunt tasks had it as a dependency, and that triggered two runs. --- gruntfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gruntfile.js b/gruntfile.js index d40cf9bb5..3863f6988 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -628,13 +628,13 @@ module.exports = function(grunt) { //alias just-build for backwards compatibility grunt.registerTask("just-build", ["build-all"]); - grunt.registerTask("build-all", (skipTsLint ? [] : ["tslint:build"]).concat([ + grunt.registerTask("build-all", [ "pack-modules", "collect-apps-raw-files", "distribute-apps-files", "distribute-ts-apps-files", - ])); + ]); grunt.registerTask("node-tests", [ "clean:nodeTests", From 31a6da0676d095eec8e5db353e10caeae68821b3 Mon Sep 17 00:00:00 2001 From: Peter Staev Date: Tue, 2 Feb 2016 18:41:36 +0200 Subject: [PATCH 3/6] fix ios dialogs.action when message/title is null --- ui/dialogs/dialogs.ios.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ui/dialogs/dialogs.ios.ts b/ui/dialogs/dialogs.ios.ts index 09b58101a..7e200cb79 100644 --- a/ui/dialogs/dialogs.ios.ts +++ b/ui/dialogs/dialogs.ios.ts @@ -403,10 +403,14 @@ function showUIAlertController(alertController: UIAlertController) { var lblColor = dialogsCommon.getLabelColor(); if (lblColor) { - var title = NSAttributedString.alloc().initWithStringAttributes(alertController.title, { [NSForegroundColorAttributeName]: lblColor.ios }); - alertController.setValueForKey(title, "attributedTitle"); - var message = NSAttributedString.alloc().initWithStringAttributes(alertController.message, { [NSForegroundColorAttributeName]: lblColor.ios }); - alertController.setValueForKey(message, "attributedMessage"); + if (alertController.title) { + var title = NSAttributedString.alloc().initWithStringAttributes(alertController.title, { [NSForegroundColorAttributeName]: lblColor.ios }); + alertController.setValueForKey(title, "attributedTitle"); + } + if (alertController.message) { + var message = NSAttributedString.alloc().initWithStringAttributes(alertController.message, { [NSForegroundColorAttributeName]: lblColor.ios }); + alertController.setValueForKey(message, "attributedMessage"); + } } viewController.presentModalViewControllerAnimated(alertController, true); From 001d542acfd68fdd21feade201298ab8295d9dbd Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Tue, 2 Feb 2016 19:03:58 +0200 Subject: [PATCH 4/6] Update ui-tests-app --- CrossPlatformModules.csproj | 6 ++++-- apps/ui-tests-app/css/{tab-view.xml => tab-view-more.xml} | 2 +- apps/ui-tests-app/css/{text.css => test.css} | 0 apps/ui-tests-app/font/material-icons.xml | 2 +- apps/ui-tests-app/font/tab-view.xml | 4 ++-- apps/ui-tests-app/mainPage.ts | 2 ++ 6 files changed, 10 insertions(+), 6 deletions(-) rename apps/ui-tests-app/css/{tab-view.xml => tab-view-more.xml} (96%) rename apps/ui-tests-app/css/{text.css => test.css} (100%) diff --git a/CrossPlatformModules.csproj b/CrossPlatformModules.csproj index 3c8aa80a5..fe955766c 100644 --- a/CrossPlatformModules.csproj +++ b/CrossPlatformModules.csproj @@ -209,11 +209,13 @@ - - + + Designer + + Designer diff --git a/apps/ui-tests-app/css/tab-view.xml b/apps/ui-tests-app/css/tab-view-more.xml similarity index 96% rename from apps/ui-tests-app/css/tab-view.xml rename to apps/ui-tests-app/css/tab-view-more.xml index 02d5cb572..43163dc8a 100644 --- a/apps/ui-tests-app/css/tab-view.xml +++ b/apps/ui-tests-app/css/tab-view-more.xml @@ -1,4 +1,4 @@ - + diff --git a/apps/ui-tests-app/css/text.css b/apps/ui-tests-app/css/test.css similarity index 100% rename from apps/ui-tests-app/css/text.css rename to apps/ui-tests-app/css/test.css diff --git a/apps/ui-tests-app/font/material-icons.xml b/apps/ui-tests-app/font/material-icons.xml index 472e27721..438b0b653 100644 --- a/apps/ui-tests-app/font/material-icons.xml +++ b/apps/ui-tests-app/font/material-icons.xml @@ -1,5 +1,5 @@  - \ No newline at end of file diff --git a/apps/ui-tests-app/font/tab-view.xml b/apps/ui-tests-app/font/tab-view.xml index d52ed3ef7..ff9376cd2 100644 --- a/apps/ui-tests-app/font/tab-view.xml +++ b/apps/ui-tests-app/font/tab-view.xml @@ -3,12 +3,12 @@ - - diff --git a/apps/ui-tests-app/mainPage.ts b/apps/ui-tests-app/mainPage.ts index db06d6d60..c552bb367 100644 --- a/apps/ui-tests-app/mainPage.ts +++ b/apps/ui-tests-app/mainPage.ts @@ -48,11 +48,13 @@ examples.set("whitespace", "css/white-space"); examples.set("radius", "css/radius"); examples.set("styles", "css/styles"); examples.set("switch", "css/views"); +examples.set("tabmore", "css/tab-view-more"); examples.set("dialogs", "dialogs/dialogs"); examples.set("fontbtn", "font/button"); examples.set("fontlbl", "font/label"); +examples.set("tabfont", "font/tab-view"); examples.set("fontfield", "font/text-field"); examples.set("fontview", "font/text-view"); From b0976bf986340066e531671b9b51042eef244509 Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Fri, 15 Jan 2016 09:20:58 +0200 Subject: [PATCH 5/6] Resolved #811: Page Navigation Transitions --- CrossPlatformModules.csproj | 19 +- apps/perf-tests/NavigationTest/app.ts | 16 +- .../NavigationTest/list-picker-page.ts | 21 + .../NavigationTest/list-picker-page.xml | 6 + apps/perf-tests/custom-transition.android.ts | 35 ++ apps/perf-tests/custom-transition.ios.ts | 26 ++ apps/perf-tests/nav-page.ts | 190 +++++++-- apps/tab-view-demo/mainPage.ts | 10 +- apps/tests/app/mainPage.ts | 1 + apps/tests/navigation-tests.ts | 113 ----- .../navigation/custom-transition.android.ts | 39 ++ .../tests/navigation/custom-transition.ios.ts | 30 ++ apps/tests/navigation/navigation-tests.ts | 183 ++++++++ apps/tests/testRunner.ts | 5 +- apps/tests/ui/helper.ts | 15 +- apps/tests/ui/page/page-tests-common.ts | 215 +++++----- apps/tests/ui/page/page-tests.ios.ts | 16 +- trace/trace.d.ts | 1 + trace/trace.ts | 3 +- tsconfig.json | 15 +- ui/animation/animation-common.ts | 6 +- ui/animation/animation.android.ts | 46 +- ui/animation/animation.d.ts | 7 +- ui/animation/animation.ios.ts | 40 +- ui/core/view-common.ts | 7 +- ui/frame/frame-common.ts | 35 +- ui/frame/frame.android.ts | 248 ++++++----- ui/frame/frame.d.ts | 36 ++ ui/frame/frame.ios.ts | 275 ++++++++++-- ui/page/page.android.ts | 6 +- ui/page/page.ios.ts | 22 - ui/transition/fade-transition.android.ts | 29 ++ ui/transition/fade-transition.ios.ts | 25 ++ ui/transition/flip-transition.android.ts | 120 ++++++ ui/transition/package.json | 2 + ui/transition/slide-transition.android.ts | 116 +++++ ui/transition/slide-transition.ios.ts | 64 +++ ui/transition/transition.android.ts | 395 ++++++++++++++++++ ui/transition/transition.d.ts | 29 ++ ui/transition/transition.ios.ts | 115 +++++ ui/ui.d.ts | 1 + 41 files changed, 2090 insertions(+), 493 deletions(-) create mode 100644 apps/perf-tests/NavigationTest/list-picker-page.ts create mode 100644 apps/perf-tests/NavigationTest/list-picker-page.xml create mode 100644 apps/perf-tests/custom-transition.android.ts create mode 100644 apps/perf-tests/custom-transition.ios.ts delete mode 100644 apps/tests/navigation-tests.ts create mode 100644 apps/tests/navigation/custom-transition.android.ts create mode 100644 apps/tests/navigation/custom-transition.ios.ts create mode 100644 apps/tests/navigation/navigation-tests.ts create mode 100644 ui/transition/fade-transition.android.ts create mode 100644 ui/transition/fade-transition.ios.ts create mode 100644 ui/transition/flip-transition.android.ts create mode 100644 ui/transition/package.json create mode 100644 ui/transition/slide-transition.android.ts create mode 100644 ui/transition/slide-transition.ios.ts create mode 100644 ui/transition/transition.android.ts create mode 100644 ui/transition/transition.d.ts create mode 100644 ui/transition/transition.ios.ts diff --git a/CrossPlatformModules.csproj b/CrossPlatformModules.csproj index 3c8aa80a5..54b01ab88 100644 --- a/CrossPlatformModules.csproj +++ b/CrossPlatformModules.csproj @@ -83,7 +83,12 @@ data-binding.xml + + + + + modal-page.xml @@ -130,6 +135,7 @@ + @@ -175,7 +181,7 @@ - + page21.xml @@ -737,6 +743,14 @@ + + + + + + + + @@ -2093,6 +2107,9 @@ + + PreserveNewest + diff --git a/apps/perf-tests/NavigationTest/app.ts b/apps/perf-tests/NavigationTest/app.ts index 91949d903..00c39550d 100644 --- a/apps/perf-tests/NavigationTest/app.ts +++ b/apps/perf-tests/NavigationTest/app.ts @@ -4,13 +4,23 @@ import navPageModule = require("../nav-page"); import trace = require("trace"); trace.enable(); trace.setCategories(trace.categories.concat( - trace.categories.NativeLifecycle - , trace.categories.Navigation + trace.categories.NativeLifecycle, + trace.categories.Navigation, + //trace.categories.Animation, + trace.categories.Transition )); application.mainEntry = { create: function () { - return new navPageModule.NavPage(0); + return new navPageModule.NavPage({ + index: 0, + backStackVisible: true, + clearHistory: false, + animated: true, + transition: 0, + curve: 0, + duration: 0, + }); } //backstackVisible: false, //clearHistory: true diff --git a/apps/perf-tests/NavigationTest/list-picker-page.ts b/apps/perf-tests/NavigationTest/list-picker-page.ts new file mode 100644 index 000000000..0c93c1bf6 --- /dev/null +++ b/apps/perf-tests/NavigationTest/list-picker-page.ts @@ -0,0 +1,21 @@ +import {Page, ShownModallyData, ListPicker} from "ui"; + +var closeCallback: Function; +var page: Page; +var listPicker: ListPicker; + +export function onLoaded(args) { + page = args.object; + listPicker = page.getViewById("listPicker"); +} + +export function onShownModally(args) { + closeCallback = args.closeCallback; + + listPicker.items = args.context.items; + listPicker.selectedIndex = args.context.selectedIndex || 0; +} + +export function onButtonTap() { + closeCallback(listPicker.selectedIndex); +} \ No newline at end of file diff --git a/apps/perf-tests/NavigationTest/list-picker-page.xml b/apps/perf-tests/NavigationTest/list-picker-page.xml new file mode 100644 index 000000000..27cdc8b69 --- /dev/null +++ b/apps/perf-tests/NavigationTest/list-picker-page.xml @@ -0,0 +1,6 @@ + + + +