mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(android): Utils.dismissKeyboard() not working with modal (#10375)
This commit is contained in:
committed by
GitHub
parent
6f599fef1c
commit
6d44c2d6e0
@@ -1,5 +1,6 @@
|
||||
import { Application } from '../../application';
|
||||
import { Trace } from '../../trace';
|
||||
import { topmost } from '../../ui/frame/frame-stack';
|
||||
|
||||
let application: android.app.Application;
|
||||
let applicationContext: android.content.Context;
|
||||
@@ -67,7 +68,9 @@ export function dismissSoftInput(nativeView?: android.view.View): void {
|
||||
}
|
||||
windowToken = nativeView.getWindowToken();
|
||||
} else if (getCurrentActivity() instanceof androidx.appcompat.app.AppCompatActivity) {
|
||||
const decorView = getCurrentActivity().getWindow().getDecorView();
|
||||
const modalDialog = (topmost()?._modalParent ?? topmost())?.modal?._dialogFragment?.getDialog();
|
||||
const window = (modalDialog ?? getCurrentActivity()).getWindow();
|
||||
const decorView = window.getDecorView();
|
||||
if (decorView) {
|
||||
windowToken = decorView.getWindowToken();
|
||||
decorView.requestFocus();
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Trace } from '../trace';
|
||||
import { getFileExtension } from './common';
|
||||
import { SDK_VERSION } from './constants';
|
||||
import { android as AndroidUtils } from './native-helper';
|
||||
import { topmost } from '../ui/frame/frame-stack';
|
||||
|
||||
export { clearInterval, clearTimeout, setInterval, setTimeout } from '../timer';
|
||||
export * from './common';
|
||||
@@ -178,10 +179,10 @@ export function dismissSoftInput(nativeView?: any): void {
|
||||
|
||||
export function dismissKeyboard() {
|
||||
dismissSoftInput();
|
||||
|
||||
const activity = AndroidUtils.getCurrentActivity();
|
||||
if (activity) {
|
||||
const focus = activity.getCurrentFocus();
|
||||
const modalDialog = (topmost()?._modalParent ?? topmost())?.modal?._dialogFragment?.getDialog();
|
||||
const view = modalDialog ?? AndroidUtils.getCurrentActivity();
|
||||
if (view) {
|
||||
const focus = view.getCurrentFocus();
|
||||
|
||||
if (focus) {
|
||||
focus.clearFocus();
|
||||
|
||||
Reference in New Issue
Block a user