mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Added private Kimera build for UnitTestApp. Added Application module snippets.
This commit is contained in:
@ -114,8 +114,14 @@ export var waitUntilReady = function (isReady: () => boolean, timeoutSec?: numbe
|
||||
}
|
||||
};
|
||||
|
||||
var doModalAndroid = function (quitLoop: () => boolean, timeoutSec: number) {
|
||||
if (!quitLoop) {
|
||||
// Setup for the Android modal loop implementation
|
||||
// TODO: If these platform-specific implementations continue to grow, think of per-platform separation (TKUnit.android)
|
||||
var nextMethod;
|
||||
var targetField;
|
||||
var prepared;
|
||||
|
||||
var prepareModal = function () {
|
||||
if (prepared) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -143,6 +149,16 @@ var doModalAndroid = function (quitLoop: () => boolean, timeoutSec: number) {
|
||||
}
|
||||
}
|
||||
|
||||
prepared = true;
|
||||
}
|
||||
|
||||
var doModalAndroid = function (quitLoop: () => boolean, timeoutSec: number) {
|
||||
if (!quitLoop) {
|
||||
return;
|
||||
}
|
||||
|
||||
prepareModal();
|
||||
|
||||
var queue = android.os.Looper.myQueue();
|
||||
|
||||
var quit = false;
|
||||
|
@ -1,4 +1,35 @@
|
||||
import app = require("application/application");
|
||||
// <snippet name="application">
|
||||
// # 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.
|
||||
// ``` JavaScript
|
||||
import app = require("application/application");
|
||||
// ```
|
||||
// The pre-required `app` module is used throughout the following code snippets.
|
||||
// </snippet>
|
||||
|
||||
// <snippet name="application">
|
||||
// ### Initialization
|
||||
// ``` JavaScript
|
||||
//// The native app instance depends on the target platform
|
||||
var nativeAppInstance;
|
||||
app.init(nativeAppInstance);
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
// <snippet name="application">
|
||||
// ### Checking the target platform
|
||||
// Use the following code in case you need to check somewhere in your code the platform you are running against:
|
||||
// ``` JavaScript
|
||||
if (app.android) {
|
||||
//// we are running on Android device
|
||||
} else if (app.ios) {
|
||||
//// we are running on iOS device
|
||||
}
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
import TKUnit = require("Tests/TKUnit");
|
||||
|
||||
export var testInitDefined = function () {
|
||||
|
@ -6,11 +6,31 @@ import commonTests = require("Tests/application-tests-common");
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(commonTests, exports);
|
||||
|
||||
// <snippet name="application">
|
||||
// ### Using the Android-specific implementation
|
||||
// ``` JavaScript
|
||||
// Accessing the Android-specific object instance (will be undefined if running on iOS)
|
||||
var androidApp = app.android;
|
||||
// ```
|
||||
// Using the Android Application context
|
||||
// ``` JavaScript
|
||||
var context = app.android.context;
|
||||
//// get the Files (Documents) folder (directory)
|
||||
var dir = context.getFilesDir();
|
||||
// ```
|
||||
// Tracking the current Activity
|
||||
// ``` JavaScript
|
||||
if (androidApp.currentActivity === androidApp.startActivity) {
|
||||
//// We are currently in the main (start) activity of the application
|
||||
}
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
export var testAndroidApplicationInitialized = function () {
|
||||
TKUnit.assert(app.android, "Android application not initialized.");
|
||||
TKUnit.assert(app.android.context, "Android context not initialized.");
|
||||
TKUnit.assert(app.android.currentActivity, "Android currentActivity not initialized.");
|
||||
TKUnit.assert(app.android.startActivity, "Android mainActivity not initialized.");
|
||||
TKUnit.assert(app.android.startActivity, "Android startActivity not initialized.");
|
||||
TKUnit.assert(app.android.nativeApp, "Android nativeApp not initialized.");
|
||||
TKUnit.assert(app.android.packageName, "Android packageName not initialized.");
|
||||
}
|
@ -85,10 +85,17 @@ var initEvents = function () {
|
||||
return lifecycleCallbacks;
|
||||
}
|
||||
|
||||
var initialized;
|
||||
export var init = function (nativeApp: android.app.Application) {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
var app = new AndroidApplication(nativeApp);
|
||||
exports.android = app;
|
||||
app.init();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
class AndroidApplication {
|
||||
|
@ -26,11 +26,17 @@ import appModule = require("application/application-common");
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(appModule, exports);
|
||||
|
||||
// TODO: Declarations
|
||||
var initialized;
|
||||
export var init = function (nativeApp: any) {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
var app = new iOSApplication(nativeApp);
|
||||
exports.ios = app;
|
||||
app.init();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
class iOSApplication {
|
||||
|
Reference in New Issue
Block a user