mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: expose application orientation (#7602)
This commit is contained in:
@@ -1,21 +1,16 @@
|
||||
// >> application-require
|
||||
import * as app from "tns-core-modules/application";
|
||||
import * as app from "tns-core-modules/application";
|
||||
import * as platform from "tns-core-modules/platform";
|
||||
// << application-require
|
||||
|
||||
// >> application-app-check
|
||||
if (app.android) {
|
||||
console.log("We are running on Android device!");
|
||||
} else if (app.ios) {
|
||||
console.log("We are running on iOS device");
|
||||
}
|
||||
// << application-app-check
|
||||
|
||||
import * as TKUnit from "../tk-unit";
|
||||
|
||||
if (app.android) {
|
||||
console.log("We are running on an Android device!");
|
||||
} else if (app.ios) {
|
||||
console.log("We are running on an iOS device!");
|
||||
}
|
||||
|
||||
export function testInitialized() {
|
||||
if (platform.device.os === platform.platformNames.android) {
|
||||
// we have the android defined
|
||||
TKUnit.assert(app.android, "Application module not properly intialized");
|
||||
} else if (platform.device.os === platform.platformNames.ios) {
|
||||
TKUnit.assert(app.ios, "Application module not properly intialized");
|
||||
|
||||
@@ -37,12 +37,13 @@ if (app.android) {
|
||||
}
|
||||
// << application-app-android-broadcast
|
||||
|
||||
export var testAndroidApplicationInitialized = function () {
|
||||
export function testAndroidApplicationInitialized() {
|
||||
TKUnit.assert(app.android, "Android application not initialized.");
|
||||
TKUnit.assert(app.android.context, "Android context not initialized.");
|
||||
TKUnit.assert(app.android.foregroundActivity, "Android foregroundActivity not initialized.");
|
||||
TKUnit.assert(app.android.foregroundActivity.isNativeScriptActivity, "Andorid foregroundActivity.isNativeScriptActivity is true");
|
||||
TKUnit.assert(app.android.foregroundActivity.isNativeScriptActivity, "Andorid foregroundActivity.isNativeScriptActivity is false.");
|
||||
TKUnit.assert(app.android.startActivity, "Android startActivity not initialized.");
|
||||
TKUnit.assert(app.android.nativeApp, "Android nativeApp not initialized.");
|
||||
TKUnit.assert(app.android.orientation, "Android orientation not initialized.");
|
||||
TKUnit.assert(app.android.packageName, "Android packageName not initialized.");
|
||||
};
|
||||
}
|
||||
|
||||
4
tests/app/application/application-tests.d.ts
vendored
4
tests/app/application/application-tests.d.ts
vendored
@@ -1,4 +1,2 @@
|
||||
/* tslint:disable */
|
||||
//@private
|
||||
import * as android from "./application-tests.android";
|
||||
import * as iOS from "./application-tests.ios";
|
||||
import * as iOS from "./application-tests.ios";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
import * as app from "tns-core-modules/application";
|
||||
import * as TKUnit from "../tk-unit";
|
||||
|
||||
export * from "./application-tests-common";
|
||||
|
||||
@@ -39,3 +40,12 @@ if (app.ios) {
|
||||
}
|
||||
|
||||
// << application-ios-delegate
|
||||
|
||||
export function testIOSApplicationInitialized() {
|
||||
TKUnit.assert(app.ios, "iOS application not initialized.");
|
||||
TKUnit.assert(app.ios.delegate, "iOS delegate not initialized.");
|
||||
TKUnit.assert(app.ios.nativeApp, "iOS nativeApp not initialized.");
|
||||
TKUnit.assert(app.ios.orientation, "iOS orientation not initialized.");
|
||||
TKUnit.assert(app.ios.window, "iOS window not initialized.");
|
||||
TKUnit.assert(app.ios.rootController, "iOS root controller not initialized.");
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
---
|
||||
nav-title: "application How-To"
|
||||
title: "application"
|
||||
environment: nativescript
|
||||
description: "Examples for using application"
|
||||
previous_url: /ApiReference/application/HOW-TO
|
||||
---
|
||||
# Application
|
||||
The Application module provides abstraction over the platform-specific Application implementations.
|
||||
It is the main BCL module and is required for other BCL modules to work properly.
|
||||
The default bootstrap.js implementation for each platform loads and initializes this module.
|
||||
{%snippet application-require%}
|
||||
|
||||
The pre-required `app` module is used throughout the following code snippets.
|
||||
### Checking the target platform
|
||||
Use the following code in case you need to check somewhere in your code the platform you are running against:
|
||||
{%snippet application-app-check%}
|
||||
|
||||
### Using the Android-specific implementation
|
||||
Accessing the Android-specific object instance (will be undefined if running on iOS)
|
||||
|
||||
{%snippet application-app-android%}
|
||||
|
||||
### Using the Android Application context
|
||||
{%snippet application-app-android-context%}
|
||||
|
||||
### Tracking the current Activity
|
||||
{%snippet application-app-android-current%}
|
||||
|
||||
### Registering a Broadcast Receiver (Android)
|
||||
{%snippet application-app-android-broadcast%}
|
||||
|
||||
### Adding a Notification Observer (iOS)
|
||||
{%snippet application-ios-observer%}
|
||||
Reference in New Issue
Block a user