From 0ae8dba96299e26fc6eb363bbd8ad7f63fc7dca3 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Tue, 7 Jul 2020 15:57:02 -0700 Subject: [PATCH] chore: cleanup --- e2e/ui-tests-app/app/app.ts | 31 ++- .../app/bottom-navigation/fancy-fonts-page.ts | 3 +- .../app/bottom-navigation/first-page.ts | 2 +- .../app/bottom-navigation/reselect-page.ts | 7 +- .../app/bottom-navigation/second-page.ts | 3 +- e2e/ui-tests-app/app/css/elevation-page.ts | 4 +- .../app/fonts-tests/button-page.ts | 9 +- .../app/fonts-tests/label-page.ts | 3 +- .../app/layouts/passThroughParent-page.ts | 3 +- .../app/tabs/custom-tabstrip-page.ts | 4 +- e2e/ui-tests-app/app/tabs/default-page.ts | 4 +- .../app/tabs/dynamic-color-change-page.ts | 4 +- e2e/ui-tests-app/app/tabs/events-page.ts | 4 +- e2e/ui-tests-app/app/tabs/first-page.ts | 3 +- e2e/ui-tests-app/app/tabs/icon-change-page.ts | 2 +- e2e/ui-tests-app/app/tabs/main-page.ts | 4 +- e2e/ui-tests-app/app/tabs/reselect-page.ts | 7 +- e2e/ui-tests-app/app/tabs/second-page.ts | 3 +- e2e/ui-tests-app/app/tabs/tabs-page.ts | 4 +- .../app/text-field/focus-blur-events-page.ts | 3 +- e2e/ui-tests-app/app/text-field/main-page.ts | 4 +- .../app/text-field/max-length-page.ts | 3 +- .../app/text-view/hint-text-color-page.ts | 5 +- e2e/ui-tests-app/app/text-view/main-page.ts | 4 +- .../text-view/text-view-hint-color-page.ts | 4 +- e2e/ui-tests-app/package.json | 10 +- e2e/ui-tests-app/references.d.ts | 4 +- e2e/ui-tests-app/tsconfig.json | 5 +- e2e/ui-tests-app/webpack.config.js | 110 +++++--- .../application/application-common.ts | 6 +- nativescript-core/application/index.ios.ts | 4 +- nativescript-core/globals/core.ts | 36 --- nativescript-core/globals/decorators.ts | 39 --- nativescript-core/globals/index.d.ts | 1 - nativescript-core/globals/index.ts | 244 +++++++++++++++++- .../globals/register-module-helpers.ts | 128 --------- nativescript-core/globals/ts-helpers.ts | 32 --- nativescript-core/index.d.ts | 79 ++++++ nativescript-core/index.ts | 6 +- nativescript-core/inspector_modules.ios.ts | 5 +- nativescript-core/package.json | 2 +- .../ui/bottom-navigation/index.ios.ts | 8 +- .../{component-builder.d.ts => index.d.ts} | 0 .../{component-builder.ts => index.ts} | 8 +- .../ui/builder/component-builder/package.json | 5 - nativescript-core/ui/core/view/index.d.ts | 26 +- nativescript-core/ui/core/view/view-common.ts | 5 +- .../ui/core/view/view-helper/index.d.ts | 3 + nativescript-core/ui/dialogs/index.ios.ts | 1 - .../editable-text-base-common.ts | 3 +- .../ui/editable-text-base/index.d.ts | 4 +- nativescript-core/ui/enums/index.d.ts | 15 +- nativescript-core/ui/enums/index.ts | 1 + nativescript-core/ui/index.d.ts | 2 + nativescript-core/ui/index.ts | 4 +- nativescript-core/ui/layouts/index.d.ts | 2 +- nativescript-core/ui/layouts/index.ts | 2 +- nativescript-core/ui/page/index.ios.ts | 10 +- .../ui/styling/style-properties.d.ts | 19 +- nativescript-core/ui/tab-view/index.ios.ts | 8 +- nativescript-core/ui/tabs/index.ios.ts | 8 +- nativescript-core/ui/text-view/index.ios.ts | 3 +- package.json | 2 +- tests/app/tk-unit.ts | 13 +- tests/app/ui/page/page-tests.ios.ts | 4 +- .../xml-declaration/xml-declaration-tests.ts | 95 +++---- tests/package.json | 6 +- tests/reference.d.ts | 4 +- tests/tsconfig.json | 2 +- tns-core-modules-widgets/package.json | 4 +- 70 files changed, 585 insertions(+), 520 deletions(-) delete mode 100644 nativescript-core/globals/core.ts delete mode 100644 nativescript-core/globals/decorators.ts delete mode 100644 nativescript-core/globals/register-module-helpers.ts delete mode 100644 nativescript-core/globals/ts-helpers.ts rename nativescript-core/ui/builder/component-builder/{component-builder.d.ts => index.d.ts} (100%) rename nativescript-core/ui/builder/component-builder/{component-builder.ts => index.ts} (98%) delete mode 100644 nativescript-core/ui/builder/component-builder/package.json diff --git a/e2e/ui-tests-app/app/app.ts b/e2e/ui-tests-app/app/app.ts index 169e9b56a..20225c615 100644 --- a/e2e/ui-tests-app/app/app.ts +++ b/e2e/ui-tests-app/app/app.ts @@ -1,22 +1,21 @@ console.log("####### ------ APP MODULES START "); -import * as application from "tns-core-modules/application"; -import * as trace from "tns-core-modules/trace"; -trace.addCategories(trace.categories.NativeLifecycle); -trace.addCategories(trace.categories.Navigation); -trace.addCategories(trace.categories.Transition); +import { Trace, Application, UnhandledErrorEventData, LaunchEventData, ApplicationEventData, DiscardedErrorEventData } from "@nativescript/core"; +Trace.addCategories(Trace.categories.NativeLifecycle); +Trace.addCategories(Trace.categories.Navigation); +Trace.addCategories(Trace.categories.Transition); -trace.enable(); +Trace.enable(); var countResume = 0; var countSuspend = 0; -application.on("displayed", args => { +Application.on("displayed", args => { const uptime = global.android ? (org).nativescript.Process.getUpTime : (global).__tns_uptime; console.log("Startup time: " + uptime() + "ms."); }); -application.on("uncaughtError", args => { +Application.on("uncaughtError", args => { const error = args.error; console.warn(error.message); if (error.nativeError) { @@ -24,7 +23,7 @@ application.on("uncaughtError", args => { } }); -application.on(application.launchEvent, function (args: application.LaunchEventData) { +Application.on(Application.launchEvent, function (args: LaunchEventData) { if (args.android) { // For Android applications, args.android is an android.content.Intent class. console.log("### Launched application with: " + args.android + "."); @@ -34,7 +33,7 @@ application.on(application.launchEvent, function (args: application.LaunchEventD } }); -application.on(application.suspendEvent, function (args: application.ApplicationEventData) { +Application.on(Application.suspendEvent, function (args: ApplicationEventData) { if (args.android) { // For Android applications, args.android is an android activity class. console.log("#" + ++countSuspend + "# SuspendEvent Activity: " + args.android); @@ -44,7 +43,7 @@ application.on(application.suspendEvent, function (args: application.Application } }); -application.on(application.resumeEvent, function (args: application.ApplicationEventData) { +Application.on(Application.resumeEvent, function (args: ApplicationEventData) { if (args.android) { // For Android applications, args.android is an android activity class. console.log("#" + ++countResume + "# ResumeEvent Activity: " + args.android); @@ -54,7 +53,7 @@ application.on(application.resumeEvent, function (args: application.ApplicationE } }); -application.on(application.exitEvent, function (args: application.ApplicationEventData) { +Application.on(Application.exitEvent, function (args: ApplicationEventData) { if (args.android) { // For Android applications, args.android is an android activity class. console.log("### ExitEvent Activity: " + args.android); @@ -64,7 +63,7 @@ application.on(application.exitEvent, function (args: application.ApplicationEve } }); -application.on(application.lowMemoryEvent, function (args: application.ApplicationEventData) { +Application.on(Application.lowMemoryEvent, function (args: ApplicationEventData) { if (args.android) { // For Android applications, args.android is an android activity class. console.log("### LowMemoryEvent Activity: " + args.android); @@ -74,21 +73,21 @@ application.on(application.lowMemoryEvent, function (args: application.Applicati } }); -application.on(application.uncaughtErrorEvent, function (args: application.UnhandledErrorEventData) { +Application.on(Application.uncaughtErrorEvent, function (args: UnhandledErrorEventData) { console.log("### NativeScriptError: " + args.error); console.log("### nativeException: " + (args.error).nativeException); console.log("### stackTrace: " + (args.error).stackTrace); console.log("### stack: " + args.error.stack); }); -application.on(application.discardedErrorEvent, function (args: application.DiscardedErrorEventData) { +Application.on(Application.discardedErrorEvent, function (args: DiscardedErrorEventData) { console.log("### [Discarded] NativeScriptError: " + args.error); console.log("### [Discarded] nativeException: " + (args.error).nativeException); console.log("### [Discarded] stackTrace: " + (args.error).stackTrace); console.log("### [Discarded] stack: " + args.error.stack); }); -application.run({ moduleName: "app-root" }); +Application.run({ moduleName: "app-root" }); // TODO: investigate tab-view -> tabviewcss test crash // TODO: investigate css -> layouts border overlap failure diff --git a/e2e/ui-tests-app/app/bottom-navigation/fancy-fonts-page.ts b/e2e/ui-tests-app/app/bottom-navigation/fancy-fonts-page.ts index 575e66672..580c99d43 100644 --- a/e2e/ui-tests-app/app/bottom-navigation/fancy-fonts-page.ts +++ b/e2e/ui-tests-app/app/bottom-navigation/fancy-fonts-page.ts @@ -1,5 +1,4 @@ -import { EventData, Page } from "tns-core-modules/ui/page/page"; -import { BottomNavigation } from "tns-core-modules/ui/bottom-navigation/bottom-navigation"; +import { EventData, Page, BottomNavigation } from "@nativescript/core"; export const selectTab = (args: EventData) => { const page = (args.object).page; diff --git a/e2e/ui-tests-app/app/bottom-navigation/first-page.ts b/e2e/ui-tests-app/app/bottom-navigation/first-page.ts index 3df754637..121cae4a0 100644 --- a/e2e/ui-tests-app/app/bottom-navigation/first-page.ts +++ b/e2e/ui-tests-app/app/bottom-navigation/first-page.ts @@ -1,5 +1,5 @@ import { EventData } from "tns-core-modules/data/observable"; -import { Button } from "tns-core-modules/ui/button/button"; +import { Button } from "tns-core-modules/ui/button"; export function goToSecond(args: EventData) { console.log("---> goToSecond Page"); diff --git a/e2e/ui-tests-app/app/bottom-navigation/reselect-page.ts b/e2e/ui-tests-app/app/bottom-navigation/reselect-page.ts index 91963cdf8..1b4d99554 100644 --- a/e2e/ui-tests-app/app/bottom-navigation/reselect-page.ts +++ b/e2e/ui-tests-app/app/bottom-navigation/reselect-page.ts @@ -1,9 +1,4 @@ -import { EventData } from "tns-core-modules/data/observable"; -import { Frame } from "tns-core-modules/ui/frame/frame"; -import { Page } from "tns-core-modules/ui/page"; -import { - TabStripItemEventData, SelectedIndexChangedEventData, BottomNavigation, TabStrip, -} from "tns-core-modules/ui/bottom-navigation"; +import { EventData, Frame, Page, TabStripItemEventData, SelectedIndexChangedEventData, BottomNavigation, TabStrip } from "@nativescript/core"; export function goToFirst(args: EventData) { console.log("---> goToFirst"); diff --git a/e2e/ui-tests-app/app/bottom-navigation/second-page.ts b/e2e/ui-tests-app/app/bottom-navigation/second-page.ts index bc0a5d0b0..826e375e0 100644 --- a/e2e/ui-tests-app/app/bottom-navigation/second-page.ts +++ b/e2e/ui-tests-app/app/bottom-navigation/second-page.ts @@ -1,5 +1,4 @@ -import { EventData } from "tns-core-modules/data/observable"; -import { Button } from "tns-core-modules/ui/button/button"; +import { Button, EventData } from "@nativescript/core"; export function goToFirst(args: EventData) { console.log("---> goToFirst Page"); diff --git a/e2e/ui-tests-app/app/css/elevation-page.ts b/e2e/ui-tests-app/app/css/elevation-page.ts index 7b149f746..d7b00e391 100644 --- a/e2e/ui-tests-app/app/css/elevation-page.ts +++ b/e2e/ui-tests-app/app/css/elevation-page.ts @@ -1,5 +1,5 @@ -import { Button } from "tns-core-modules/ui/button/button"; -import { EventData } from "tns-core-modules/ui/page/page"; +import { Button } from "tns-core-modules/ui/button"; +import { EventData } from "tns-core-modules/ui/page"; const states = [ { class: "", text: "default elevation" }, diff --git a/e2e/ui-tests-app/app/fonts-tests/button-page.ts b/e2e/ui-tests-app/app/fonts-tests/button-page.ts index 4cbc406c1..40247d793 100644 --- a/e2e/ui-tests-app/app/fonts-tests/button-page.ts +++ b/e2e/ui-tests-app/app/fonts-tests/button-page.ts @@ -1,11 +1,8 @@ -import * as stack from "tns-core-modules/ui/layouts/stack-layout"; -import { Button } from "@nativescript/core/ui/button"; -import * as view from "tns-core-modules/ui/core/view"; -import { unsetValue } from "tns-core-modules/ui/core/view"; +import { unsetValue, Button, View, StackLayout } from "@nativescript/core"; export function resetStyles(args) { - var stackLayout = args.object.parent.parent; - view.eachDescendant(stackLayout, function (v: view.View) { + var stackLayout = args.object.parent.parent; + view.eachDescendant(stackLayout, function (v: View) { v.style.fontFamily = unsetValue; v.style.fontSize = unsetValue; v.style.fontStyle = unsetValue; diff --git a/e2e/ui-tests-app/app/fonts-tests/label-page.ts b/e2e/ui-tests-app/app/fonts-tests/label-page.ts index bd26a6e28..cc1c68055 100644 --- a/e2e/ui-tests-app/app/fonts-tests/label-page.ts +++ b/e2e/ui-tests-app/app/fonts-tests/label-page.ts @@ -1,5 +1,4 @@ -import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout"; -import { View, unsetValue, eachDescendant } from "tns-core-modules/ui/core/view"; +import { View, unsetValue, eachDescendant, StackLayout } from "@nativescript/core"; export function resetStyles(args) { var stackLayout = args.object.parent; diff --git a/e2e/ui-tests-app/app/layouts/passThroughParent-page.ts b/e2e/ui-tests-app/app/layouts/passThroughParent-page.ts index 9e6d9d6ec..dc16d272b 100644 --- a/e2e/ui-tests-app/app/layouts/passThroughParent-page.ts +++ b/e2e/ui-tests-app/app/layouts/passThroughParent-page.ts @@ -1,5 +1,4 @@ -import { EventData, Page } from "tns-core-modules/ui/page/page"; -import { Label } from "tns-core-modules/ui/label/label"; +import { EventData, Page, Label } from "@nativescript/core"; const setLabelTextAndLog = (args, text: string) => { const page = args.object.page; diff --git a/e2e/ui-tests-app/app/tabs/custom-tabstrip-page.ts b/e2e/ui-tests-app/app/tabs/custom-tabstrip-page.ts index a845f682e..f5d9946f8 100644 --- a/e2e/ui-tests-app/app/tabs/custom-tabstrip-page.ts +++ b/e2e/ui-tests-app/app/tabs/custom-tabstrip-page.ts @@ -1,6 +1,4 @@ -import { EventData } from "tns-core-modules/data/observable"; -import { Page } from "tns-core-modules/ui/page"; -import { Tabs } from "tns-core-modules/ui/tabs"; +import { EventData, Page, Tabs } from "@nativescript/core"; export function goToFirst(args: EventData) { const page = (args.object).page; diff --git a/e2e/ui-tests-app/app/tabs/default-page.ts b/e2e/ui-tests-app/app/tabs/default-page.ts index 40a685667..033b8011a 100644 --- a/e2e/ui-tests-app/app/tabs/default-page.ts +++ b/e2e/ui-tests-app/app/tabs/default-page.ts @@ -1,6 +1,4 @@ -import { EventData } from "tns-core-modules/data/observable"; -import { Page } from "tns-core-modules/ui/page"; -import { Tabs } from "tns-core-modules/ui/tabs"; +import { EventData, Page, Tabs } from "@nativescript/core"; export function goToFirst(args: EventData) { const page = (args.object).page; diff --git a/e2e/ui-tests-app/app/tabs/dynamic-color-change-page.ts b/e2e/ui-tests-app/app/tabs/dynamic-color-change-page.ts index bf15cc6a2..94a2c6b40 100644 --- a/e2e/ui-tests-app/app/tabs/dynamic-color-change-page.ts +++ b/e2e/ui-tests-app/app/tabs/dynamic-color-change-page.ts @@ -1,6 +1,4 @@ -import { View } from "tns-core-modules/ui/core/view"; -import { Page } from "tns-core-modules/ui/page"; -import { Tabs } from "tns-core-modules/ui/tabs"; +import { View, Page, Tabs } from "@nativescript/core"; export function onButtonTap(args) { const page = (args.object).page; diff --git a/e2e/ui-tests-app/app/tabs/events-page.ts b/e2e/ui-tests-app/app/tabs/events-page.ts index aa049d535..b690921b4 100644 --- a/e2e/ui-tests-app/app/tabs/events-page.ts +++ b/e2e/ui-tests-app/app/tabs/events-page.ts @@ -1,6 +1,4 @@ -import { EventData } from "tns-core-modules/data/observable"; -import { Page } from "tns-core-modules/ui/page"; -import { Tabs, SelectedIndexChangedEventData } from "tns-core-modules/ui/tabs"; +import { EventData, Page, Tabs, SelectedIndexChangedEventData } from "@nativescript/core"; export function goToFirst(args: EventData) { console.log("---> goToFirst"); diff --git a/e2e/ui-tests-app/app/tabs/first-page.ts b/e2e/ui-tests-app/app/tabs/first-page.ts index 098ed4140..a4dfe3d94 100644 --- a/e2e/ui-tests-app/app/tabs/first-page.ts +++ b/e2e/ui-tests-app/app/tabs/first-page.ts @@ -1,5 +1,4 @@ -import { EventData } from "tns-core-modules/data/observable"; -import { Button } from "tns-core-modules/ui/button/button"; +import { EventData, Button } from "@nativescript/core"; export function goToSecond(args: EventData) { console.log("---> goToSecond Page"); diff --git a/e2e/ui-tests-app/app/tabs/icon-change-page.ts b/e2e/ui-tests-app/app/tabs/icon-change-page.ts index 892650e9d..a605caf8e 100644 --- a/e2e/ui-tests-app/app/tabs/icon-change-page.ts +++ b/e2e/ui-tests-app/app/tabs/icon-change-page.ts @@ -1,4 +1,4 @@ -import { Tabs, SelectedIndexChangedEventData } from "tns-core-modules/ui/tabs"; +import { Tabs, SelectedIndexChangedEventData } from "@nativescript/core"; export function onSelectedIndexChanged(args: SelectedIndexChangedEventData) { const tabsNav = args.object; diff --git a/e2e/ui-tests-app/app/tabs/main-page.ts b/e2e/ui-tests-app/app/tabs/main-page.ts index bfee3c3ab..04c83fd8b 100644 --- a/e2e/ui-tests-app/app/tabs/main-page.ts +++ b/e2e/ui-tests-app/app/tabs/main-page.ts @@ -1,6 +1,4 @@ -import { EventData } from "tns-core-modules/data/observable"; -import { WrapLayout } from "tns-core-modules/ui/layouts/wrap-layout"; -import { Page } from "tns-core-modules/ui/page"; +import { EventData, WrapLayout, Page } from "@nativescript/core"; import { SubMainPageViewModel } from "../sub-main-page-view-model"; diff --git a/e2e/ui-tests-app/app/tabs/reselect-page.ts b/e2e/ui-tests-app/app/tabs/reselect-page.ts index 012e393c8..7f52188a0 100644 --- a/e2e/ui-tests-app/app/tabs/reselect-page.ts +++ b/e2e/ui-tests-app/app/tabs/reselect-page.ts @@ -1,9 +1,4 @@ -import { EventData } from "tns-core-modules/data/observable"; -import { Frame } from "tns-core-modules/ui/frame/frame"; -import { Page } from "tns-core-modules/ui/page"; -import { - TabStripItemEventData, SelectedIndexChangedEventData, Tabs, TabStrip //, TabStripItem -} from "tns-core-modules/ui/tabs"; +import { EventData, Frame, Page, TabStripItemEventData, SelectedIndexChangedEventData, Tabs, TabStrip } from "@nativescript/core"; export function goToFirst(args: EventData) { console.log("---> goToFirst"); diff --git a/e2e/ui-tests-app/app/tabs/second-page.ts b/e2e/ui-tests-app/app/tabs/second-page.ts index cc6782463..0a8b653af 100644 --- a/e2e/ui-tests-app/app/tabs/second-page.ts +++ b/e2e/ui-tests-app/app/tabs/second-page.ts @@ -1,5 +1,4 @@ -import { EventData } from "tns-core-modules/data/observable"; -import { Button } from "tns-core-modules/ui/button/button"; +import { EventData, Button } from "@nativescript/core"; export function goToFirst(args: EventData) { console.log("---> goToFirst Page"); diff --git a/e2e/ui-tests-app/app/tabs/tabs-page.ts b/e2e/ui-tests-app/app/tabs/tabs-page.ts index 40a685667..033b8011a 100644 --- a/e2e/ui-tests-app/app/tabs/tabs-page.ts +++ b/e2e/ui-tests-app/app/tabs/tabs-page.ts @@ -1,6 +1,4 @@ -import { EventData } from "tns-core-modules/data/observable"; -import { Page } from "tns-core-modules/ui/page"; -import { Tabs } from "tns-core-modules/ui/tabs"; +import { EventData, Page, Tabs } from "@nativescript/core"; export function goToFirst(args: EventData) { const page = (args.object).page; diff --git a/e2e/ui-tests-app/app/text-field/focus-blur-events-page.ts b/e2e/ui-tests-app/app/text-field/focus-blur-events-page.ts index 4e8a43211..f98552f06 100644 --- a/e2e/ui-tests-app/app/text-field/focus-blur-events-page.ts +++ b/e2e/ui-tests-app/app/text-field/focus-blur-events-page.ts @@ -1,5 +1,4 @@ -import { TextField } from "tns-core-modules/ui/text-field"; -import { TextView } from "tns-core-modules/ui/text-view"; +import { TextField, TextView } from "@nativescript/core"; export function onLoaded(args) { const page = args.object; diff --git a/e2e/ui-tests-app/app/text-field/main-page.ts b/e2e/ui-tests-app/app/text-field/main-page.ts index c07d35c01..d54596a6b 100644 --- a/e2e/ui-tests-app/app/text-field/main-page.ts +++ b/e2e/ui-tests-app/app/text-field/main-page.ts @@ -1,7 +1,5 @@ -import { EventData } from "tns-core-modules/data/observable"; +import { EventData, WrapLayout, Page } from "@nativescript/core"; import { SubMainPageViewModel } from "../sub-main-page-view-model"; -import { WrapLayout } from "tns-core-modules/ui/layouts/wrap-layout"; -import { Page } from "tns-core-modules/ui/page"; export function pageLoaded(args: EventData) { const page = args.object; diff --git a/e2e/ui-tests-app/app/text-field/max-length-page.ts b/e2e/ui-tests-app/app/text-field/max-length-page.ts index b258fc7e4..784decaaa 100644 --- a/e2e/ui-tests-app/app/text-field/max-length-page.ts +++ b/e2e/ui-tests-app/app/text-field/max-length-page.ts @@ -1,5 +1,4 @@ -import { Page } from "tns-core-modules/ui/page"; -import { TextField } from "tns-core-modules/ui/text-field"; +import { Page, TextField } from "@nativescript/core"; export function setText(args) { let page = args; diff --git a/e2e/ui-tests-app/app/text-view/hint-text-color-page.ts b/e2e/ui-tests-app/app/text-view/hint-text-color-page.ts index 701548e1e..91744e8be 100644 --- a/e2e/ui-tests-app/app/text-view/hint-text-color-page.ts +++ b/e2e/ui-tests-app/app/text-view/hint-text-color-page.ts @@ -1,7 +1,4 @@ -import { Page } from "tns-core-modules/ui/page"; -import { unsetValue } from "tns-core-modules/ui/core/view"; -import { TextView } from "tns-core-modules/ui/text-view"; -import { TextField } from "tns-core-modules/ui/text-field"; +import { TextView, unsetValue, TextField, Page } from "@nativescript/core"; function exectuteOnAll(page: Page, callback: (txt: TextView | TextField) => void) { page.getViewById("container").eachChild((child) => { diff --git a/e2e/ui-tests-app/app/text-view/main-page.ts b/e2e/ui-tests-app/app/text-view/main-page.ts index 48ce1ef21..e7ec58962 100644 --- a/e2e/ui-tests-app/app/text-view/main-page.ts +++ b/e2e/ui-tests-app/app/text-view/main-page.ts @@ -1,7 +1,5 @@ -import { EventData } from "tns-core-modules/data/observable"; +import { EventData, WrapLayout, Page } from "@nativescript/core"; import { SubMainPageViewModel } from "../sub-main-page-view-model"; -import { WrapLayout } from "tns-core-modules/ui/layouts/wrap-layout"; -import { Page } from "tns-core-modules/ui/page"; export function pageLoaded(args: EventData) { const page = args.object; diff --git a/e2e/ui-tests-app/app/text-view/text-view-hint-color-page.ts b/e2e/ui-tests-app/app/text-view/text-view-hint-color-page.ts index 8d14b813f..355b6f35a 100644 --- a/e2e/ui-tests-app/app/text-view/text-view-hint-color-page.ts +++ b/e2e/ui-tests-app/app/text-view/text-view-hint-color-page.ts @@ -1,6 +1,4 @@ -import { Page } from "tns-core-modules/ui/page"; -import { TextView } from "tns-core-modules/ui/text-view"; -import { Color } from "tns-core-modules/color"; +import { Page, TextView, Color } from "@nativescript/core"; export function changeTextAndColor(args) { const page = args.object.page; diff --git a/e2e/ui-tests-app/package.json b/e2e/ui-tests-app/package.json index 086c744af..f04d286fd 100644 --- a/e2e/ui-tests-app/package.json +++ b/e2e/ui-tests-app/package.json @@ -5,7 +5,7 @@ "version": "next" }, "tns-ios": { - "version": "next" + "version": "6.6.0-alpha.2-ios14-2020-07-06-159403-01" } }, "main": "app.js", @@ -13,8 +13,8 @@ "license": "SEE LICENSE IN ", "repository": "", "dependencies": { - "@nativescript/core": "file:../../nativescript-core", - "tns-core-modules": "file:../../dist/tns-core-modules" + "@nativescript/core": "file:../../dist/nativescript-core-7.0.0-rc.6.tgz", + "@nativescript/core-widgets": "^7.0.0-rc.0" }, "devDependencies": { "@testdeck/mocha": "0.0.6", @@ -29,8 +29,8 @@ "mochawesome": "~3.1.2", "nativescript-dev-appium": "next", "@nativescript/webpack": "^2.0.0-alpha.3", - "tns-platform-declarations": "file:../../tns-platform-declarations", - "typescript": "~3.4.1" + "@nativescript/types": "file:../../dist/nativescript-types-7.0.0-rc.0.tgz", + "typescript": "~3.9.0" }, "gitHead": "8ab7726d1ee9991706069c1359c552e67ee0d1a4", "readme": "NativeScript Application", diff --git a/e2e/ui-tests-app/references.d.ts b/e2e/ui-tests-app/references.d.ts index c894da706..ba96c5b1b 100644 --- a/e2e/ui-tests-app/references.d.ts +++ b/e2e/ui-tests-app/references.d.ts @@ -1,2 +1,2 @@ -/// -/// +/// +/// diff --git a/e2e/ui-tests-app/tsconfig.json b/e2e/ui-tests-app/tsconfig.json index b20b00667..85bd97fea 100644 --- a/e2e/ui-tests-app/tsconfig.json +++ b/e2e/ui-tests-app/tsconfig.json @@ -5,7 +5,7 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true, "noEmitHelpers": true, - "noEmitOnError": true, + "noEmitOnError": false, "skipLibCheck": true, "lib": [ "es6", @@ -16,6 +16,9 @@ "~/*": [ "app/*" ], + "tns-core-modules/*": [ + "./node_modules/@nativescript/core/*" + ], "*": [ "./node_modules/*" ] diff --git a/e2e/ui-tests-app/webpack.config.js b/e2e/ui-tests-app/webpack.config.js index 7fd9e5013..eb85af082 100644 --- a/e2e/ui-tests-app/webpack.config.js +++ b/e2e/ui-tests-app/webpack.config.js @@ -1,9 +1,10 @@ const { join, relative, resolve, sep } = require("path"); const webpack = require("webpack"); -const nsWebpack = require("nativescript-dev-webpack"); -const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target"); -const CleanWebpackPlugin = require("clean-webpack-plugin"); +const nsWebpack = require("@nativescript/webpack"); +const nativescriptTarget = require("@nativescript/webpack/nativescript-target"); +const { getNoEmitOnErrorFromTSConfig } = require("@nativescript/webpack/utils/tsconfig-utils"); +const { CleanWebpackPlugin } = require("clean-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer"); @@ -13,12 +14,13 @@ const hashSalt = Date.now().toString(); module.exports = env => { // Add your custom Activities, Services and other Android app components here. - const appComponents = [ - "tns-core-modules/ui/frame", - "tns-core-modules/ui/frame/activity", - ]; + const appComponents = env.appComponents || []; + appComponents.push(...[ + "@nativescript/core/ui/frame", + "@nativescript/core/ui/frame/activity", + ]); - const platform = env && (env.android && "android" || env.ios && "ios"); + const platform = env && (env.android && "android" || env.ios && "ios" || env.platform); if (!platform) { throw new Error("You need to provide a target platform!"); } @@ -26,6 +28,10 @@ module.exports = env => { const platforms = ["ios", "android"]; const projectRoot = __dirname; + if (env.platform) { + platforms.push(env.platform); + } + // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform, projectRoot)); @@ -45,22 +51,39 @@ module.exports = env => { hmr, // --env.hmr, unitTesting, // --env.unitTesting, verbose, // --env.verbose + snapshotInDocker, // --env.snapshotInDocker + skipSnapshotTools, // --env.skipSnapshotTools + compileSnapshot // --env.compileSnapshot } = env; + + const useLibs = compileSnapshot; const isAnySourceMapEnabled = !!sourceMap || !!hiddenSourceMap; const externals = nsWebpack.getConvertedExternals(env.externals); const appFullPath = resolve(projectRoot, appPath); + const hasRootLevelScopedModules = nsWebpack.hasRootLevelScopedModules({ projectDir: projectRoot }); + let coreModulesPackageName = "tns-core-modules"; + const alias = env.alias || {}; + alias['~'] = appFullPath; + + if (hasRootLevelScopedModules) { + coreModulesPackageName = "@nativescript/core"; + alias["tns-core-modules"] = coreModulesPackageName; + } const appResourcesFullPath = resolve(projectRoot, appResourcesPath); + const copyIgnore = { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }; + const entryModule = nsWebpack.getEntryModule(appFullPath, platform); const entryPath = `.${sep}${entryModule}.ts`; - const entries = { bundle: entryPath }; + const entries = env.entries || {}; + entries.bundle = entryPath; const tsConfigPath = resolve(projectRoot, "tsconfig.tns.json"); - const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("tns-core-modules") > -1); + const areCoreModulesExternal = Array.isArray(env.externals) && env.externals.some(e => e.indexOf("@nativescript") > -1); if (platform === "ios" && !areCoreModulesExternal) { - entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules"; + entries["tns_modules/@nativescript/core/inspector_modules"] = "inspector_modules"; }; let sourceMapFilename = nsWebpack.getSourceMapFilename(hiddenSourceMap, __dirname, dist); @@ -71,6 +94,8 @@ module.exports = env => { itemsToClean.push(`${join(projectRoot, "platforms", "android", "app", "build", "configurations", "nativescript-android-snapshot")}`); } + const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig(tsConfigPath); + nsWebpack.processAppComponents(appComponents, platform); const config = { mode: production ? "production" : "development", @@ -96,16 +121,14 @@ module.exports = env => { }, resolve: { extensions: [".ts", ".js", ".scss", ".css"], - // Resolve {N} system modules from tns-core-modules + // Resolve {N} system modules from @nativescript/core modules: [ - resolve(__dirname, "node_modules/tns-core-modules"), + resolve(__dirname, `node_modules/${coreModulesPackageName}`), resolve(__dirname, "node_modules"), - "node_modules/tns-core-modules", + `node_modules/${coreModulesPackageName}`, "node_modules", ], - alias: { - '~': appFullPath - }, + alias, // resolve symlinks to symlinked modules symlinks: true }, @@ -124,6 +147,7 @@ module.exports = env => { devtool: hiddenSourceMap ? "hidden-source-map" : (sourceMap ? "inline-source-map" : "none"), optimization: { runtimeChunk: "single", + noEmitOnErrors: noEmitOnErrorFromTSConfig, splitChunks: { cacheGroups: { vendor: { @@ -167,12 +191,12 @@ module.exports = env => { use: [ // Require all Android app components platform === "android" && { - loader: "nativescript-dev-webpack/android-app-components-loader", + loader: "@nativescript/webpack/android-app-components-loader", options: { modules: appComponents } }, { - loader: "nativescript-dev-webpack/bundle-config-loader", + loader: "@nativescript/webpack/bundle-config-loader", options: { loadCss: !snapshot, // load the application css if in debug mode unitTesting, @@ -186,20 +210,20 @@ module.exports = env => { { test: /\.(ts|css|scss|html|xml)$/, - use: "nativescript-dev-webpack/hmr/hot-loader" + use: "@nativescript/webpack/hmr/hot-loader" }, - { test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader" }, + { test: /\.(html|xml)$/, use: "@nativescript/webpack/xml-namespace-loader" }, { test: /\.css$/, - use: { loader: "css-loader", options: { url: false } } + use: "@nativescript/webpack/css2json-loader" }, { test: /\.scss$/, use: [ - { loader: "css-loader", options: { url: false } }, + "@nativescript/webpack/css2json-loader", "sass-loader" ] }, @@ -230,15 +254,19 @@ module.exports = env => { "process": "global.process", }), // Remove all files from the out dir. - new CleanWebpackPlugin(itemsToClean, { verbose: !!verbose }), - // Copy assets to out dir. Add your own globs as needed. - new CopyWebpackPlugin([ - { from: { glob: "fonts/**" } }, - { from: { glob: "**/*.jpg" } }, - { from: { glob: "**/*.png" } }, - { from: { glob: "**/*.html" } }, - { from: { glob: "web-view/test.css" } }, - ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), + new CleanWebpackPlugin({ + cleanOnceBeforeBuildPatterns: itemsToClean, + verbose: !!verbose + }), + // Copy assets + new CopyWebpackPlugin({ + patterns: [ + { from: 'assets/**', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } }, + { from: 'fonts/**', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } }, + { from: '**/*.jpg', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } }, + { from: '**/*.png', noErrorOnMissing: true, globOptions: { dot: false, ...copyIgnore } }, + ], + }), new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"), // For instructions on how to set up workers with webpack // check out https://github.com/nativescript/worker-loader @@ -252,10 +280,15 @@ module.exports = env => { // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement new ForkTsCheckerWebpackPlugin({ - tsconfig: tsConfigPath, - async: false, - useTypescriptIncrementalApi: true, - memoryLimit: 4096 + async: false, + typescript: { + configFile: tsConfigPath, + memoryLimit: 4096, + diagnosticOptions: { + syntactic: true, + semantic: true + } + } }) ], }; @@ -275,10 +308,13 @@ module.exports = env => { config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({ chunk: "vendor", requireModules: [ - "tns-core-modules/bundle-entry-points", + "@nativescript/core/bundle-entry-points", ], projectRoot, webpackConfig: config, + snapshotInDocker, + skipSnapshotTools, + useLibs })); } diff --git a/nativescript-core/application/application-common.ts b/nativescript-core/application/application-common.ts index 14a4a0370..dfff5194e 100644 --- a/nativescript-core/application/application-common.ts +++ b/nativescript-core/application/application-common.ts @@ -1,5 +1,9 @@ // Require globals first so that snapshot takes __extends function. -import '../globals'; +// apply polyfills first +import { initGlobal } from '../globals'; +if (!(global).hasInitGlobal) { + initGlobal(); +} // Types import { AndroidApplication, iOSApplication } from '.'; diff --git a/nativescript-core/application/index.ios.ts b/nativescript-core/application/index.ios.ts index 598fd58e7..efca38b04 100644 --- a/nativescript-core/application/index.ios.ts +++ b/nativescript-core/application/index.ios.ts @@ -1,14 +1,14 @@ // Types import { iOSApplication as iOSApplicationDefinition } from '.'; import { ApplicationEventData, CssChangedEventData, LaunchEventData, LoadAppCSSEventData, OrientationChangedEventData, SystemAppearanceChangedEventData } from './application-interfaces'; -import { View } from '../ui/core/view'; -import { NavigationEntry } from '../ui/frame/frame-interfaces'; // Require import { displayedEvent, exitEvent, getCssFileName, launchEvent, livesync, lowMemoryEvent, notify, on, orientationChanged, orientationChangedEvent, resumeEvent, setApplication, suspendEvent, systemAppearanceChanged, systemAppearanceChangedEvent } from './application-common'; // First reexport so that app module is initialized. export * from './application-common'; +import { View } from '../ui/core/view'; +import { NavigationEntry } from '../ui/frame/frame-interfaces'; // TODO: Remove this and get it from global to decouple builder for angular import { Builder } from '../ui/builder'; import { CLASS_PREFIX, getSystemCssClasses, pushToSystemCssClasses, ROOT_VIEW_CSS_CLASS } from '../css/system-classes'; diff --git a/nativescript-core/globals/core.ts b/nativescript-core/globals/core.ts deleted file mode 100644 index cbf87e2cc..000000000 --- a/nativescript-core/globals/core.ts +++ /dev/null @@ -1,36 +0,0 @@ -// Required by TypeScript compiler -import './ts-helpers'; -import './register-module-helpers'; - -// This method iterates all the keys in the source exports object and copies them to the destination exports one. -// Note: the method will not check for naming collisions and will override any already existing entries in the destination exports. -global.moduleMerge = function (sourceExports: any, destExports: any) { - for (let key in sourceExports) { - destExports[key] = sourceExports[key]; - } -}; - -global.zonedCallback = function (callback: Function): Function { - if ((global).zone) { - // Zone v0.5.* style callback wrapping - return (global).zone.bind(callback); - } - if ((global).Zone) { - // Zone v0.6.* style callback wrapping - return (global).Zone.current.wrap(callback); - } else { - return callback; - } -}; - -(global).System = { - import(path) { - return new Promise((resolve, reject) => { - try { - resolve(global.require(path)); - } catch (e) { - reject(e); - } - }); - }, -}; diff --git a/nativescript-core/globals/decorators.ts b/nativescript-core/globals/decorators.ts deleted file mode 100644 index bc99ffcfe..000000000 --- a/nativescript-core/globals/decorators.ts +++ /dev/null @@ -1,39 +0,0 @@ -export function Deprecated(target: Object, key?: string | symbol, descriptor?: any) { - if (descriptor) { - const originalMethod = descriptor.value; - - descriptor.value = function (...args: any[]) { - console.log(`${key.toString()} is deprecated`); - - return originalMethod.apply(this, args); - }; - - return descriptor; - } else { - console.log(`${(target && (target).name) || target} is deprecated`); - - return target; - } -} - -global.Deprecated = Deprecated; - -export function Experimental(target: Object, key?: string | symbol, descriptor?: any) { - if (descriptor) { - const originalMethod = descriptor.value; - - descriptor.value = function (...args: any[]) { - console.log(`${key.toString()} is experimental`); - - return originalMethod.apply(this, args); - }; - - return descriptor; - } else { - console.log(`${(target && (target).name) || target} is experimental`); - - return target; - } -} - -global.Experimental = Experimental; diff --git a/nativescript-core/globals/index.d.ts b/nativescript-core/globals/index.d.ts index 3653fc9d0..c1ea0392a 100644 --- a/nativescript-core/globals/index.d.ts +++ b/nativescript-core/globals/index.d.ts @@ -1,3 +1,2 @@ -export declare var hasInitGlobal: boolean; export function installPolyfills(moduleName: string, exportNames: string[]): void; export function initGlobal(): void; diff --git a/nativescript-core/globals/index.ts b/nativescript-core/globals/index.ts index b08f63890..efb442363 100644 --- a/nativescript-core/globals/index.ts +++ b/nativescript-core/globals/index.ts @@ -1,4 +1,15 @@ -export let hasInitGlobal = false; +import * as tslib from 'tslib'; + +type ModuleLoader = (name?: string) => any; + +interface Context { + keys(): string[]; + (key: string): any; +} + +interface ExtensionMap { + [originalFileExtension: string]: string; +} function registerOnGlobalContext(moduleName: string, exportName: string): void { Object.defineProperty(global, exportName, { @@ -30,11 +41,195 @@ export function installPolyfills(moduleName: string, exportNames: string[]) { } export function initGlobal() { - console.log('initPolyfills called, init:', hasInitGlobal); - if (!hasInitGlobal) { - hasInitGlobal = true; - // apply global polyfills first - require('./core'); + console.log('initGlobal called, init:', (global).hasInitGlobal); + if (!(global).hasInitGlobal) { + (global).hasInitGlobal = true; + // ts-helpers + // Required by V8 snapshot generator + if (!(global).__extends) { + (global).__extends = function (d, b) { + for (let p in b) { + if (b.hasOwnProperty(p)) { + d[p] = b[p]; + } + } + function __() { + this.constructor = d; + } + d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __()); + }; + } + + // Bind the tslib helpers to global scope. + // This is needed when we don't use importHelpers, which + // breaks extending native-classes + for (const fnName of Object.keys(tslib)) { + if (typeof tslib[fnName] !== 'function') { + continue; + } + + if (fnName in global) { + // Don't override globals that are already defined (ex. __extends) + continue; + } + + global[fnName] = tslib[fnName]; + } + + // module helpers + const modules: Map = new Map(); + const modulesLoadedForUI = new Set(); + const defaultExtensionMap: ExtensionMap = { + '.js': '.js', + '.ts': '.js', + '.kt': '.js', + '.css': '.css', + '.scss': '.css', + '.less': '.css', + '.sass': '.css', + '.xml': '.xml', + }; + + // Cast to because moduleResolvers is read-only in definitions + (global).moduleResolvers = [global.require]; + + global.registerModule = function (name: string, loader: ModuleLoader): void { + modules.set(name, { loader, moduleId: name }); + }; + + global._unregisterModule = function _unregisterModule(name: string): void { + modules.delete(name); + }; + + global._isModuleLoadedForUI = function _isModuleLoadedForUI(moduleName: string): boolean { + return modulesLoadedForUI.has(moduleName); + }; + + global.registerWebpackModules = function registerWebpackModules(context: Context, extensionMap: ExtensionMap = {}) { + context.keys().forEach((moduleId) => { + const extDotIndex = moduleId.lastIndexOf('.'); + const base = moduleId.substr(0, extDotIndex); + const originalExt = moduleId.substr(extDotIndex); + const registerExt = extensionMap[originalExt] || defaultExtensionMap[originalExt] || originalExt; + + // We prefer source files for webpack scenarios before compilation leftovers, + // e. g. if we get a .js and .ts for the same module, the .js is probably the compiled version of the .ts file, + // so we register the .ts with higher priority, similar is the case with us preferring the .scss to .css + const isSourceFile = originalExt !== registerExt; + const registerName = base + registerExt; + + const registerWithName = (nickName: string) => { + modules.set(nickName, { + moduleId, + loader: () => { + return context(moduleId); + }, + }); + }; + + if (registerName.startsWith('./') && registerName.endsWith('.js')) { + const jsNickNames = [ + // This is extremely short version like "main-page" that was promoted to be used with global.registerModule("module-name", loaderFunc); + registerName.substr(2, registerName.length - 5), + // This is for supporting module names like "./main/main-page" + registerName.substr(0, registerName.length - 3), + // This is for supporting module names like "main/main-page.js" + registerName.substr(2), + ]; + + jsNickNames.forEach((jsNickName) => { + if (isSourceFile || !global.moduleExists(jsNickName)) { + registerWithName(jsNickName); + } + }); + } else if (registerName.startsWith('./')) { + const moduleNickNames = [ + // This is for supporting module names like "main/main-page.xml" + registerName.substr(2), + ]; + + moduleNickNames.forEach((moduleNickName) => { + if (!global.moduleExists(moduleNickName)) { + registerWithName(moduleNickName); + } + }); + } + + if (isSourceFile || !global.moduleExists(registerName)) { + registerWithName(registerName); + } + }); + }; + + global.moduleExists = function moduleExists(name: string): boolean { + return modules.has(name); + }; + + global.loadModule = function loadModule(name: string, isUIModule: boolean = false): any { + const moduleInfo = modules.get(name); + if (moduleInfo) { + if (isUIModule) { + modulesLoadedForUI.add(moduleInfo.moduleId); + } + + const result = moduleInfo.loader(name); + + if (result.enableAutoAccept) { + result.enableAutoAccept(); + } + + return result; + } + + for (let resolver of (global).moduleResolvers) { + const result = resolver(name); + if (result) { + modules.set(name, { moduleId: name, loader: () => result }); + + return result; + } + } + }; + + global.getRegisteredModules = function getRegisteredModules(): string[] { + return Array.from(modules.keys()); + }; + + /** + * Polyfills + */ + // This method iterates all the keys in the source exports object and copies them to the destination exports one. + // Note: the method will not check for naming collisions and will override any already existing entries in the destination exports. + global.moduleMerge = function (sourceExports: any, destExports: any) { + for (let key in sourceExports) { + destExports[key] = sourceExports[key]; + } + }; + + global.zonedCallback = function (callback: Function): Function { + if ((global).zone) { + // Zone v0.5.* style callback wrapping + return (global).zone.bind(callback); + } + if ((global).Zone) { + // Zone v0.6.* style callback wrapping + return (global).Zone.current.wrap(callback); + } else { + return callback; + } + }; + + (global).System = { + import(path) { + return new Promise((resolve, reject) => { + try { + resolve(global.require(path)); + } catch (e) { + reject(e); + } + }); + }, + }; // DOM api polyfills global.registerModule('timer', () => require('../timer')); @@ -56,6 +251,41 @@ export function initGlobal() { installPolyfills('fetch', ['fetch', 'Headers', 'Request', 'Response']); // Custom decorators - require('./decorators'); + + global.Deprecated = function (target: Object, key?: string | symbol, descriptor?: any) { + if (descriptor) { + const originalMethod = descriptor.value; + + descriptor.value = function (...args: any[]) { + console.log(`${key.toString()} is deprecated`); + + return originalMethod.apply(this, args); + }; + + return descriptor; + } else { + console.log(`${(target && (target).name) || target} is deprecated`); + + return target; + } + }; + + global.Experimental = function (target: Object, key?: string | symbol, descriptor?: any) { + if (descriptor) { + const originalMethod = descriptor.value; + + descriptor.value = function (...args: any[]) { + console.log(`${key.toString()} is experimental`); + + return originalMethod.apply(this, args); + }; + + return descriptor; + } else { + console.log(`${(target && (target).name) || target} is experimental`); + + return target; + } + }; } } diff --git a/nativescript-core/globals/register-module-helpers.ts b/nativescript-core/globals/register-module-helpers.ts deleted file mode 100644 index f3bbaab94..000000000 --- a/nativescript-core/globals/register-module-helpers.ts +++ /dev/null @@ -1,128 +0,0 @@ -type ModuleLoader = (name?: string) => any; - -interface Context { - keys(): string[]; - (key: string): any; -} - -interface ExtensionMap { - [originalFileExtension: string]: string; -} - -const modules: Map = new Map(); -const modulesLoadedForUI = new Set(); -const defaultExtensionMap: ExtensionMap = { - '.js': '.js', - '.ts': '.js', - '.kt': '.js', - '.css': '.css', - '.scss': '.css', - '.less': '.css', - '.sass': '.css', - '.xml': '.xml', -}; - -// Cast to because moduleResolvers is read-only in definitions -(global).moduleResolvers = [global.require]; - -global.registerModule = function (name: string, loader: ModuleLoader): void { - modules.set(name, { loader, moduleId: name }); -}; - -global._unregisterModule = function _unregisterModule(name: string): void { - modules.delete(name); -}; - -global._isModuleLoadedForUI = function _isModuleLoadedForUI(moduleName: string): boolean { - return modulesLoadedForUI.has(moduleName); -}; - -global.registerWebpackModules = function registerWebpackModules(context: Context, extensionMap: ExtensionMap = {}) { - context.keys().forEach((moduleId) => { - const extDotIndex = moduleId.lastIndexOf('.'); - const base = moduleId.substr(0, extDotIndex); - const originalExt = moduleId.substr(extDotIndex); - const registerExt = extensionMap[originalExt] || defaultExtensionMap[originalExt] || originalExt; - - // We prefer source files for webpack scenarios before compilation leftovers, - // e. g. if we get a .js and .ts for the same module, the .js is probably the compiled version of the .ts file, - // so we register the .ts with higher priority, similar is the case with us preferring the .scss to .css - const isSourceFile = originalExt !== registerExt; - const registerName = base + registerExt; - - const registerWithName = (nickName: string) => { - modules.set(nickName, { - moduleId, - loader: () => { - return context(moduleId); - }, - }); - }; - - if (registerName.startsWith('./') && registerName.endsWith('.js')) { - const jsNickNames = [ - // This is extremely short version like "main-page" that was promoted to be used with global.registerModule("module-name", loaderFunc); - registerName.substr(2, registerName.length - 5), - // This is for supporting module names like "./main/main-page" - registerName.substr(0, registerName.length - 3), - // This is for supporting module names like "main/main-page.js" - registerName.substr(2), - ]; - - jsNickNames.forEach((jsNickName) => { - if (isSourceFile || !global.moduleExists(jsNickName)) { - registerWithName(jsNickName); - } - }); - } else if (registerName.startsWith('./')) { - const moduleNickNames = [ - // This is for supporting module names like "main/main-page.xml" - registerName.substr(2), - ]; - - moduleNickNames.forEach((moduleNickName) => { - if (!global.moduleExists(moduleNickName)) { - registerWithName(moduleNickName); - } - }); - } - - if (isSourceFile || !global.moduleExists(registerName)) { - registerWithName(registerName); - } - }); -}; - -global.moduleExists = function moduleExists(name: string): boolean { - return modules.has(name); -}; - -global.loadModule = function loadModule(name: string, isUIModule: boolean = false): any { - const moduleInfo = modules.get(name); - if (moduleInfo) { - if (isUIModule) { - modulesLoadedForUI.add(moduleInfo.moduleId); - } - - const result = moduleInfo.loader(name); - - if (result.enableAutoAccept) { - result.enableAutoAccept(); - } - - return result; - } - - for (let resolver of (global).moduleResolvers) { - const result = resolver(name); - if (result) { - modules.set(name, { moduleId: name, loader: () => result }); - - return result; - } - } -}; - -global.getRegisteredModules = function getRegisteredModules(): string[] { - return Array.from(modules.keys()); -}; diff --git a/nativescript-core/globals/ts-helpers.ts b/nativescript-core/globals/ts-helpers.ts deleted file mode 100644 index 56446d0b3..000000000 --- a/nativescript-core/globals/ts-helpers.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Required by V8 snapshot generator -if (!global.__extends) { - global.__extends = function (d, b) { - for (let p in b) { - if (b.hasOwnProperty(p)) { - d[p] = b[p]; - } - } - function __() { - this.constructor = d; - } - d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __()); - }; -} - -import * as tslib from 'tslib'; - -// Bind the tslib helpers to global scope. -// This is needed when we don't use importHelpers, which -// breaks extending native-classes -for (const fnName of Object.keys(tslib)) { - if (typeof tslib[fnName] !== 'function') { - continue; - } - - if (fnName in global) { - // Don't override globals that are already defined (ex. __extends) - continue; - } - - global[fnName] = tslib[fnName]; -} diff --git a/nativescript-core/index.d.ts b/nativescript-core/index.d.ts index 18f83f8e7..e53bb6d50 100644 --- a/nativescript-core/index.d.ts +++ b/nativescript-core/index.d.ts @@ -27,6 +27,32 @@ export declare const Application: { hasLaunched: typeof hasLaunched; android: AndroidApplication; ios: iOSApplication; +} = { + launchEvent: 'launch', + displayedEvent: 'displayed', + uncaughtErrorEvent: 'uncaughtError', + discardedErrorEvent: 'discardedError', + suspendEvent: 'suspend', + resumeEvent: 'resume', + exitEvent: 'exit', + lowMemoryEvent: 'lowMemory', + orientationChangedEvent: 'orientationChanged', + getMainEntry, + getRootView, + resetRootView, + setResources, + setCssFileName, + getCssFileName, + loadAppCss, + addCss, + on, + off, + run, + orientation, + getNativeApplication, + hasLaunched, + android, + ios, }; import { setString, getString, clear, flush, getAllKeys, getBoolean, getNumber, hasKey, remove, setBoolean, setNumber } from './application-settings'; export declare const ApplicationSettings: { @@ -41,6 +67,18 @@ export declare const ApplicationSettings: { setBoolean: typeof setBoolean; getNumber: typeof getNumber; setNumber: typeof setNumber; +} = { + clear, + flush, + hasKey, + remove, + setString, + getString, + getAllKeys, + getBoolean, + setBoolean, + getNumber, + setNumber, }; export { Color } from './color'; import { connectionType, getConnectionType, startMonitoring, stopMonitoring } from './connectivity'; @@ -49,6 +87,11 @@ export declare const Connectivity: { getConnectionType: typeof getConnectionType; startMonitoring: typeof startMonitoring; stopMonitoring: typeof stopMonitoring; +} = { + connectionType, + getConnectionType, + startMonitoring, + stopMonitoring, }; export { ObservableArray, ChangeType, ChangedData } from './data/observable-array'; export { Observable, PropertyChangeData, EventData } from './data/observable'; @@ -62,6 +105,12 @@ export declare const Http: { getJSON: typeof getJSON; getString: typeof httpGetString; request: typeof request; +} = { + getFile, + getImage, + getJSON, + getString, + request, }; export { ImageAsset, ImageAssetOptions } from './image-asset'; export { ImageSource } from './image-source'; @@ -81,6 +130,19 @@ export declare const Profiling: { profile: typeof profile; startCPUProfile: typeof startCPUProfile; stopCPUProfile: typeof stopCPUProfile; +} = { + enable: profilingEnable, + disable: profilingDisable, + time, + uptime, + start, + stop, + isRunning, + dumpProfiles, + resetProfiles, + profile, + startCPUProfile, + stopCPUProfile, }; export { encoding } from './text'; export * from './trace'; @@ -104,5 +166,22 @@ export declare const Utils: { layout: typeof layout; android: typeof androidUtils; ios: typeof iosUtils; +} = { + GC, + isFontIconURI, + isDataURI, + isFileOrResourcePath, + executeOnMainThread, + mainThreadify, + isMainThread, + dispatchToMainThread, + releaseNativeObject, + getModuleName, + openFile, + openUrl, + isRealDevice, + layout, + android, + ios, }; export { XmlParser, ParserEventType, ParserEvent } from './xml'; diff --git a/nativescript-core/index.ts b/nativescript-core/index.ts index f3bc48d62..321b33253 100644 --- a/nativescript-core/index.ts +++ b/nativescript-core/index.ts @@ -1,8 +1,8 @@ /// -// apply polyfills first -import { initGlobal, hasInitGlobal } from './globals'; -if (!hasInitGlobal) { +// Init globals first +import { initGlobal } from './globals'; +if (!(global).hasInitGlobal) { initGlobal(); } diff --git a/nativescript-core/inspector_modules.ios.ts b/nativescript-core/inspector_modules.ios.ts index 4b0d0f2af..894512e90 100644 --- a/nativescript-core/inspector_modules.ios.ts +++ b/nativescript-core/inspector_modules.ios.ts @@ -1,5 +1,8 @@ console.log('Loading inspector modules...'); -require('./globals/ts-helpers'); +import { initGlobal } from './globals'; +if (!(global).hasInitGlobal) { + initGlobal(); +} require('./debugger/webinspector-network'); require('./debugger/webinspector-dom'); require('./debugger/webinspector-css'); diff --git a/nativescript-core/package.json b/nativescript-core/package.json index b64653fd3..a2484a0c1 100644 --- a/nativescript-core/package.json +++ b/nativescript-core/package.json @@ -3,7 +3,7 @@ "main": "index", "types": "index.d.ts", "description": "NativeScript Core Modules", - "version": "7.0.0-rc.2", + "version": "7.0.0-rc.6", "homepage": "https://www.nativescript.org", "repository": { "type": "git", diff --git a/nativescript-core/ui/bottom-navigation/index.ios.ts b/nativescript-core/ui/bottom-navigation/index.ios.ts index bea9550b8..057fcf756 100644 --- a/nativescript-core/ui/bottom-navigation/index.ios.ts +++ b/nativescript-core/ui/bottom-navigation/index.ios.ts @@ -9,7 +9,7 @@ import { Color } from '../../color'; import { ImageSource } from '../../image-source'; import { Device } from '../../platform'; import { ios as iosUtils, isFontIconURI, layout } from '../../utils'; -import { CSSType, ios as iosView, View } from '../core/view'; +import { CSSType, IOSHelper, View } from '../core/view'; import { Frame } from '../frame'; import { Font } from '../styling/font'; import { getIconSpecSize, itemsProperty, selectedIndexProperty, TabNavigationBase, tabStripProperty } from '../tab-navigation-base/tab-navigation-base'; @@ -44,7 +44,7 @@ class UITabBarControllerImpl extends UITabBarController { // Unify translucent and opaque bars layout this.extendedLayoutIncludesOpaqueBars = true; - iosView.updateAutoAdjustScrollInsets(this, owner); + IOSHelper.updateAutoAdjustScrollInsets(this, owner); if (!owner.parent) { owner.callLoaded(); @@ -86,7 +86,7 @@ class UITabBarControllerImpl extends UITabBarController { const owner = this._owner.get(); if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) { owner.notify({ - eventName: iosView.traitCollectionColorAppearanceChangedEvent, + eventName: IOSHelper.traitCollectionColorAppearanceChangedEvent, object: owner, }); } @@ -540,7 +540,7 @@ export class BottomNavigation extends TabNavigationBase { newController = item.content.ios.controller; (item).setViewController(newController, newController.view); } else { - newController = iosView.UILayoutViewController.initWithOwner(new WeakRef(item.content)) as UIViewController; + newController = IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(item.content)) as UIViewController; newController.view.addSubview(item.content.nativeViewProtected); item.content.viewController = newController; (item).setViewController(newController, item.content.nativeViewProtected); diff --git a/nativescript-core/ui/builder/component-builder/component-builder.d.ts b/nativescript-core/ui/builder/component-builder/index.d.ts similarity index 100% rename from nativescript-core/ui/builder/component-builder/component-builder.d.ts rename to nativescript-core/ui/builder/component-builder/index.d.ts diff --git a/nativescript-core/ui/builder/component-builder/component-builder.ts b/nativescript-core/ui/builder/component-builder/index.ts similarity index 98% rename from nativescript-core/ui/builder/component-builder/component-builder.ts rename to nativescript-core/ui/builder/component-builder/index.ts index 78d4d8dc3..83cd21560 100644 --- a/nativescript-core/ui/builder/component-builder/component-builder.ts +++ b/nativescript-core/ui/builder/component-builder/index.ts @@ -1,5 +1,4 @@ // Definitions. -import { ComponentModule } from '.'; import { View } from '../../core/view'; // Types. @@ -11,6 +10,11 @@ import { Device } from '../../../platform'; import { sanitizeModuleName } from '../module-name-sanitizer'; import { resolveModuleName } from '../../../module-name-resolver'; +export interface ComponentModule { + component: View; + exports: any; +} + const UI_PATH = 'ui/'; const MODULES = { TabViewItem: 'ui/tab-view', @@ -156,7 +160,7 @@ export function getComponentModule(elementName: string, namespace: string, attri applyComponentCss(instance, moduleNamePath, attributes); } - applyComponentAttributes(instance, instanceModule, moduleExports); + applyComponentAttributes(instance, instanceModule, moduleExports, attributes); let componentModule; if (instance && instanceModule) { diff --git a/nativescript-core/ui/builder/component-builder/package.json b/nativescript-core/ui/builder/component-builder/package.json deleted file mode 100644 index dc505b879..000000000 --- a/nativescript-core/ui/builder/component-builder/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "component-builder", - "main": "component-builder", - "types": "component-builder.d.ts" -} diff --git a/nativescript-core/ui/core/view/index.d.ts b/nativescript-core/ui/core/view/index.d.ts index 77af158c0..791986806 100644 --- a/nativescript-core/ui/core/view/index.d.ts +++ b/nativescript-core/ui/core/view/index.d.ts @@ -7,6 +7,9 @@ import { HorizontalAlignment, VerticalAlignment, Visibility, Length, PercentLeng import { GestureTypes, GestureEventData, GesturesObserver } from '../../gestures'; import { LinearGradient } from '../../styling/gradient'; +// helpers (these are okay re-exported here) +export * from './view-helper'; + export function PseudoClassHandler(...pseudoClasses: string[]): MethodDecorator; /** @@ -854,26 +857,3 @@ export const isEnabledProperty: Property; export const isUserInteractionEnabledProperty: Property; export const iosOverflowSafeAreaProperty: Property; export const iosOverflowSafeAreaEnabledProperty: InheritedProperty; - -export namespace ios { - /** - * String value used when hooking to traitCollectionColorAppearanceChangedEvent event. - */ - export const traitCollectionColorAppearanceChangedEvent: string; - - /** - * Returns a view with viewController or undefined if no such found along the view's parent chain. - * @param view The view form which to start the search. - */ - export function getParentWithViewController(view: View): View; - export function updateAutoAdjustScrollInsets(controller: any /* UIViewController */, owner: View): void; - export function updateConstraints(controller: any /* UIViewController */, owner: View): void; - export function layoutView(controller: any /* UIViewController */, owner: View): void; - export function getPositionFromFrame(frame: any /* CGRect */): { left; top; right; bottom }; - export function getFrameFromPosition(position: { left; top; right; bottom }, insets?: { left; top; right; bottom }): any; /* CGRect */ - export function shrinkToSafeArea(view: View, frame: any /* CGRect */): any; /* CGRect */ - export function expandBeyondSafeArea(view: View, frame: any /* CGRect */): any; /* CGRect */ - export class UILayoutViewController { - public static initWithOwner(owner: WeakRef): UILayoutViewController; - } -} diff --git a/nativescript-core/ui/core/view/view-common.ts b/nativescript-core/ui/core/view/view-common.ts index 2e279e65e..986a96086 100644 --- a/nativescript-core/ui/core/view/view-common.ts +++ b/nativescript-core/ui/core/view/view-common.ts @@ -24,6 +24,9 @@ import { TextTransform } from '../../text-base'; import * as am from '../../animation'; +// helpers (these are okay re-exported here) +export * from './view-helper'; + let animationModule: typeof am; function ensureAnimationModule() { if (!animationModule) { @@ -166,7 +169,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { } let handled = false; - this.eachChildView((child) => { + this.eachChildView((child: ViewCommon) => { if (child._onLivesync(context)) { handled = true; diff --git a/nativescript-core/ui/core/view/view-helper/index.d.ts b/nativescript-core/ui/core/view/view-helper/index.d.ts index d38a4af26..5a90b7a61 100644 --- a/nativescript-core/ui/core/view/view-helper/index.d.ts +++ b/nativescript-core/ui/core/view/view-helper/index.d.ts @@ -33,6 +33,9 @@ export class ViewHelper { public static combineMeasuredStates(curState: number, newState): number; } +/** + * Various iOS view helper methods + */ export namespace IOSHelper { /** * String value used when hooking to traitCollectionColorAppearanceChangedEvent event. diff --git a/nativescript-core/ui/dialogs/index.ios.ts b/nativescript-core/ui/dialogs/index.ios.ts index 459c9bf8c..c1c35c192 100644 --- a/nativescript-core/ui/dialogs/index.ios.ts +++ b/nativescript-core/ui/dialogs/index.ios.ts @@ -1,7 +1,6 @@ /** * iOS specific dialogs functions implementation. */ -import { ios as iosView } from '../core/view'; import { Trace } from '../../trace'; import { ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions, getCurrentPage, getLabelColor, getButtonColors, getTextFieldColor, isDialogOptions, inputType, capitalizationType, DialogStrings, parseLoginOptions } from './dialogs-common'; import { isString, isDefined, isFunction } from '../../utils/types'; diff --git a/nativescript-core/ui/editable-text-base/editable-text-base-common.ts b/nativescript-core/ui/editable-text-base/editable-text-base-common.ts index 716e84aea..4d2f37aa3 100644 --- a/nativescript-core/ui/editable-text-base/editable-text-base-common.ts +++ b/nativescript-core/ui/editable-text-base/editable-text-base-common.ts @@ -1,10 +1,11 @@ -import { EditableTextBase as EditableTextBaseDefinition, KeyboardType, ReturnKeyType, UpdateTextTrigger, AutocapitalizationType } from '.'; +import { EditableTextBase as EditableTextBaseDefinition, ReturnKeyType, UpdateTextTrigger, AutocapitalizationType } from '.'; import { TextBase } from '../text-base'; import { Property, CssProperty, makeValidator, makeParser } from '../core/properties'; import { PseudoClassHandler } from '../core/view'; import { booleanConverter } from '../core/view-base'; import { Style } from '../styling/style'; import { Color } from '../../color'; +import { KeyboardType } from '../enums'; export abstract class EditableTextBase extends TextBase implements EditableTextBaseDefinition { public static blurEvent = 'blur'; diff --git a/nativescript-core/ui/editable-text-base/index.d.ts b/nativescript-core/ui/editable-text-base/index.d.ts index f52bdb4b6..bb01a3f6b 100644 --- a/nativescript-core/ui/editable-text-base/index.d.ts +++ b/nativescript-core/ui/editable-text-base/index.d.ts @@ -3,6 +3,7 @@ import { Color } from '../../color'; import { FormattedString } from '../text-base/formatted-string'; import { Style } from '../styling/style'; import { Property, CssProperty } from '../core/properties'; +import { KeyboardType } from '../enums'; /** * Represents the base class for all editable text views. @@ -65,7 +66,6 @@ export class EditableTextBase extends TextBase { //@endprivate } -export type KeyboardType = 'datetime' | 'phone' | 'number' | 'url' | 'email' | 'integer'; export type ReturnKeyType = 'done' | 'next' | 'go' | 'search' | 'send'; export type UpdateTextTrigger = 'focusLost' | 'textChanged'; export type AutocapitalizationType = 'none' | 'words' | 'sentences' | 'allcharacters'; @@ -86,5 +86,3 @@ export const maxLengthProperty: Property; */ export function _updateCharactersInRangeReplacementString(formattedText: FormattedString, rangeLocation: number, rangeLength: number, replacementString: string): void; //@endprivate - -export * from '../text-base'; diff --git a/nativescript-core/ui/enums/index.d.ts b/nativescript-core/ui/enums/index.d.ts index 59758e5df..b1abc78d9 100644 --- a/nativescript-core/ui/enums/index.d.ts +++ b/nativescript-core/ui/enums/index.d.ts @@ -1,5 +1,5 @@ import { CubicBezierAnimationCurve } from '../animation'; -import { KeyboardType as BaseKeyboardType, ReturnKeyType as BaseReturnKeyType, UpdateTextTrigger as BaseUpdateTrigger, AutocapitalizationType as BaseAutocapitalizationType } from '../editable-text-base'; +import { ReturnKeyType as BaseReturnKeyType, UpdateTextTrigger as BaseUpdateTrigger, AutocapitalizationType as BaseAutocapitalizationType } from '../editable-text-base'; import { WhiteSpace as BaseWhiteSpace, TextAlignment as BaseTextAlignment, TextTransform as BaseTextTransform, TextDecoration as BaseTextDecoration } from '../text-base'; @@ -13,6 +13,7 @@ import { Stretch as BaseStretch } from '../image'; import { FontStyle as BaseFontStyle, FontWeight as BaseFontWeight } from '../styling/font-common'; +export type KeyboardType = 'datetime' | 'phone' | 'number' | 'url' | 'email' | 'integer'; /** * Represents a soft keyboard flavor. */ @@ -21,36 +22,36 @@ export module KeyboardType { * Android: [TYPE_CLASS_DATETIME](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_DATETIME) | [TYPE_DATETIME_VARIATION_NORMAL](http://developer.android.com/reference/android/text/InputType.html#TYPE_DATETIME_VARIATION_NORMAL) * iOS: [UIKeyboardTypeNumbersAndPunctuation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export const datetime: BaseKeyboardType; + export const datetime: KeyboardType; /** * Android: [TYPE_CLASS_PHONE](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_PHONE) * iOS: [UIKeyboardTypePhonePad](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export const phone: BaseKeyboardType; + export const phone: KeyboardType; /** * Android: [TYPE_CLASS_NUMBER](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_NUMBER) | [TYPE_NUMBER_VARIATION_NORMAL](http://developer.android.com/intl/es/reference/android/text/InputType.html#TYPE_NUMBER_VARIATION_NORMAL) | [TYPE_NUMBER_FLAG_SIGNED](http://developer.android.com/reference/android/text/InputType.html#TYPE_NUMBER_FLAG_SIGNED) | [TYPE_NUMBER_FLAG_DECIMAL](http://developer.android.com/reference/android/text/InputType.html#TYPE_NUMBER_FLAG_DECIMAL) * iOS: [UIKeyboardTypeNumbersAndPunctuation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export const number: BaseKeyboardType; + export const number: KeyboardType; /** * Android: [TYPE_CLASS_TEXT](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_TEXT) | [TYPE_TEXT_VARIATION_URI](http://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_VARIATION_URI) * iOS: [UIKeyboardTypeURL](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export const url: BaseKeyboardType; + export const url: KeyboardType; /** * Android: [TYPE_CLASS_TEXT](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_TEXT) | [TYPE_TEXT_VARIATION_EMAIL_ADDRESS](http://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_VARIATION_EMAIL_ADDRESS) * iOS: [UIKeyboardTypeEmailAddress](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export const email: BaseKeyboardType; + export const email: KeyboardType; /** * Android: [TYPE_CLASS_NUMBER](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_NUMBER | [TYPE_NUMBER_VARIATION_PASSWORD](android type_text_variation_password)) * iOS: [UIKeyboardTypeNumberPad](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export const integer: BaseKeyboardType; + export const integer: KeyboardType; } /** diff --git a/nativescript-core/ui/enums/index.ts b/nativescript-core/ui/enums/index.ts index 21a7443b9..9c4d29116 100644 --- a/nativescript-core/ui/enums/index.ts +++ b/nativescript-core/ui/enums/index.ts @@ -1,6 +1,7 @@ // imported for definition purposes only import * as animationModule from '../../ui/animation'; +export type KeyboardType = 'datetime' | 'phone' | 'number' | 'url' | 'email' | 'integer'; export module KeyboardType { export const datetime = 'datetime'; export const phone = 'phone'; diff --git a/nativescript-core/ui/index.d.ts b/nativescript-core/ui/index.d.ts index 2dc8ce776..65b02e6fb 100644 --- a/nativescript-core/ui/index.d.ts +++ b/nativescript-core/ui/index.d.ts @@ -14,6 +14,8 @@ export { DatePicker } from './date-picker'; export { action, alert, confirm, login, prompt, getCurrentPage, Dialogs, DialogStrings, DialogOptions, CancelableOptions, AlertOptions, PromptResult, PromptOptions, ActionOptions, ConfirmOptions, LoginResult, LoginOptions, inputType, capitalizationType } from './dialogs'; export * from './editable-text-base'; +import * as enumsModule from './enums'; +export const Enums = enumsModule; export { Frame, NavigationEntry, NavigationContext, NavigationTransition, BackstackEntry, ViewEntry } from './frame'; export { GestureEventData, GestureEventDataWithState, GestureStateTypes, GestureTypes, GesturesObserver, TapGestureEventData, PanGestureEventData, PinchGestureEventData, RotationGestureEventData, SwipeDirection, SwipeGestureEventData, TouchGestureEventData } from './gestures'; diff --git a/nativescript-core/ui/index.ts b/nativescript-core/ui/index.ts index 2dc8ce776..0e2efdb5d 100644 --- a/nativescript-core/ui/index.ts +++ b/nativescript-core/ui/index.ts @@ -14,6 +14,8 @@ export { DatePicker } from './date-picker'; export { action, alert, confirm, login, prompt, getCurrentPage, Dialogs, DialogStrings, DialogOptions, CancelableOptions, AlertOptions, PromptResult, PromptOptions, ActionOptions, ConfirmOptions, LoginResult, LoginOptions, inputType, capitalizationType } from './dialogs'; export * from './editable-text-base'; +import * as enumsModule from './enums'; +export const Enums = enumsModule; export { Frame, NavigationEntry, NavigationContext, NavigationTransition, BackstackEntry, ViewEntry } from './frame'; export { GestureEventData, GestureEventDataWithState, GestureStateTypes, GestureTypes, GesturesObserver, TapGestureEventData, PanGestureEventData, PinchGestureEventData, RotationGestureEventData, SwipeDirection, SwipeGestureEventData, TouchGestureEventData } from './gestures'; @@ -49,7 +51,7 @@ export { TabStrip, TabStripItemEventData } from './tab-navigation-base/tab-strip export { TabStripItem } from './tab-navigation-base/tab-strip-item'; export { TabView, TabViewItem } from './tab-view'; export { Tabs } from './tabs'; -export { TextBase } from './text-base'; +export { TextBase, TextTransform } from './text-base'; export { FormattedString } from './text-base/formatted-string'; export { Span } from './text-base/span'; export { TextField } from './text-field'; diff --git a/nativescript-core/ui/layouts/index.d.ts b/nativescript-core/ui/layouts/index.d.ts index 06e5aeba8..62c6bd601 100644 --- a/nativescript-core/ui/layouts/index.d.ts +++ b/nativescript-core/ui/layouts/index.d.ts @@ -1,7 +1,7 @@ export { AbsoluteLayout } from './absolute-layout'; export { DockLayout } from './dock-layout'; export { FlexboxLayout } from './flexbox-layout'; -export { GridLayout, GridUnitType } from './grid-layout'; +export { GridLayout, GridUnitType, ItemSpec } from './grid-layout'; export { StackLayout } from './stack-layout'; export { WrapLayout } from './wrap-layout'; export { LayoutBase } from './layout-base'; diff --git a/nativescript-core/ui/layouts/index.ts b/nativescript-core/ui/layouts/index.ts index 06e5aeba8..62c6bd601 100644 --- a/nativescript-core/ui/layouts/index.ts +++ b/nativescript-core/ui/layouts/index.ts @@ -1,7 +1,7 @@ export { AbsoluteLayout } from './absolute-layout'; export { DockLayout } from './dock-layout'; export { FlexboxLayout } from './flexbox-layout'; -export { GridLayout, GridUnitType } from './grid-layout'; +export { GridLayout, GridUnitType, ItemSpec } from './grid-layout'; export { StackLayout } from './stack-layout'; export { WrapLayout } from './wrap-layout'; export { LayoutBase } from './layout-base'; diff --git a/nativescript-core/ui/page/index.ios.ts b/nativescript-core/ui/page/index.ios.ts index 692537260..bf01468b7 100644 --- a/nativescript-core/ui/page/index.ios.ts +++ b/nativescript-core/ui/page/index.ios.ts @@ -3,7 +3,7 @@ import { Frame, BackstackEntry } from '../frame'; import { NavigationType } from '../frame/frame-common'; // Types. -import { ios as iosView, View } from '../core/view'; +import { View, IOSHelper } from '../core/view'; import { PageBase, actionBarHiddenProperty, statusBarStyleProperty } from './page-common'; import { profile } from '../../profiling'; @@ -118,7 +118,7 @@ class UIViewControllerImpl extends UIViewController { } // Set autoAdjustScrollInsets in will appear - as early as possible - iosView.updateAutoAdjustScrollInsets(this, owner); + IOSHelper.updateAutoAdjustScrollInsets(this, owner); // Pages in backstack are unloaded so raise loaded here. if (!owner.isLoaded) { @@ -242,7 +242,7 @@ class UIViewControllerImpl extends UIViewController { super.viewWillLayoutSubviews(); const owner = this._owner.get(); if (owner) { - iosView.updateConstraints(this, owner); + IOSHelper.updateConstraints(this, owner); } } @@ -290,7 +290,7 @@ class UIViewControllerImpl extends UIViewController { } } - iosView.layoutView(this, owner); + IOSHelper.layoutView(this, owner); } } @@ -302,7 +302,7 @@ class UIViewControllerImpl extends UIViewController { const owner = this._owner.get(); if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) { owner.notify({ - eventName: iosView.traitCollectionColorAppearanceChangedEvent, + eventName: IOSHelper.traitCollectionColorAppearanceChangedEvent, object: owner, }); } diff --git a/nativescript-core/ui/styling/style-properties.d.ts b/nativescript-core/ui/styling/style-properties.d.ts index 1916bd2e4..3496f39a7 100644 --- a/nativescript-core/ui/styling/style-properties.d.ts +++ b/nativescript-core/ui/styling/style-properties.d.ts @@ -111,4 +111,21 @@ export const fontInternalProperty: InheritedCssProperty; export type BackgroundRepeat = 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat'; export type Visibility = 'visible' | 'hidden' | 'collapse'; export type HorizontalAlignment = 'left' | 'center' | 'right' | 'stretch'; -export type VerticalAlignment = 'top' | 'middle' | 'bottom' | 'stretch'; +export namespace HorizontalAlignment { + export const LEFT: 'left'; + export const CENTER: 'center'; + export const RIGHT: 'right'; + export const STRETCH: 'stretch'; +} +export type VerticalAlignment = 'top' | 'middle' | 'bottom' | 'stretch' | 'text-top' | 'text-bottom' | 'super' | 'sub' | 'baseline'; +export namespace VerticalAlignment { + export const TOP: 'top'; + export const MIDDLE: 'middle'; + export const BOTTOM: 'bottom'; + export const STRETCH: 'stretch'; + export const TEXTTOP: 'text-top'; + export const TEXTBOTTOM: 'text-bottom'; + export const SUPER: 'super'; + export const SUB: 'sub'; + export const BASELINE: 'baseline'; +} diff --git a/nativescript-core/ui/tab-view/index.ios.ts b/nativescript-core/ui/tab-view/index.ios.ts index 9aa7b437f..1bd4a5264 100644 --- a/nativescript-core/ui/tab-view/index.ios.ts +++ b/nativescript-core/ui/tab-view/index.ios.ts @@ -1,7 +1,7 @@ import { TabViewItem as TabViewItemDefinition } from '.'; import { Font } from '../styling/font'; -import { ios as iosView, View } from '../core/view'; +import { IOSHelper, View } from '../core/view'; import { ViewBase } from '../core/view-base'; import { TabViewBase, TabViewItemBase, itemsProperty, selectedIndexProperty, tabTextColorProperty, tabTextFontSizeProperty, tabBackgroundColorProperty, selectedTabTextColorProperty, iosIconRenderingModeProperty, traceMissingIcon } from './tab-view-common'; import { Color } from '../../color'; @@ -44,7 +44,7 @@ class UITabBarControllerImpl extends UITabBarController { return; } - iosView.updateAutoAdjustScrollInsets(this, owner); + IOSHelper.updateAutoAdjustScrollInsets(this, owner); if (!owner.parent) { owner.callLoaded(); @@ -78,7 +78,7 @@ class UITabBarControllerImpl extends UITabBarController { const owner = this._owner.get(); if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) { owner.notify({ - eventName: iosView.traitCollectionColorAppearanceChangedEvent, + eventName: IOSHelper.traitCollectionColorAppearanceChangedEvent, object: owner, }); } @@ -432,7 +432,7 @@ export class TabView extends TabViewBase { newController = item.view.ios.controller; item.setViewController(newController, newController.view); } else { - newController = iosView.UILayoutViewController.initWithOwner(new WeakRef(item.view)) as UIViewController; + newController = IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(item.view)) as UIViewController; newController.view.addSubview(item.view.nativeViewProtected); item.view.viewController = newController; item.setViewController(newController, item.view.nativeViewProtected); diff --git a/nativescript-core/ui/tabs/index.ios.ts b/nativescript-core/ui/tabs/index.ios.ts index 39ef3f35a..d2383329a 100644 --- a/nativescript-core/ui/tabs/index.ios.ts +++ b/nativescript-core/ui/tabs/index.ios.ts @@ -9,7 +9,7 @@ import { Color } from '../../color'; import { ImageSource } from '../../image-source'; import { Device } from '../../platform'; import { ios as iosUtils, isFontIconURI, layout } from '../../utils'; -import { ios as iosView, View } from '../core/view'; +import { IOSHelper, View } from '../core/view'; import { ViewBase } from '../core/view-base'; import { Frame } from '../frame'; import { Font } from '../styling/font'; @@ -144,7 +144,7 @@ class UIPageViewControllerImpl extends UIPageViewController { return; } - iosView.updateAutoAdjustScrollInsets(this, owner); + IOSHelper.updateAutoAdjustScrollInsets(this, owner); // Tabs can be reset as a root view. Call loaded here in this scenario. if (!owner.isLoaded) { @@ -234,7 +234,7 @@ class UIPageViewControllerImpl extends UIPageViewController { const owner = this._owner.get(); if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) { owner.notify({ - eventName: iosView.traitCollectionColorAppearanceChangedEvent, + eventName: IOSHelper.traitCollectionColorAppearanceChangedEvent, object: owner, }); } @@ -665,7 +665,7 @@ export class Tabs extends TabsBase { newController = item.content.ios.controller; (item).setViewController(newController, newController.view); } else { - newController = iosView.UILayoutViewController.initWithOwner(new WeakRef(item.content)) as UIViewController; + newController = IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(item.content)) as UIViewController; newController.view.addSubview(item.content.nativeViewProtected); item.content.viewController = newController; (item).setViewController(newController, item.content.nativeViewProtected); diff --git a/nativescript-core/ui/text-view/index.ios.ts b/nativescript-core/ui/text-view/index.ios.ts index a3647276e..f3a20d72b 100644 --- a/nativescript-core/ui/text-view/index.ios.ts +++ b/nativescript-core/ui/text-view/index.ios.ts @@ -1,6 +1,7 @@ import { ScrollEventData } from '../scroll-view'; +import { textProperty } from '../text-base'; import { TextViewBase as TextViewBaseCommon, maxLinesProperty } from './text-view-common'; -import { editableProperty, hintProperty, textProperty, placeholderColorProperty, _updateCharactersInRangeReplacementString } from '../editable-text-base'; +import { editableProperty, hintProperty, placeholderColorProperty, _updateCharactersInRangeReplacementString } from '../editable-text-base'; import { CSSType } from '../core/view'; import { Color } from '../../color'; import { colorProperty, borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length } from '../styling/style-properties'; diff --git a/package.json b/package.json index bcee4fa3f..c899e38e6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "NativeScript", "description": "NativeScript Core Modules", "homepage": "https://nativescript.org", - "version": "7.0.0-rc.2", + "version": "7.0.0-rc.6", "repository": { "type": "git", "url": "https://github.com/NativeScript/NativeScript" diff --git a/tests/app/tk-unit.ts b/tests/app/tk-unit.ts index 82e072da3..b374f2c40 100644 --- a/tests/app/tk-unit.ts +++ b/tests/app/tk-unit.ts @@ -11,13 +11,10 @@ */ -import * as application from "@nativescript/core/application"; -import * as platform from "@nativescript/core/platform"; -import * as timer from "@nativescript/core/timer"; -import { Trace } from "@nativescript/core"; +import { isIOS, Trace, Device } from "@nativescript/core"; import * as types from "@nativescript/core/utils/types"; -const sdkVersion = parseInt(platform.Device.sdkVersion); +const sdkVersion = parseInt(Device.sdkVersion); Trace.enable(); @@ -361,7 +358,7 @@ export function waitUntilReady(isReady: () => boolean, timeoutSec: number = 3, s return; } - if (application.ios) { + if (isIOS) { const timeoutMs = timeoutSec * 1000; let totalWaitTime = 0; while (true) { @@ -381,7 +378,7 @@ export function waitUntilReady(isReady: () => boolean, timeoutSec: number = 3, s } } } - } else if (application.android) { + } else { doModalAndroid(isReady, timeoutSec, shouldThrow); } } @@ -431,7 +428,7 @@ function doModalAndroid(quitLoop: () => boolean, timeoutSec: number, shouldThrow let quit = false; let timeout = false; - timer.setTimeout(() => { + setTimeout(() => { quit = true; timeout = true; }, timeoutSec * 1000); diff --git a/tests/app/ui/page/page-tests.ios.ts b/tests/app/ui/page/page-tests.ios.ts index 7481bd4d3..ef87dde09 100644 --- a/tests/app/ui/page/page-tests.ios.ts +++ b/tests/app/ui/page/page-tests.ios.ts @@ -1,6 +1,4 @@ -import { Page, View, EventData } from "@nativescript/core/ui/page"; -import { Label } from "@nativescript/core/ui/label"; -import { Frame } from "@nativescript/core/ui/frame"; +import { Page, View, EventData, Label, Frame } from "@nativescript/core"; import * as TKUnit from "../../tk-unit"; import * as helper from "../../ui-helper"; import { addLabelToPage } from "./page-tests-common"; diff --git a/tests/app/xml-declaration/xml-declaration-tests.ts b/tests/app/xml-declaration/xml-declaration-tests.ts index e57c34547..33280ee1f 100644 --- a/tests/app/xml-declaration/xml-declaration-tests.ts +++ b/tests/app/xml-declaration/xml-declaration-tests.ts @@ -1,19 +1,6 @@ import * as TKUnit from "../tk-unit"; -import { Builder } from "@nativescript/core/ui/builder"; -import * as buttonModule from "@nativescript/core/ui/button"; -import * as switchModule from "@nativescript/core/ui/switch"; -import * as searchBarModule from "@nativescript/core/ui/search-bar"; -import * as textFieldModule from "@nativescript/core/ui/text-field"; -import * as gridLayoutModule from "@nativescript/core/ui/layouts/grid-layout"; -import * as absoluteLayoutModule from "@nativescript/core/ui/layouts/absolute-layout"; +import { Builder, Button, Switch, SearchBar, TextField, GridLayout, AbsoluteLayout, Observable, TabView, Page, Label } from "@nativescript/core"; import * as types from "@nativescript/core/utils/types"; -import * as observable from "@nativescript/core/data/observable"; -import * as stackLayoutModule from "@nativescript/core/ui/layouts/stack-layout"; -import { Label } from "@nativescript/core/ui/label"; -import { Page } from "@nativescript/core/ui/page"; -import { Button } from "@nativescript/core/ui/button"; -import { TabView } from "@nativescript/core/ui/tab-view"; -import { Observable } from "@nativescript/core/data/observable"; import { TemplateView } from "./template-builder-tests/template-view"; import * as listViewModule from "@nativescript/core/ui/list-view"; import * as helper from "../ui-helper"; @@ -201,7 +188,7 @@ export function test_parse_ShouldResolveExportsFromCodeFileForTemplates() { function testAction(views: Array) { var ctrl; - var obj = new observable.Observable(); + var obj = new Observable(); obj.set("items", [1]); obj.set("itemLoading", function (args: listViewModule.ItemEventData) { ctrl = args.view; @@ -282,32 +269,32 @@ export function test_parse_ShouldFindEventHandlersWithOnInExports() { export function test_parse_ShouldSetGridAttachedProperties() { var p = Builder.parse(""); - var grid = p.content; + var grid = p.content; var child = grid.getChildAt(0); - var col = gridLayoutModule.GridLayout.getColumn(child); + var col = GridLayout.getColumn(child); TKUnit.assertEqual(col, 2, "Expected result for grid column: 2; Actual result: " + col + ";"); - var row = gridLayoutModule.GridLayout.getRow(child); + var row = GridLayout.getRow(child); TKUnit.assertEqual(row, 1, "Expected result for grid row: 1; Actual result: " + row + ";"); - var colSpan = gridLayoutModule.GridLayout.getColumnSpan(child); + var colSpan = GridLayout.getColumnSpan(child); TKUnit.assertEqual(colSpan, 4, "Expected result for grid column span: 4; Actual result: " + colSpan + ";"); - var rowSpan = gridLayoutModule.GridLayout.getRowSpan(child); + var rowSpan = GridLayout.getRowSpan(child); TKUnit.assertEqual(rowSpan, 3, "Expected result for grid row span: 3; Actual result: " + rowSpan + ";"); } export function test_parse_ShouldSetCanvasAttachedProperties() { var p = Builder.parse(""); - var absLayout = p.content; + var absLayout = p.content; var child = absLayout.getChildAt(0); - var left = absoluteLayoutModule.AbsoluteLayout.getLeft(child); + var left = AbsoluteLayout.getLeft(child); TKUnit.assert(Length.equals(left, Length.parse("1")), `Expected result for canvas left: 1; Actual result: ${(left).value};`); - var top = absoluteLayoutModule.AbsoluteLayout.getTop(child); + var top = AbsoluteLayout.getTop(child); TKUnit.assert(Length.equals(top, Length.parse("2")), `Expected result for canvas top: 2; Actual result: ${(top).value};`); } @@ -318,28 +305,28 @@ export function test_parse_ShouldParseNumberProperties() { export function test_parse_ShouldParseBooleanProperties() { var p = Builder.parse(""); - var sw = p.content; + var sw = p.content; TKUnit.assertTrue(sw.checked, "Expected result: true; Actual result: " + sw.checked + "; type: " + typeof (sw.checked)); } export function test_parse_ShouldParseBooleanPropertiesIgnoreCase() { var p = Builder.parse(""); - var sw = p.content; + var sw = p.content; TKUnit.assert(sw.checked === false, "Expected result: false; Actual result: " + sw.checked + "; type: " + typeof (sw.checked)); } export function test_parse_ShouldParseBooleanPropertiesIgnoreCaseInverted() { var p = Builder.parse(""); - var tf = p.content; + var tf = p.content; TKUnit.assertFalse(tf.editable, "Expected result: false; Actual result: " + tf.editable + "; type: " + typeof (tf.editable)); } export function test_parse_ShouldParsePlatformSpecificProperties() { var p = Builder.parse(""); - var tf = p.content; + var tf = p.content; if (platform.Device.os === platform.platformNames.ios) { TKUnit.assertFalse(tf.editable, "Expected result: false; Actual result: " + tf.editable + "; type: " + typeof (tf.editable)); @@ -351,7 +338,7 @@ export function test_parse_ShouldParsePlatformSpecificProperties() { export function test_parse_ShouldParsePlatformSpecificComponents() { var p = Builder.parse(""); if (platform.Device.os === platform.platformNames.ios) { - TKUnit.assert(p.content instanceof textFieldModule.TextField, "Expected result: TextField; Actual result: " + p.content); + TKUnit.assert(p.content instanceof TextField, "Expected result: TextField; Actual result: " + p.content); } else { TKUnit.assert(p.content instanceof Label, "Expected result: Label; Actual result: " + p.content); @@ -372,17 +359,17 @@ export function test_parse_ThrowErrorWhenNestingPlatforms() { export function test_parse_ShouldParseBindings() { var p = Builder.parse(""); p.bindingContext = { myProp: true }; - var sw = p.content; + var sw = p.content; TKUnit.assertTrue(sw.checked, "Expected result: true; Actual result: " + sw.checked + "; type: " + typeof (sw.checked)); } export function test_parse_ShouldParseBindingsWithObservable() { var p = Builder.parse(""); - var obj = new observable.Observable(); + var obj = new Observable(); obj.set("myProp", true); p.bindingContext = obj; - var sw = p.content; + var sw = p.content; TKUnit.assertTrue(sw.checked, "Expected result: true; Actual result: " + sw.checked + "; type: " + typeof (sw.checked)); @@ -398,7 +385,7 @@ export function test_parse_ShouldParseBindingsToEvents() { // } }; - var btn = p.content; + var btn =