Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, AfterViewInit } from "@angular/core";
import { hasKey, getString, remove } from "tns-core-modules/application-settings";
import { RouterExtensions } from "nativescript-angular/router";
import * as app from "tns-core-modules/application";
import { RouterExtensions } from "@nativescript/angular";
import { Application, ApplicationEventData, ApplicationSettings } from "@nativescript/core";
import { DeepLinkData } from "./shared/deep-link-data";
@Component({
moduleId: module.id,
Expand All @@ -13,7 +12,7 @@ export class AppComponent implements AfterViewInit {
constructor(private router: RouterExtensions) { }

ngAfterViewInit() {
app.on(app.resumeEvent, (args: app.ApplicationEventData) => {
Application.on(Application.resumeEvent, (args: ApplicationEventData) => {
if (args.android) {
const dld = new DeepLinkData("", args.android);
this.launchExample();
Expand All @@ -23,9 +22,9 @@ export class AppComponent implements AfterViewInit {
});
}
public launchExample() {
if (hasKey("gotoexample")) {
let value = getString("gotoexample");
remove("gotoexample");
if (ApplicationSettings.hasKey("gotoexample")) {
let value = ApplicationSettings.getString("gotoexample");
ApplicationSettings.remove("gotoexample");
this.router.navigate([value]);
}
}
Expand Down
8 changes: 4 additions & 4 deletions app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// >> ngmodule-config
// this import should be first in order to load some required settings (like globals and reflect-metadata)
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { NativeScriptModule } from "@nativescript/angular";
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { NativeScriptFormsModule } from "nativescript-angular/forms";
import { NativeScriptRouterModule } from "@nativescript/angular";
import { NativeScriptFormsModule } from "@nativescript/angular";
import { routes } from "./app.routes";
import { AppComponent } from "./app.component";
import { ModalDialogService } from "nativescript-angular/modal-dialog";
import { ModalDialogService } from "@nativescript/angular";

@NgModule({
schemas: [NO_ERRORS_SCHEMA],
Expand Down
7 changes: 6 additions & 1 deletion app/delegate/my-delegate.ios.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { DeepLinkData } from "../shared/deep-link-data";
export class MyDelegate extends UIResponder implements UIApplicationDelegate {

@NativeClass
class MyDelegate extends UIResponder implements UIApplicationDelegate {
// tslint:disable-next-line
public static ObjCProtocols = [UIApplicationDelegate];

Expand All @@ -8,3 +10,6 @@ export class MyDelegate extends UIResponder implements UIApplicationDelegate {
return true;
}
}

export {MyDelegate};

2 changes: 1 addition & 1 deletion app/directives/example.directive.ts
Original file line number Diff line number Diff line change
@@ -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]"
Expand Down
11 changes: 4 additions & 7 deletions app/directives/toggle-nav-button.directive.ts
Original file line number Diff line number Diff line change
@@ -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 { RouterExtensions } from "nativescript-angular/router";
import * as app from "tns-core-modules/application";
import { EventData, NavigationButton, Page, isAndroid, isIOS } from "@nativescript/core";
import { RouterExtensions } from "@nativescript/angular";

@Directive({
selector: "[sdkToggleNavButton]"
Expand All @@ -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 = "";
}

Expand Down
4 changes: 2 additions & 2 deletions app/examples-list.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { NativeScriptCommonModule } from "nativescript-angular/common";
import { NativeScriptRouterModule } from "@nativescript/angular";
import { NativeScriptCommonModule } from "@nativescript/angular";
import { ExamplesListComponent } from "./examples-list.component";
import { TitleAndNavButtonModule } from "./directives/title-and-nav-button.module";

Expand Down
8 changes: 4 additions & 4 deletions app/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { platformNativeScriptDynamic } from "nativescript-angular/platform";
import { platformNativeScriptDynamic } from "@nativescript/angular";
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);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { NativeScriptCommonModule } from "nativescript-angular/common";
import { NativeScriptRouterModule } from "@nativescript/angular";
import { NativeScriptCommonModule } from "@nativescript/angular";
import { ApplicationSettingsExamplesComponent } from "./application-settings-examples.component";
import { UsageComponent } from "./usage/usage.component";
import { TitleAndNavButtonModule } from "../../directives/title-and-nav-button.module";
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from "@angular/core";
import { android as androidApp, ios as iosApp } from "tns-core-modules/application";
import { Application, isAndroid, isIOS } from "@nativescript/core";

@Component({
moduleId: module.id,
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -60,15 +60,15 @@ 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;
}
}

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
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from "@angular/core";
import { android as androidApp, ios as iosApp } from "tns-core-modules/application";
import { Application, isAndroid, isIOS } from "@nativescript/core";

@Component({
moduleId: module.id,
Expand All @@ -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;
Expand All @@ -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);
});
Expand All @@ -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;
}
}
Expand Down
Loading