Skip to content

Commit 4d1e4a1

Browse files
authored
feat: NS7 update (#456)
* chore: migration * fix: @nativescript/core imports * fix: nativescript-angular imports * fix: imports * chore: add skipLibCheck to tsconfig.json * fix: nativeClass * fix: imports and tsconfig update
1 parent 3470b07 commit 4d1e4a1

File tree

139 files changed

+671
-641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+671
-641
lines changed

app/app.component.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Component, AfterViewInit } from "@angular/core";
2-
import { hasKey, getString, remove } from "tns-core-modules/application-settings";
3-
import { RouterExtensions } from "nativescript-angular/router";
4-
import * as app from "tns-core-modules/application";
2+
import { RouterExtensions } from "@nativescript/angular";
3+
import { Application, ApplicationEventData, ApplicationSettings } from "@nativescript/core";
54
import { DeepLinkData } from "./shared/deep-link-data";
65
@Component({
76
moduleId: module.id,
@@ -13,7 +12,7 @@ export class AppComponent implements AfterViewInit {
1312
constructor(private router: RouterExtensions) { }
1413

1514
ngAfterViewInit() {
16-
app.on(app.resumeEvent, (args: app.ApplicationEventData) => {
15+
Application.on(Application.resumeEvent, (args: ApplicationEventData) => {
1716
if (args.android) {
1817
const dld = new DeepLinkData("", args.android);
1918
this.launchExample();
@@ -23,9 +22,9 @@ export class AppComponent implements AfterViewInit {
2322
});
2423
}
2524
public launchExample() {
26-
if (hasKey("gotoexample")) {
27-
let value = getString("gotoexample");
28-
remove("gotoexample");
25+
if (ApplicationSettings.hasKey("gotoexample")) {
26+
let value = ApplicationSettings.getString("gotoexample");
27+
ApplicationSettings.remove("gotoexample");
2928
this.router.navigate([value]);
3029
}
3130
}

app/app.module.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// >> ngmodule-config
22
// this import should be first in order to load some required settings (like globals and reflect-metadata)
3-
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
3+
import { NativeScriptModule } from "@nativescript/angular";
44
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
5-
import { NativeScriptRouterModule } from "nativescript-angular/router";
6-
import { NativeScriptFormsModule } from "nativescript-angular/forms";
5+
import { NativeScriptRouterModule } from "@nativescript/angular";
6+
import { NativeScriptFormsModule } from "@nativescript/angular";
77
import { routes } from "./app.routes";
88
import { AppComponent } from "./app.component";
9-
import { ModalDialogService } from "nativescript-angular/modal-dialog";
9+
import { ModalDialogService } from "@nativescript/angular";
1010

1111
@NgModule({
1212
schemas: [NO_ERRORS_SCHEMA],

app/delegate/my-delegate.ios.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { DeepLinkData } from "../shared/deep-link-data";
2-
export class MyDelegate extends UIResponder implements UIApplicationDelegate {
2+
3+
@NativeClass
4+
class MyDelegate extends UIResponder implements UIApplicationDelegate {
35
// tslint:disable-next-line
46
public static ObjCProtocols = [UIApplicationDelegate];
57

@@ -8,3 +10,6 @@ export class MyDelegate extends UIResponder implements UIApplicationDelegate {
810
return true;
911
}
1012
}
13+
14+
export {MyDelegate};
15+

app/directives/example.directive.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Directive } from "@angular/core";
22
import { ActivatedRoute } from "@angular/router";
3-
import { Page } from "tns-core-modules/ui/page";
3+
import { Page } from "@nativescript/core";
44

55
@Directive({
66
selector: "[sdkExampleTitle]"

app/directives/toggle-nav-button.directive.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { ActivatedRoute } from "@angular/router";
22
import { Directive, OnInit } from "@angular/core";
3-
import { EventData } from "tns-core-modules/data/observable";
4-
import { NavigationButton } from "tns-core-modules/ui/action-bar";
5-
import { Page } from "tns-core-modules/ui/page";
6-
import { RouterExtensions } from "nativescript-angular/router";
7-
import * as app from "tns-core-modules/application";
3+
import { EventData, NavigationButton, Page, isAndroid, isIOS } from "@nativescript/core";
4+
import { RouterExtensions } from "@nativescript/angular";
85

96
@Directive({
107
selector: "[sdkToggleNavButton]"
@@ -23,12 +20,12 @@ export class ToggleNavButtonDirective implements OnInit {
2320
let navigationButton = new NavigationButton();
2421
navigationButton.visibility = "visible";
2522

26-
if (app.android) {
23+
if (isAndroid) {
2724
navigationButton.icon = "res://ic_arrow_back_black_24dp";
2825
navigationButton.on("tap", (args: EventData) => {
2926
this.routerExtensions.backToPreviousPage();
3027
});
31-
} else if (app.ios) {
28+
} else if (isIOS) {
3229
navigationButton.text = "";
3330
}
3431

app/examples-list.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
2-
import { NativeScriptRouterModule } from "nativescript-angular/router";
3-
import { NativeScriptCommonModule } from "nativescript-angular/common";
2+
import { NativeScriptRouterModule } from "@nativescript/angular";
3+
import { NativeScriptCommonModule } from "@nativescript/angular";
44
import { ExamplesListComponent } from "./examples-list.component";
55
import { TitleAndNavButtonModule } from "./directives/title-and-nav-button.module";
66

app/main.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { platformNativeScriptDynamic } from "nativescript-angular/platform";
1+
import { platformNativeScriptDynamic } from "@nativescript/angular";
22
import { AppModule } from "./app.module";
3-
import { ios } from "tns-core-modules/application";
4-
import { isIOS } from "tns-core-modules/platform";
3+
import { Application } from "@nativescript/core";
4+
import { isIOS } from "@nativescript/core";
55
import { MyDelegate } from "./delegate/my-delegate";
66

77
if (isIOS) {
8-
ios.delegate = MyDelegate;
8+
Application.ios.delegate = MyDelegate;
99
}
1010
platformNativeScriptDynamic().bootstrapModule(AppModule);

app/ng-framework-modules-category/application-settings/application-settings-examples.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
2-
import { NativeScriptRouterModule } from "nativescript-angular/router";
3-
import { NativeScriptCommonModule } from "nativescript-angular/common";
2+
import { NativeScriptRouterModule } from "@nativescript/angular";
3+
import { NativeScriptCommonModule } from "@nativescript/angular";
44
import { ApplicationSettingsExamplesComponent } from "./application-settings-examples.component";
55
import { UsageComponent } from "./usage/usage.component";
66
import { TitleAndNavButtonModule } from "../../directives/title-and-nav-button.module";
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
// >> app-settings-code
22
import { Component } from "@angular/core";
3-
import {
4-
getBoolean,
5-
setBoolean,
6-
getNumber,
7-
setNumber,
8-
getString,
9-
setString,
10-
hasKey,
11-
remove,
12-
clear
13-
} from "tns-core-modules/application-settings";
3+
import { ApplicationSettings } from "@nativescript/core";
144

155
@Component({
166
moduleId: module.id,
@@ -19,27 +9,27 @@ import {
199
export class UsageComponent {
2010

2111
constructor() {
22-
setBoolean("isTurnedOn", true);
23-
setString("username", "Wolfgang");
24-
setNumber("locationX", 54.321);
12+
ApplicationSettings.setBoolean("isTurnedOn", true);
13+
ApplicationSettings.setString("username", "Wolfgang");
14+
ApplicationSettings.setNumber("locationX", 54.321);
2515

26-
const isTurnedOn: boolean = getBoolean("isTurnedOn");
27-
const username: string = getString("username");
28-
const locationX: number = getNumber("locationX");
16+
const isTurnedOn: boolean = ApplicationSettings.getBoolean("isTurnedOn");
17+
const username: string = ApplicationSettings.getString("username");
18+
const locationX: number = ApplicationSettings.getNumber("locationX");
2919

3020
// Will return "No string value" if there is no value for "noSuchKey"
31-
const someKey: string = getString("noSuchKey", "No string value");
21+
const someKey: string = ApplicationSettings.getString("noSuchKey", "No string value");
3222

3323
// Will return false if there is no key with name "noSuchKey"
34-
let isKeExisting: boolean = hasKey("noSuchKey");
24+
let isKeExisting: boolean = ApplicationSettings.hasKey("noSuchKey");
3525
}
3626

3727
onClearß() {
3828
// Removing a single entry via its key name
39-
remove("isTurnedOn");
29+
ApplicationSettings.remove("isTurnedOn");
4030

4131
// Clearing the whole application-settings for this app
42-
clear();
32+
ApplicationSettings.clear();
4333
}
4434
}
4535
// << app-settings-code

app/ng-framework-modules-category/application/app-checking-target/app-checking-target.component.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// >> app-check-target-code
22
import { Component } from "@angular/core";
3-
import { android as androidApp, ios as iosApp } from "tns-core-modules/application";
3+
import { isAndroid, isIOS } from "@nativescript/core";
44

55
@Component({
66
moduleId: module.id,
@@ -10,10 +10,10 @@ export class AppCheckingTargetExampleComponent {
1010
public isItemVisible: boolean;
1111

1212
constructor() {
13-
if (androidApp) {
13+
if (isAndroid) {
1414
console.log("We are running on Android device!");
1515
this.isItemVisible = true;
16-
} else if (iosApp) {
16+
} else if (isIOS) {
1717
console.log("We are running on iOS device");
1818
this.isItemVisible = false;
1919
}

app/ng-framework-modules-category/application/app-using-android-specifics/app-using-android-specifics.component.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from "@angular/core";
2-
import { android as androidApp, ios as iosApp } from "tns-core-modules/application";
2+
import { Application, isAndroid, isIOS } from "@nativescript/core";
33

44
@Component({
55
moduleId: module.id,
@@ -16,22 +16,22 @@ export class AppUsingAndroidExampleComponent {
1616
public batteryLife: string;
1717

1818
constructor() {
19-
if (androidApp) {
19+
if (isAndroid) {
2020
console.log("We are running on Android device!");
2121
this.isItemVisible = true;
2222

2323
// >> app-class-properties
24-
// import { android as androidApp } from "tns-core-modules/application";
25-
let isPaused = androidApp.paused; // e.g. false
26-
let packageName = androidApp.packageName; // The package ID e.g. org.nativescript.nativescriptsdkexamplesng
27-
let nativeApp = androidApp.nativeApp; // The native APplication reference
28-
let foregroundActivity = androidApp.foregroundActivity; // The current Activity reference
29-
let context = androidApp.context; console.log(context); // The current Android context
24+
// import { Application } from "@nativescript/core";
25+
let isPaused = Application.android.paused; // e.g. false
26+
let packageName = Application.android.packageName; // The package ID e.g. org.nativescript.nativescriptsdkexamplesng
27+
let nativeApp = Application.android.nativeApp; // The native Application reference
28+
let foregroundActivity = Application.android.foregroundActivity; // The current Activity reference
29+
let context = Application.android.context; console.log(context); // The current Android context
3030
// << app-class-properties
3131

3232
// >> app-android-dirs-code
3333
this.fileList = [];
34-
this.appContext = androidApp.context;
34+
this.appContext = Application.android.context;
3535

3636
// https://developer.android.com/reference/android/content/Context.html#getFilesDir()
3737
this.filesDir = this.appContext.getFilesDir();
@@ -51,7 +51,7 @@ export class AppUsingAndroidExampleComponent {
5151
let that = this;
5252

5353
// Broadcast Receiver https://developer.android.com/reference/android/content/BroadcastReceiver
54-
androidApp.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED,
54+
Application.android.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED,
5555
function onReceiveCallback(androidContext: android.content.Context, intent: android.content.Intent) {
5656
let level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1);
5757
let scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1);
@@ -60,15 +60,15 @@ export class AppUsingAndroidExampleComponent {
6060
that.batteryLife = percent.toString();
6161
});
6262
// << app-android-broadcast-code
63-
} else if (iosApp) {
63+
} else if (isIOS) {
6464
console.log("We are running on iOS device");
6565
this.isItemVisible = false;
6666
}
6767
}
6868

6969
unregister() {
7070
// >> app-android-broadcast-unregister-code
71-
androidApp.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED);
71+
Application.android.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED);
7272
// << app-android-broadcast-unregister-code
7373
}
7474
}

app/ng-framework-modules-category/application/app-using-ios-specifics/app-using-ios-specifics.component.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from "@angular/core";
2-
import { android as androidApp, ios as iosApp } from "tns-core-modules/application";
2+
import { Application, isAndroid, isIOS } from "@nativescript/core";
33

44
@Component({
55
moduleId: module.id,
@@ -13,19 +13,19 @@ export class AppUsingIosExampleComponent {
1313

1414
constructor() {
1515

16-
if (iosApp) {
16+
if (isIOS) {
1717
// >> app-class-properties-ios
18-
// import { ios as iosApp } from "tns-core-modules/application";
18+
// import { Application } from "@nativescript/core";
1919

2020
// https://developer.apple.com/documentation/uikit/uiapplicationdelegate?language=objc
21-
let delegate = iosApp.delegate; // the iOS application delegate
21+
let delegate = Application.ios.delegate; // the iOS application delegate
2222

23-
let nativeApp = iosApp.nativeApp; // The native iOS app
23+
let nativeApp = Application.ios.nativeApp; // The native iOS app
2424

2525
// https://developer.apple.com/documentation/uikit/uiwindow/1621581-rootviewcontroller?language=objc
26-
let rootController = iosApp.rootController; // the iOS rootViewController
26+
let rootController = Application.ios.rootController; // the iOS rootViewController
2727

28-
let window = iosApp.window; // UIWindow
28+
let window = Application.ios.window; // UIWindow
2929
// << app-class-properties-ios
3030

3131
this.isItemVisible = true;
@@ -36,7 +36,7 @@ export class AppUsingIosExampleComponent {
3636
this.batteryLife = +(UIDevice.currentDevice.batteryLevel * 100);
3737

3838
let that = this;
39-
let observer = iosApp.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification,
39+
let observer = Application.ios.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification,
4040
function onReceiveCallback(notification: NSNotification) {
4141
that.batteryLife = +(UIDevice.currentDevice.batteryLevel * 100);
4242
});
@@ -45,10 +45,10 @@ export class AppUsingIosExampleComponent {
4545
if (this.goodToRemove) {
4646
// >> app-ios-observer-remove-code
4747
// When no longer needed, remove the notification observer
48-
iosApp.removeNotificationObserver(observer, UIDeviceBatteryLevelDidChangeNotification);
48+
Application.ios.removeNotificationObserver(observer, UIDeviceBatteryLevelDidChangeNotification);
4949
// << app-ios-observer-remove-code
5050
}
51-
} else if (androidApp) {
51+
} else if (isAndroid) {
5252
this.isItemVisible = false;
5353
}
5454
}

0 commit comments

Comments
 (0)