Skip to content

Commit 6f118a6

Browse files
committed
fix(dialogs): android ensure keyboard is hidden on alert dismiss
1 parent 915f166 commit 6f118a6

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/dialogs/dialogs.android.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
fromObject,
1818
inputType
1919
} from '@nativescript/core';
20+
import { ad } from '@nativescript/core/utils';
2021
import { LoginOptions, MDCAlertControlerOptions, PromptOptions } from './dialogs';
2122
import { isDialogOptions } from './dialogs-common';
2223

@@ -62,8 +63,8 @@ function createAlertDialogBuilder(options?: DialogOptions & MDCAlertControlerOpt
6263
options.view instanceof View
6364
? options.view
6465
: Builder.createViewFromEntry({
65-
moduleName: options.view as string
66-
});
66+
moduleName: options.view as string
67+
});
6768

6869
view.cssClasses.add(CSSUtils.MODAL_ROOT_VIEW_CSS_CLASS);
6970
const modalRootViewCssClasses = CSSUtils.getSystemCssClasses();
@@ -128,17 +129,15 @@ function showDialog(dlg: androidx.appcompat.app.AlertDialog, options: DialogOpti
128129

129130
// let { color, backgroundColor } = getButtonColors();
130131

131-
132-
133132
if (options.buttonInkColor || options.buttonTitleColor) {
134133
dlg.create();
135134
const buttons: com.google.android.material.button.MaterialButton[] = [];
136135
for (let i = -1; i > -4; i--) {
137136
buttons.push(dlg.getButton(i) as com.google.android.material.button.MaterialButton);
138137
}
139138

140-
const nInkColor = options.buttonInkColor && getColorStateList(options.buttonInkColor.android);
141-
const nTitleColor = options.buttonTitleColor && getColorStateList(options.buttonTitleColor.android);
139+
const nInkColor = options.buttonInkColor && getColorStateList(options.buttonInkColor.android);
140+
const nTitleColor = options.buttonTitleColor && getColorStateList(options.buttonTitleColor.android);
142141

143142
buttons.forEach((button) => {
144143
if (button) {
@@ -171,6 +170,9 @@ function prepareAndCreateAlertDialog(
171170
if (onDoneCalled) {
172171
return;
173172
}
173+
//ensure we hide any keyboard
174+
const imm = ad.getApplicationContext().getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
175+
imm.toggleSoftInput(android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
174176
onDoneCalled = true;
175177
if (options.view instanceof View) {
176178
Utils.android.dismissSoftInput(options.view.nativeView);
@@ -343,8 +345,8 @@ export function confirm(arg: any): Promise<boolean> {
343345
defaultOptions,
344346
!isDialogOptions(arg)
345347
? {
346-
message: arg + ''
347-
}
348+
message: arg + ''
349+
}
348350
: arg
349351
);
350352
const alert = createAlertDialogBuilder(options);

0 commit comments

Comments
 (0)