From 299b1cd3e92b303b3fb0ac8d96dddd55458ae5ec Mon Sep 17 00:00:00 2001 From: Janos Hrubos <33330538+janoshrubos@users.noreply.github.com> Date: Thu, 18 Feb 2021 09:49:50 +0100 Subject: [PATCH 1/7] chore: migration --- app/package.json | 11 ------- nativescript.config.ts | 11 +++++++ nsconfig.json | 1 - package.json | 73 +++++++++++++++++++----------------------- references.d.ts | 3 +- tsconfig.json | 17 +++++++--- 6 files changed, 57 insertions(+), 59 deletions(-) delete mode 100644 app/package.json create mode 100644 nativescript.config.ts delete mode 100644 nsconfig.json diff --git a/app/package.json b/app/package.json deleted file mode 100644 index fc125a69..00000000 --- a/app/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "android": { - "v8Flags": "--expose_gc", - "markingMode": "none" - }, - "name": "nativescript-sdk-examples-ng", - "main": "main.js", - "version": "1.0.0", - "author": "Telerik ", - "description": "{N} SDK Sample App" -} diff --git a/nativescript.config.ts b/nativescript.config.ts new file mode 100644 index 00000000..69183f08 --- /dev/null +++ b/nativescript.config.ts @@ -0,0 +1,11 @@ +import { NativeScriptConfig } from '@nativescript/core' + +export default { + id: 'org.nativescript.nativescriptsdkexamplesng', + appPath: 'app', + appResourcesPath: 'app/App_Resources', + android: { + v8Flags: '--expose_gc', + markingMode: 'none', + }, +} as NativeScriptConfig diff --git a/nsconfig.json b/nsconfig.json deleted file mode 100644 index 9e26dfee..00000000 --- a/nsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/package.json b/package.json index ae2c6897..713ecb85 100644 --- a/package.json +++ b/package.json @@ -19,49 +19,41 @@ "documentation" ], "license": "Apache-2.0", - "nativescript": { - "id": "org.nativescript.nativescriptsdkexamplesng", - "tns-android": { - "version": "6.5.0" - }, - "tns-ios": { - "version": "6.5.0" - } - }, "dependencies": { - "@angular/common": "~8.2.0", - "@angular/compiler": "~8.2.0", - "@angular/core": "~8.2.0", - "@angular/forms": "~8.2.0", - "@angular/platform-browser": "~8.2.0", - "@angular/platform-browser-dynamic": "~8.2.0", - "@angular/router": "~8.2.0", - "@nativescript/core": "^6.5.0", - "@nativescript/theme": "^2.1.2", - "nativescript-angular": "^8.21.0", - "nativescript-camera": "^4.5.0", - "nativescript-geolocation": "^5.1.0", - "nativescript-intl": "~3.0.0", - "reflect-metadata": "~0.1.12", - "rxjs": "^6.4.0", - "tns-core-modules": "^6.5.0", - "zone.js": "^0.9.1" + "@angular/common": "11.2.1", + "@angular/compiler": "11.2.1", + "@angular/core": "11.2.1", + "@angular/forms": "11.2.1", + "@angular/platform-browser": "11.2.1", + "@angular/platform-browser-dynamic": "11.2.1", + "@angular/router": "11.2.1", + "@nativescript/core": "7.2.1", + "@nativescript/theme": "3.0.1", + "nativescript-camera": "4.5.0", + "nativescript-geolocation": "5.1.0", + "nativescript-intl": "4.0.2", + "reflect-metadata": "0.1.13", + "rxjs": "6.6.3", + "zone.js": "0.11.4", + "@nativescript/webpack": "4.1.0", + "@nativescript/angular": "11.0.1" }, "devDependencies": { - "@angular/compiler-cli": "~8.2.0", - "@ngtools/webpack": "~8.2.0", - "codelyzer": "^3.0.1", - "fs-extra": "^0.30.0", - "glob": "^7.1.3", + "@angular/compiler-cli": "11.2.1", + "@ngtools/webpack": "11.2.1", + "codelyzer": "6.0.1", + "fs-extra": "9.1.0", + "glob": "7.1.6", "lazy": "1.0.11", - "markdown-snippet-injector": "^0.2.2", - "nativescript-dev-webpack": "^1.5.1", - "opener": "^1.4.1", - "rimraf": "^2.5.3", - "tar.gz": "^1.0.5", - "tns-platform-declarations": "^6.4.2", - "tslint": "^5.11.0", - "typescript": "~3.5.3" + "markdown-snippet-injector": "0.2.4", + "opener": "1.5.2", + "rimraf": "3.0.2", + "tar.gz": "1.0.7", + "tslint": "6.1.3", + "typescript": "4.1.5", + "@nativescript/ios": "7.2.0", + "@nativescript/android": "7.0.1", + "@nativescript/types": "7.2.0" }, "scripts": { "pretsc": "npm install", @@ -78,5 +70,6 @@ "update-app-ng-deps": "update-app-ng-deps", "ns-verify-bundle": "ns-verify-bundle", "update-ns-webpack": "update-ns-webpack" - } + }, + "main": "main.js" } diff --git a/references.d.ts b/references.d.ts index 1e5e9616..d7433268 100644 --- a/references.d.ts +++ b/references.d.ts @@ -1,2 +1 @@ -/// -/// +/// diff --git a/tsconfig.json b/tsconfig.json index f5b1ad98..3e989b5c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "module": "commonjs", - "target": "es5", + "module": "esnext", + "target": "es2017", "experimentalDecorators": true, "emitDecoratorMetadata": true, "noEmitHelpers": true, @@ -9,17 +9,24 @@ "lib": [ "es6", "dom", - "es2015.iterable" + "es2015.iterable", + "es2017" ], "baseUrl": ".", "paths": { "~/*": [ "app/*" ] - } + }, + "moduleResolution": "node", + "removeComments": false }, + "include": [ + "./reference.d.ts", + "app/**/*.ts" + ], "exclude": [ "node_modules", "platforms" ] -} \ No newline at end of file +} From 643f1b5445e9350440aa733809e9be1ce4bb1261 Mon Sep 17 00:00:00 2001 From: Janos Hrubos <33330538+janoshrubos@users.noreply.github.com> Date: Thu, 18 Feb 2021 10:52:38 +0100 Subject: [PATCH 2/7] fix: @nativescript/core imports --- app/app.component.ts | 6 +-- app/directives/example.directive.ts | 2 +- app/directives/toggle-nav-button.directive.ts | 9 ++-- app/main.ts | 6 +-- .../usage/usage.component.ts | 32 ++++-------- .../app-checking-target.component.ts | 6 +-- .../app-using-android-specifics.component.ts | 24 ++++----- .../app-using-ios-specifics.component.ts | 20 ++++---- .../application-events.component.ts | 29 ++++------- .../color/usage/usage.component.ts | 7 ++- .../connectivity/usage/usage.component.ts | 29 +++++------ .../file-system/delete/delete.component.ts | 2 +- .../file-system/paths/paths.component.ts | 2 +- .../file-system/read/read.component.ts | 6 +-- .../file-system/update/update.component.ts | 2 +- .../file-system/usage/usage.component.ts | 2 +- .../fps-meter/usage/usage.component.ts | 2 +- .../platform/usage/platform-module-example.ts | 30 +++++------ .../timer/set-interval/setinterval-example.ts | 8 +-- .../timer/set-timeout/settimeout-example.ts | 10 ++-- .../custom-tracewriter-example.component.ts | 31 ++++-------- ...e-specific-categories-example.component.ts | 50 ++++++++----------- .../using-camera/using-camera.component.ts | 2 +- .../basic-location-example.ts | 4 +- .../location-monitoring-example.ts | 4 +- .../modal-view.component.ts | 2 +- .../home-modal-view-content.component.ts | 2 +- .../modal-view.ts | 2 +- .../usage/usage.component.ts | 3 +- .../animating-properties.component.ts | 6 +-- .../chaining-animations.component.ts | 2 +- .../multiple-views.component.ts | 8 +-- .../width-height-properties.component.ts | 7 ++- .../button/styling/styling.component.ts | 2 +- .../button/usage/usage.component.ts | 3 +- .../date-picker/styling/styling.component.ts | 2 +- .../date-picker/usage/usage.component.ts | 2 +- .../action-dialog/action-dialog.component.ts | 4 +- .../alert-dialog/alert-dialog.component.ts | 4 +- .../confirm-dialog.component.ts | 4 +- .../login-dialog/login-dialog.component.ts | 4 +- .../prompt-dialog/prompt-dialog.component.ts | 20 +++----- .../double-tap/double-tap.component.ts | 3 +- .../long-press/long-press.component.ts | 4 +- .../gestures/pan/pan.component.ts | 2 +- .../gestures/pinch/pinch.component.ts | 4 +- .../gestures/rotation/rotation.component.ts | 4 +- .../gestures/swipe/swipe.component.ts | 2 +- .../gestures/tap/tap.component.ts | 4 +- .../gestures/touch/touch.component.ts | 2 +- .../image/usage/usage.component.ts | 3 +- .../listpicker/styling/styling.component.ts | 2 +- .../listpicker/usage/usage.component.ts | 3 +- .../tips-and-tricks.component.ts | 2 +- .../listview/usage/usage.component.ts | 2 +- .../create-custom-directive.component.ts | 2 +- .../ngif-directive-advanced.component.ts | 6 +-- .../tips-and-tricks.component.ts | 2 +- .../progress/usage/usage.component.ts | 3 +- .../tips-and-tricks.component.ts | 2 +- .../search-bar/usage/usage.component.ts | 2 +- .../styling/styling.component.ts | 2 +- .../segmented-bar/usage/usage.component.ts | 2 +- .../slider/usage/usage.component.ts | 2 +- .../apply-style-code.component.ts | 3 +- .../switch/usage/usage.component.ts | 3 +- .../tab-view/usage/usage.component.ts | 2 +- .../text-field/usage/usage.component.ts | 5 +- .../text-view/usage/usage.component.ts | 3 +- .../time-picker/usage/usage.component.ts | 2 +- .../tips-and-tricks.component.ts | 2 +- .../web-view/usage/usage.component.ts | 2 +- app/shared/deep-link-data.ts | 5 +- 73 files changed, 207 insertions(+), 282 deletions(-) diff --git a/app/app.component.ts b/app/app.component.ts index ae9a39d6..f8983b1a 100644 --- a/app/app.component.ts +++ b/app/app.component.ts @@ -1,7 +1,7 @@ import { Component, AfterViewInit } from "@angular/core"; -import { hasKey, getString, remove } from "tns-core-modules/application-settings"; +import { hasKey, getString, remove } from "@nativescript/core"; import { RouterExtensions } from "nativescript-angular/router"; -import * as app from "tns-core-modules/application"; +import { Application } from "@nativescript/core"; import { DeepLinkData } from "./shared/deep-link-data"; @Component({ moduleId: module.id, @@ -13,7 +13,7 @@ export class AppComponent implements AfterViewInit { constructor(private router: RouterExtensions) { } ngAfterViewInit() { - app.on(app.resumeEvent, (args: app.ApplicationEventData) => { + Application.on(Application.resumeEvent, (args: Application.ApplicationEventData) => { if (args.android) { const dld = new DeepLinkData("", args.android); this.launchExample(); diff --git a/app/directives/example.directive.ts b/app/directives/example.directive.ts index ee253927..9f81ac77 100644 --- a/app/directives/example.directive.ts +++ b/app/directives/example.directive.ts @@ -1,6 +1,6 @@ import { Directive } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; -import { Page } from "tns-core-modules/ui/page"; +import { Page } from "@nativescript/core"; @Directive({ selector: "[sdkExampleTitle]" diff --git a/app/directives/toggle-nav-button.directive.ts b/app/directives/toggle-nav-button.directive.ts index 74d9653c..a3949d06 100644 --- a/app/directives/toggle-nav-button.directive.ts +++ b/app/directives/toggle-nav-button.directive.ts @@ -1,10 +1,7 @@ import { ActivatedRoute } from "@angular/router"; import { Directive, OnInit } from "@angular/core"; -import { EventData } from "tns-core-modules/data/observable"; -import { NavigationButton } from "tns-core-modules/ui/action-bar"; -import { Page } from "tns-core-modules/ui/page"; +import { EventData, NavigationButton, Page, isAndroid, isIOS } from "@nativescript/core"; import { RouterExtensions } from "nativescript-angular/router"; -import * as app from "tns-core-modules/application"; @Directive({ selector: "[sdkToggleNavButton]" @@ -23,12 +20,12 @@ export class ToggleNavButtonDirective implements OnInit { let navigationButton = new NavigationButton(); navigationButton.visibility = "visible"; - if (app.android) { + if (isAndroid) { navigationButton.icon = "res://ic_arrow_back_black_24dp"; navigationButton.on("tap", (args: EventData) => { this.routerExtensions.backToPreviousPage(); }); - } else if (app.ios) { + } else if (isIOS) { navigationButton.text = ""; } diff --git a/app/main.ts b/app/main.ts index c8530f25..8748ad0b 100644 --- a/app/main.ts +++ b/app/main.ts @@ -1,10 +1,10 @@ import { platformNativeScriptDynamic } from "nativescript-angular/platform"; import { AppModule } from "./app.module"; -import { ios } from "tns-core-modules/application"; -import { isIOS } from "tns-core-modules/platform"; +import { Application } from "@nativescript/core"; +import { isIOS } from "@nativescript/core"; import { MyDelegate } from "./delegate/my-delegate"; if (isIOS) { - ios.delegate = MyDelegate; + Application.ios.delegate = MyDelegate; } platformNativeScriptDynamic().bootstrapModule(AppModule); diff --git a/app/ng-framework-modules-category/application-settings/usage/usage.component.ts b/app/ng-framework-modules-category/application-settings/usage/usage.component.ts index e4b2c62b..b547bcf4 100644 --- a/app/ng-framework-modules-category/application-settings/usage/usage.component.ts +++ b/app/ng-framework-modules-category/application-settings/usage/usage.component.ts @@ -1,16 +1,6 @@ // >> app-settings-code import { Component } from "@angular/core"; -import { - getBoolean, - setBoolean, - getNumber, - setNumber, - getString, - setString, - hasKey, - remove, - clear -} from "tns-core-modules/application-settings"; +import { ApplicationSettings } from "@nativescript/core"; @Component({ moduleId: module.id, @@ -19,27 +9,27 @@ import { export class UsageComponent { constructor() { - setBoolean("isTurnedOn", true); - setString("username", "Wolfgang"); - setNumber("locationX", 54.321); + ApplicationSettings.setBoolean("isTurnedOn", true); + ApplicationSettings.setString("username", "Wolfgang"); + ApplicationSettings.setNumber("locationX", 54.321); - const isTurnedOn: boolean = getBoolean("isTurnedOn"); - const username: string = getString("username"); - const locationX: number = getNumber("locationX"); + const isTurnedOn: boolean = ApplicationSettings.getBoolean("isTurnedOn"); + const username: string = ApplicationSettings.getString("username"); + const locationX: number = ApplicationSettings.getNumber("locationX"); // Will return "No string value" if there is no value for "noSuchKey" - const someKey: string = getString("noSuchKey", "No string value"); + const someKey: string = ApplicationSettings.getString("noSuchKey", "No string value"); // Will return false if there is no key with name "noSuchKey" - let isKeExisting: boolean = hasKey("noSuchKey"); + let isKeExisting: boolean = ApplicationSettings.hasKey("noSuchKey"); } onClearß() { // Removing a single entry via its key name - remove("isTurnedOn"); + ApplicationSettings.remove("isTurnedOn"); // Clearing the whole application-settings for this app - clear(); + ApplicationSettings.clear(); } } // << app-settings-code diff --git a/app/ng-framework-modules-category/application/app-checking-target/app-checking-target.component.ts b/app/ng-framework-modules-category/application/app-checking-target/app-checking-target.component.ts index d274ffae..5cd84742 100644 --- a/app/ng-framework-modules-category/application/app-checking-target/app-checking-target.component.ts +++ b/app/ng-framework-modules-category/application/app-checking-target/app-checking-target.component.ts @@ -1,6 +1,6 @@ // >> app-check-target-code import { Component } from "@angular/core"; -import { android as androidApp, ios as iosApp } from "tns-core-modules/application"; +import { isAndroid, isIos } from "@nativescript/core"; @Component({ moduleId: module.id, @@ -10,10 +10,10 @@ export class AppCheckingTargetExampleComponent { public isItemVisible: boolean; constructor() { - if (androidApp) { + if (isAndroid) { console.log("We are running on Android device!"); this.isItemVisible = true; - } else if (iosApp) { + } else if (isIos) { console.log("We are running on iOS device"); this.isItemVisible = false; } diff --git a/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts b/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts index 8595eb77..1fced545 100644 --- a/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts +++ b/app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts @@ -1,5 +1,5 @@ import { Component } from "@angular/core"; -import { android as androidApp, ios as iosApp } from "tns-core-modules/application"; +import { isAndroid, isIOS } from "@nativescript/core"; @Component({ moduleId: module.id, @@ -16,22 +16,22 @@ export class AppUsingAndroidExampleComponent { public batteryLife: string; constructor() { - if (androidApp) { + if (isAndroid) { console.log("We are running on Android device!"); this.isItemVisible = true; // >> app-class-properties - // import { android as androidApp } from "tns-core-modules/application"; - let isPaused = androidApp.paused; // e.g. false - let packageName = androidApp.packageName; // The package ID e.g. org.nativescript.nativescriptsdkexamplesng - let nativeApp = androidApp.nativeApp; // The native APplication reference - let foregroundActivity = androidApp.foregroundActivity; // The current Activity reference - let context = androidApp.context; console.log(context); // The current Android context + // import { Application } from "@nativescript/core"; + let isPaused = Application.android.paused; // e.g. false + let packageName = Application.android.packageName; // The package ID e.g. org.nativescript.nativescriptsdkexamplesng + let nativeApp = Application.android.nativeApp; // The native Application reference + let foregroundActivity = Application.android.foregroundActivity; // The current Activity reference + let context = Application.android.context; console.log(context); // The current Android context // << app-class-properties // >> app-android-dirs-code this.fileList = []; - this.appContext = androidApp.context; + this.appContext = Application.android.context; // https://developer.android.com/reference/android/content/Context.html#getFilesDir() this.filesDir = this.appContext.getFilesDir(); @@ -51,7 +51,7 @@ export class AppUsingAndroidExampleComponent { let that = this; // Broadcast Receiver https://developer.android.com/reference/android/content/BroadcastReceiver - androidApp.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED, + Application.android.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED, function onReceiveCallback(androidContext: android.content.Context, intent: android.content.Intent) { let level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1); let scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1); @@ -60,7 +60,7 @@ export class AppUsingAndroidExampleComponent { that.batteryLife = percent.toString(); }); // << app-android-broadcast-code - } else if (iosApp) { + } else if (isIOS) { console.log("We are running on iOS device"); this.isItemVisible = false; } @@ -68,7 +68,7 @@ export class AppUsingAndroidExampleComponent { unregister() { // >> app-android-broadcast-unregister-code - androidApp.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED); + Application.android.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED); // << app-android-broadcast-unregister-code } } diff --git a/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts b/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts index c3dc5f52..47998668 100644 --- a/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts +++ b/app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts @@ -1,5 +1,5 @@ import { Component } from "@angular/core"; -import { android as androidApp, ios as iosApp } from "tns-core-modules/application"; +import { isAndroid, isIOS } from "@nativescript/core"; @Component({ moduleId: module.id, @@ -13,19 +13,19 @@ export class AppUsingIosExampleComponent { constructor() { - if (iosApp) { + if (isIOS) { // >> app-class-properties-ios - // import { ios as iosApp } from "tns-core-modules/application"; + // import { Application } from "@nativescript/core"; // https://developer.apple.com/documentation/uikit/uiapplicationdelegate?language=objc - let delegate = iosApp.delegate; // the iOS application delegate + let delegate = Application.ios.delegate; // the iOS application delegate - let nativeApp = iosApp.nativeApp; // The native iOS app + let nativeApp = Application.ios.nativeApp; // The native iOS app // https://developer.apple.com/documentation/uikit/uiwindow/1621581-rootviewcontroller?language=objc - let rootController = iosApp.rootController; // the iOS rootViewController + let rootController = Application.ios.rootController; // the iOS rootViewController - let window = iosApp.window; // UIWindow + let window = Application.ios.window; // UIWindow // << app-class-properties-ios this.isItemVisible = true; @@ -36,7 +36,7 @@ export class AppUsingIosExampleComponent { this.batteryLife = +(UIDevice.currentDevice.batteryLevel * 100); let that = this; - let observer = iosApp.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification, + let observer = Application.ios.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification, function onReceiveCallback(notification: NSNotification) { that.batteryLife = +(UIDevice.currentDevice.batteryLevel * 100); }); @@ -45,10 +45,10 @@ export class AppUsingIosExampleComponent { if (this.goodToRemove) { // >> app-ios-observer-remove-code // When no longer needed, remove the notification observer - iosApp.removeNotificationObserver(observer, UIDeviceBatteryLevelDidChangeNotification); + Application.ios.removeNotificationObserver(observer, UIDeviceBatteryLevelDidChangeNotification); // << app-ios-observer-remove-code } - } else if (androidApp) { + } else if (isAndroid) { this.isItemVisible = false; } } diff --git a/app/ng-framework-modules-category/application/application-events/application-events.component.ts b/app/ng-framework-modules-category/application/application-events/application-events.component.ts index ccecf2fc..62f2db55 100644 --- a/app/ng-framework-modules-category/application/application-events/application-events.component.ts +++ b/app/ng-framework-modules-category/application/application-events/application-events.component.ts @@ -1,16 +1,5 @@ import { Component } from "@angular/core"; -import { - on, - ApplicationEventData, - launchEvent, LaunchEventData, - resumeEvent, - exitEvent, - uncaughtErrorEvent, UnhandledErrorEventData, - displayedEvent, - lowMemoryEvent, - orientationChangedEvent, OrientationChangedEventData, - suspendEvent -} from "tns-core-modules/application"; +import { Application, LaunchEventData, OrientationChangedEventData, UnhandledErrorEventData } from "@nativescript/core"; let launchListener, suspendListener, @@ -33,35 +22,35 @@ export class ApplicationEventsComponent { launchListener = (args: LaunchEventData) => { console.log("The appication was launched!"); }; - on(launchEvent, launchListener); + Application.on(Application.launchEvent, launchListener); // << application-events-launch-ng // >> application-events-suspend-ng suspendListener = (args: ApplicationEventData) => { console.log("The appication was suspended!"); }; - on(suspendEvent, suspendListener); + Application.on(Application.suspendEvent, suspendListener); // << application-events-suspend-ng // >> application-events-resume-ng resumeListener = (args: ApplicationEventData) => { console.log("The appication was resumed!"); }; - on(resumeEvent, resumeListener); + Application.on(Application.resumeEvent, resumeListener); // << application-events-resume-ng // >> application-events-exit-ng exitListener = (args: ApplicationEventData) => { console.log("The appication was closed!"); }; - on(exitEvent, exitListener); + Application.on(Application.exitEvent, exitListener); // << application-events-exit-ng // >> application-events-displayed-ng displayedListener = (args: ApplicationEventData) => { console.log("NativeScript displayedEvent!"); }; - on(displayedEvent, displayedListener); + Application.on(Application.displayedEvent, displayedListener); // << application-events-displayed-ng // >> application-events-low-memory-ng @@ -69,7 +58,7 @@ export class ApplicationEventsComponent { // the instance that has raised the event console.log("Instance: ", args.object); }; - on(lowMemoryEvent, lowMemoryListener); + Application.on(Application.lowMemoryEvent, lowMemoryListener); // << application-events-low-memory-ng // >> application-events-orientation-ng @@ -77,7 +66,7 @@ export class ApplicationEventsComponent { // orientationChangedEventData.newValue: "portrait" | "landscape" | "unknown" console.log("Orientation: ", args.newValue); }; - on(orientationChangedEvent, orientationChangedListener); + Application.on(Application.orientationChangedEvent, orientationChangedListener); // << application-events-orientation-ng // >> application-events-error-ng @@ -85,7 +74,7 @@ export class ApplicationEventsComponent { // UnhandledErrorEventData.error: NativeScriptError console.log("NativeScript Error: ", args.error); }; - on(uncaughtErrorEvent, uncaughtErrorListener); + Application.on(Application.uncaughtErrorEvent, uncaughtErrorListener); // << application-events-error-ng } } diff --git a/app/ng-framework-modules-category/color/usage/usage.component.ts b/app/ng-framework-modules-category/color/usage/usage.component.ts index a8a24d92..66a57d05 100644 --- a/app/ng-framework-modules-category/color/usage/usage.component.ts +++ b/app/ng-framework-modules-category/color/usage/usage.component.ts @@ -1,9 +1,8 @@ // tslint:disable:no-bitwise // >> creating-colors-code import { Component } from "@angular/core"; -import { Color } from "tns-core-modules/color"; -import * as colors from "tns-core-modules/color/known-colors"; -import { isKnownName } from "tns-core-modules/color/known-colors"; +import { OrangeRed, isKnownName } from "@nativescript/core/color/known-colors"; +import { Color } from "@nativescript/core"; @Component({ moduleId: module.id, @@ -31,7 +30,7 @@ export class UsageComponent { } // Using supported known colors from tns-core-modules/color/known-colors - let colorKnownName = new Color(colors.OrangeRed); + let colorKnownName = new Color(OrangeRed); } } // << creating-colors-code diff --git a/app/ng-framework-modules-category/connectivity/usage/usage.component.ts b/app/ng-framework-modules-category/connectivity/usage/usage.component.ts index 609d86f7..54fc925e 100644 --- a/app/ng-framework-modules-category/connectivity/usage/usage.component.ts +++ b/app/ng-framework-modules-category/connectivity/usage/usage.component.ts @@ -1,11 +1,6 @@ // >> connectivity-start-code import { Component, OnInit, OnDestroy } from "@angular/core"; -import { - getConnectionType, - startMonitoring, - stopMonitoring -} from "tns-core-modules/connectivity"; -import * as connectivityModule from "tns-core-modules/connectivity"; +import { Connectivity } from "@nativescript/core"; @Component({ moduleId: module.id, @@ -16,19 +11,19 @@ export class UsageComponent implements OnInit, OnDestroy { connectionType: string; constructor() { - let type = getConnectionType(); + let type = Connectivity.getConnectionType(); switch (type) { - case connectivityModule.connectionType.none: + case Connectivity.connectionType.none: this.connectionType = "None"; break; - case connectivityModule.connectionType.wifi: + case Connectivity.connectionType.wifi: this.connectionType = "Wi-Fi"; break; - case connectivityModule.connectionType.mobile: + case Connectivity.connectionType.mobile: this.connectionType = "Mobile"; break; - case connectivityModule.connectionType.bluetooth: + case Connectivity.connectionType.bluetooth: this.connectionType = "Bluetooth"; break; default: @@ -37,21 +32,21 @@ export class UsageComponent implements OnInit, OnDestroy { } ngOnInit() { - startMonitoring((type) => { + Connectivity.startMonitoring((type) => { switch (type) { - case connectivityModule.connectionType.none: + case Connectivity.connectionType.none: this.connectionType = "None"; console.log("Connection type changed to none."); break; - case connectivityModule.connectionType.wifi: + case Connectivity.connectionType.wifi: this.connectionType = "Wi-Fi"; console.log("Connection type changed to WiFi."); break; - case connectivityModule.connectionType.mobile: + case Connectivity.connectionType.mobile: this.connectionType = "Mobile"; console.log("Connection type changed to mobile."); break; - case connectivityModule.connectionType.bluetooth: + case Connectivity.connectionType.bluetooth: this.connectionType = "Bluetooth"; console.log("Connection type changed to Bluetooth."); break; @@ -63,7 +58,7 @@ export class UsageComponent implements OnInit, OnDestroy { ngOnDestroy() { // Stoping the connection monitoring - stopMonitoring(); + Connectivity.stopMonitoring(); } } // << connectivity-start-code diff --git a/app/ng-framework-modules-category/file-system/delete/delete.component.ts b/app/ng-framework-modules-category/file-system/delete/delete.component.ts index 6444b49a..cb2d3528 100644 --- a/app/ng-framework-modules-category/file-system/delete/delete.component.ts +++ b/app/ng-framework-modules-category/file-system/delete/delete.component.ts @@ -1,6 +1,6 @@ import { Component } from "@angular/core"; // >> fs-delete-import-code -import { File, Folder, knownFolders } from "tns-core-modules/file-system"; +import { File, Folder, knownFolders } from "@nativescript/core"; // << fs-delete-import-code @Component({ moduleId: module.id, diff --git a/app/ng-framework-modules-category/file-system/paths/paths.component.ts b/app/ng-framework-modules-category/file-system/paths/paths.component.ts index c4f5f720..0f7229cc 100644 --- a/app/ng-framework-modules-category/file-system/paths/paths.component.ts +++ b/app/ng-framework-modules-category/file-system/paths/paths.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from "@angular/core"; // >> fs-paths-import-code -import { knownFolders, path, File, Folder } from "tns-core-modules/file-system"; +import { knownFolders, path, File, Folder } from "@nativescript/core"; // << fs-paths-import-code @Component({ diff --git a/app/ng-framework-modules-category/file-system/read/read.component.ts b/app/ng-framework-modules-category/file-system/read/read.component.ts index 4078311d..ac3356bf 100644 --- a/app/ng-framework-modules-category/file-system/read/read.component.ts +++ b/app/ng-framework-modules-category/file-system/read/read.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from "@angular/core"; -import * as imageSource from "tns-core-modules/image-source"; +import { ImageSource } from "@nativescript/core"; // >> fs-read-import-code -import { knownFolders, path, File, Folder } from "tns-core-modules/file-system"; +import { knownFolders, path, File, Folder } from "@nativescript/core"; // << fs-read-import-code @Component({ @@ -81,7 +81,7 @@ export class ReadExampleComponent implements OnInit { public onReadSync() { // >> fs-read-sync-code - let image = imageSource.fromResource("icon"); + let image = ImageSource.fromResourceSync("icon"); let folder = knownFolders.documents(); let myPath = path.join(folder.path, "Test.png"); let saved = image.saveToFile(myPath, "png"); diff --git a/app/ng-framework-modules-category/file-system/update/update.component.ts b/app/ng-framework-modules-category/file-system/update/update.component.ts index 90d535df..8f9f75ae 100644 --- a/app/ng-framework-modules-category/file-system/update/update.component.ts +++ b/app/ng-framework-modules-category/file-system/update/update.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from "@angular/core"; // >> fs-update-import-code -import { knownFolders, path, File, Folder } from "tns-core-modules/file-system"; +import { knownFolders, path, File, Folder } from "@nativescript/core"; // << fs-update-import-code @Component({ moduleId: module.id, diff --git a/app/ng-framework-modules-category/file-system/usage/usage.component.ts b/app/ng-framework-modules-category/file-system/usage/usage.component.ts index c4643040..1349c6de 100644 --- a/app/ng-framework-modules-category/file-system/usage/usage.component.ts +++ b/app/ng-framework-modules-category/file-system/usage/usage.component.ts @@ -1,6 +1,6 @@ import { Component } from "@angular/core"; // >> fs-create-import-code -import { knownFolders, path, File, Folder } from "tns-core-modules/file-system"; +import { knownFolders, path, File, Folder } from "@nativescript/core"; // << fs-create-import-code @Component({ diff --git a/app/ng-framework-modules-category/fps-meter/usage/usage.component.ts b/app/ng-framework-modules-category/fps-meter/usage/usage.component.ts index acdb1a6d..6250ff45 100644 --- a/app/ng-framework-modules-category/fps-meter/usage/usage.component.ts +++ b/app/ng-framework-modules-category/fps-meter/usage/usage.component.ts @@ -1,6 +1,6 @@ // >> fps-meter-module-usage import { Component, NgZone } from "@angular/core"; -import { start, removeCallback, addCallback, stop } from "tns-core-modules/fps-meter"; +import { start, removeCallback, addCallback, stop } from "@nativescript/core/fps-meter"; @Component({ moduleId: module.id, diff --git a/app/ng-framework-modules-category/platform/usage/platform-module-example.ts b/app/ng-framework-modules-category/platform/usage/platform-module-example.ts index 221dc9ed..19008349 100644 --- a/app/ng-framework-modules-category/platform/usage/platform-module-example.ts +++ b/app/ng-framework-modules-category/platform/usage/platform-module-example.ts @@ -1,7 +1,7 @@ // tslint:disable:max-line-length // >> import-platform-module import { Component } from "@angular/core"; -import { isAndroid, isIOS, device, screen } from "tns-core-modules/platform"; +import { isAndroid, isIOS, Device, Screen } from "@nativescript/core"; @Component({ moduleId: module.id, @@ -13,21 +13,21 @@ export class PlatformModuleExampleComponent { console.log(`Running on Android? ${isAndroid}`); console.log(`Running on iOS? ${isIOS}`); - console.log(`device.model ${device.model}`); // For example: "Nexus 5" or "iPhone". - console.log(`device.deviceType ${device.deviceType}`); // "Phone" | "Tablet" - console.log(`device.os ${device.os}`); // For example: "Android" or "iOS". - console.log(`device.osVersion ${device.osVersion}`); // For example: 4.4.4(android), 8.1(ios) - console.log(`device.sdkVersion ${device.sdkVersion}`); // For example: 19(android), 8.1(ios). - console.log(`device.language ${device.language}`); // For example "en" or "en-US". - console.log(`device.manufacturer ${device.manufacturer}`); // For example: "Apple" or "HTC" or "Samsung". - console.log(`device.uuid ${device.uuid}`); // The unique identification number - console.log(`device.region ${device.region}`); // For example "US". + console.log(`device.model ${Device.model}`); // For example: "Nexus 5" or "iPhone". + console.log(`device.deviceType ${Device.deviceType}`); // "Phone" | "Tablet" + console.log(`device.os ${Device.os}`); // For example: "Android" or "iOS". + console.log(`device.osVersion ${Device.osVersion}`); // For example: 4.4.4(android), 8.1(ios) + console.log(`device.sdkVersion ${Device.sdkVersion}`); // For example: 19(android), 8.1(ios). + console.log(`device.language ${Device.language}`); // For example "en" or "en-US". + console.log(`device.manufacturer ${Device.manufacturer}`); // For example: "Apple" or "HTC" or "Samsung". + console.log(`device.uuid ${Device.uuid}`); // The unique identification number + console.log(`device.region ${Device.region}`); // For example "US". - console.log(`screen.mainScreen.heightDIPs ${screen.mainScreen.heightDIPs}`); // The absolute height of the screen in density independent pixels. - console.log(`screen.mainScreen.heightPixels ${screen.mainScreen.heightPixels}`); // The absolute height of the screen in pixels. - console.log(`screen.mainScreen.scale ${screen.mainScreen.scale}`); // The logical density of the display. - console.log(`screen.mainScreen.widthDIPs ${screen.mainScreen.widthDIPs}`); // The absolute width of the screen in density independent pixels. - console.log(`screen.mainScreen.widthPixels ${screen.mainScreen.widthPixels}`); // The absolute width of the screen in pixel + console.log(`screen.mainScreen.heightDIPs ${Screen.mainScreen.heightDIPs}`); // The absolute height of the screen in density independent pixels. + console.log(`screen.mainScreen.heightPixels ${Screen.mainScreen.heightPixels}`); // The absolute height of the screen in pixels. + console.log(`screen.mainScreen.scale ${Screen.mainScreen.scale}`); // The logical density of the display. + console.log(`screen.mainScreen.widthDIPs ${Screen.mainScreen.widthDIPs}`); // The absolute width of the screen in density independent pixels. + console.log(`screen.mainScreen.widthPixels ${Screen.mainScreen.widthPixels}`); // The absolute width of the screen in pixel } } // << import-platform-module diff --git a/app/ng-framework-modules-category/timer/set-interval/setinterval-example.ts b/app/ng-framework-modules-category/timer/set-interval/setinterval-example.ts index 1caba399..7f2c5585 100644 --- a/app/ng-framework-modules-category/timer/set-interval/setinterval-example.ts +++ b/app/ng-framework-modules-category/timer/set-interval/setinterval-example.ts @@ -1,6 +1,6 @@ import { Component } from "@angular/core"; -import { setInterval, clearInterval } from "tns-core-modules/timer"; +import { Utils } from "@nativescript/core"; @Component({ moduleId: module.id, @@ -19,7 +19,7 @@ export class SetIntervalComponent { let that = this; // >> set-interval-example - this.id = setInterval(() => { + this.id = Utils.setInterval(() => { let randNumber = Math.floor(Math.random() * (that.color.length)); that.buttoncolor = that.color[randNumber]; }, 1000); @@ -28,13 +28,13 @@ export class SetIntervalComponent { public onButtonTap(args) { if (this.status) { - clearInterval(this.id); + Utils.clearInterval(this.id); this.status = false; this.buttonText = "Enable color change"; } else { let that = this; - this.id = setInterval(() => { + this.id = Utils.setInterval(() => { let randNumber = Math.floor(Math.random() * (that.color.length)); that.buttoncolor = that.color[randNumber]; }, 1000); diff --git a/app/ng-framework-modules-category/timer/set-timeout/settimeout-example.ts b/app/ng-framework-modules-category/timer/set-timeout/settimeout-example.ts index 18926410..509167db 100644 --- a/app/ng-framework-modules-category/timer/set-timeout/settimeout-example.ts +++ b/app/ng-framework-modules-category/timer/set-timeout/settimeout-example.ts @@ -1,9 +1,5 @@ - import { Component } from "@angular/core"; -import { EventData } from "tns-core-modules/data/observable"; -import { setTimeout } from "tns-core-modules/timer"; -import { Color } from "tns-core-modules/color"; -import { Button } from "tns-core-modules/ui/button"; +import { Button, Color, EventData, Utils } from "@nativescript/core"; @Component({ moduleId: module.id, styleUrls: ["./settimeout-example.css"], @@ -16,7 +12,7 @@ export class SetTimeoutComponent { let button =