diff --git a/apps/toolbox/src/main-page.xml b/apps/toolbox/src/main-page.xml
index 5f8c600f1..45d5f51a3 100644
--- a/apps/toolbox/src/main-page.xml
+++ b/apps/toolbox/src/main-page.xml
@@ -10,6 +10,7 @@
+
diff --git a/apps/toolbox/src/pages/a11y.xml b/apps/toolbox/src/pages/a11y.xml
index d8c62cb36..1e65f3070 100644
--- a/apps/toolbox/src/pages/a11y.xml
+++ b/apps/toolbox/src/pages/a11y.xml
@@ -25,10 +25,10 @@
-
+
-
+
diff --git a/apps/toolbox/src/pages/dialogs.ts b/apps/toolbox/src/pages/dialogs.ts
new file mode 100644
index 000000000..eae02f2bd
--- /dev/null
+++ b/apps/toolbox/src/pages/dialogs.ts
@@ -0,0 +1,37 @@
+import { Page, Observable, EventData, Dialogs } from '@nativescript/core';
+
+let page: Page;
+
+export function navigatingTo(args: EventData) {
+ page = args.object;
+ page.bindingContext = new SampleData();
+}
+
+export class SampleData extends Observable {
+ dialogAlert() {
+ Dialogs.alert('Hello');
+ }
+ dialogAlertWithOptions() {
+ Dialogs.alert({
+ title: 'Hello',
+ message: 'Oh hi!',
+ okButtonText: 'Nice',
+ });
+ }
+ dialogConfirm() {
+ Dialogs.confirm('Is it?').then((ok) => {
+ Dialogs.alert('Ok then!');
+ });
+ }
+
+ dialogLogin() {
+ Dialogs.login('Login').then((result) => {
+ console.log(result);
+ });
+ }
+ dialogAction() {
+ Dialogs.action('Actions', 'Cancel', ['Test', 'Testing']).then((result) => {
+ console.log(result);
+ });
+ }
+}
diff --git a/apps/toolbox/src/pages/dialogs.xml b/apps/toolbox/src/pages/dialogs.xml
new file mode 100644
index 000000000..fb0977658
--- /dev/null
+++ b/apps/toolbox/src/pages/dialogs.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/core/ui/dialogs/index.android.ts b/packages/core/ui/dialogs/index.android.ts
index 79932e18a..28b88bc14 100644
--- a/packages/core/ui/dialogs/index.android.ts
+++ b/packages/core/ui/dialogs/index.android.ts
@@ -3,7 +3,7 @@
*/
import { DialogOptions, ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from './dialogs-common';
import { getLabelColor, getButtonColors, isDialogOptions, inputType, capitalizationType, DialogStrings, parseLoginOptions } from './dialogs-common';
-import { android as androidApp } from '../../application';
+import { ad } from '../../utils/native-helper';
export * from './dialogs-common';
@@ -12,7 +12,7 @@ function isString(value): value is string {
}
function createAlertDialog(options?: DialogOptions): android.app.AlertDialog.Builder {
- const alert = new android.app.AlertDialog.Builder(androidApp.foregroundActivity, options.theme ? options.theme : -1);
+ const alert = new android.app.AlertDialog.Builder(ad.getCurrentActivity(), options.theme ? options.theme : -1);
alert.setTitle(options && isString(options.title) ? options.title : '');
alert.setMessage(options && isString(options.message) ? options.message : '');
if (options && options.cancelable === false) {
@@ -202,7 +202,7 @@ export function prompt(...args): Promise {
try {
const alert = createAlertDialog(options);
- const input = new android.widget.EditText(androidApp.foregroundActivity);
+ const input = new android.widget.EditText(ad.getCurrentActivity());
if (options) {
if (options.inputType === inputType.password) {
@@ -257,23 +257,21 @@ export function login(...args: any[]): Promise {
return new Promise((resolve, reject) => {
try {
- const context = androidApp.foregroundActivity;
-
const alert = createAlertDialog(options);
- const userNameInput = new android.widget.EditText(context);
+ const userNameInput = new android.widget.EditText(ad.getApplicationContext());
userNameInput.setHint(options.userNameHint ? options.userNameHint : '');
userNameInput.setText(options.userName ? options.userName : '');
- const passwordInput = new android.widget.EditText(context);
+ const passwordInput = new android.widget.EditText(ad.getApplicationContext());
passwordInput.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordInput.setTypeface(android.graphics.Typeface.DEFAULT);
passwordInput.setHint(options.passwordHint ? options.passwordHint : '');
passwordInput.setText(options.password ? options.password : '');
- const layout = new android.widget.LinearLayout(context);
+ const layout = new android.widget.LinearLayout(ad.getApplicationContext());
layout.setOrientation(1);
layout.addView(userNameInput);
layout.addView(passwordInput);
@@ -324,8 +322,7 @@ export function action(...args): Promise {
return new Promise((resolve, reject) => {
try {
- const activity = androidApp.foregroundActivity || androidApp.startActivity;
- const alert = new android.app.AlertDialog.Builder(activity, options.theme ? options.theme : -1);
+ const alert = new android.app.AlertDialog.Builder(ad.getCurrentActivity(), options.theme ? options.theme : -1);
const message = options && isString(options.message) ? options.message : '';
const title = options && isString(options.title) ? options.title : '';
if (options && options.cancelable === false) {
diff --git a/packages/core/ui/frame/index.android.ts b/packages/core/ui/frame/index.android.ts
index 337198e68..f0c7b4537 100644
--- a/packages/core/ui/frame/index.android.ts
+++ b/packages/core/ui/frame/index.android.ts
@@ -21,6 +21,7 @@ import { Device } from '../../platform';
import { profile } from '../../profiling';
import { android as androidApplication } from '../../application';
import { setSuspended } from '../../application/application-common';
+import { ad } from '../../utils/native-helper';
export * from './frame-common';
@@ -94,7 +95,7 @@ export class Frame extends FrameBase {
}
public static reloadPage(context?: ModuleContext): void {
- const activity = application.android.foregroundActivity;
+ const activity = ad.getCurrentActivity();
const callbacks: AndroidActivityCallbacks = activity[CALLBACKS];
if (callbacks) {
const rootView: View = callbacks.getRootView();
@@ -147,7 +148,8 @@ export class Frame extends FrameBase {
// _onAttachedToWindow called from OS again after it was detach
// still happens with androidx.fragment:1.3.2
- const lifecycleState = (androidApplication.foregroundActivity?.getLifecycle?.() || androidApplication.startActivity?.getLifecycle?.())?.getCurrentState() || androidx.lifecycle.Lifecycle.State.CREATED;
+ const activity = ad.getCurrentActivity();
+ const lifecycleState = activity?.getLifecycle?.()?.getCurrentState() || androidx.lifecycle.Lifecycle.State.CREATED;
if ((this._manager && this._manager.isDestroyed()) || !lifecycleState.isAtLeast(androidx.lifecycle.Lifecycle.State.CREATED)) {
return;
}
diff --git a/packages/core/utils/mainthread-helper.android.ts b/packages/core/utils/mainthread-helper.android.ts
index 1838a6a6c..8f47797a9 100644
--- a/packages/core/utils/mainthread-helper.android.ts
+++ b/packages/core/utils/mainthread-helper.android.ts
@@ -1,4 +1,4 @@
-import { android as ad } from '../application';
+import { ad } from './native-helper';
export function dispatchToMainThread(func: () => void) {
const runOnMainThread = (global as any).__runOnMainThread;
@@ -20,7 +20,7 @@ export function isMainThread(): boolean {
}
export function dispatchToUIThread(func: () => void) {
- const activity: androidx.appcompat.app.AppCompatActivity = ad.foregroundActivity || ad.startActivity;
+ const activity: androidx.appcompat.app.AppCompatActivity = ad.getCurrentActivity();
if (activity && func) {
activity.runOnUiThread(
new java.lang.Runnable({