From 7d75c6f42ccc4b6795f84cb06b22d2ce793008ad Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Mon, 16 Nov 2020 09:28:43 +0100 Subject: [PATCH 1/2] fix android modal not following activity windowSoftInputMode Also added an android modal parameter to set a custom windowSoftInputMode --- packages/core/ui/core/view-base/index.d.ts | 4 +++ packages/core/ui/core/view-base/index.ts | 5 ++++ packages/core/ui/core/view/index.android.ts | 30 +++++++++++++++++---- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/packages/core/ui/core/view-base/index.d.ts b/packages/core/ui/core/view-base/index.d.ts index 4e7313dbd..b71b0919f 100644 --- a/packages/core/ui/core/view-base/index.d.ts +++ b/packages/core/ui/core/view-base/index.d.ts @@ -83,6 +83,10 @@ export interface ShowModalOptions { * An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode. */ cancelable?: boolean; + /** + * An optional parameter specifying the windowSoftInputMode of the dialog window + */ + windowSoftInputMode?: number; }; /** * An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode. diff --git a/packages/core/ui/core/view-base/index.ts b/packages/core/ui/core/view-base/index.ts index 67e4010b0..0615f6ed9 100644 --- a/packages/core/ui/core/view-base/index.ts +++ b/packages/core/ui/core/view-base/index.ts @@ -87,6 +87,11 @@ export interface ShowModalOptions { * An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode. */ cancelable?: boolean; + + /** + * An optional parameter specifying the windowSoftInputMode of the dialog window + */ + windowSoftInputMode?: number; }; /** * An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode. diff --git a/packages/core/ui/core/view/index.android.ts b/packages/core/ui/core/view/index.android.ts index 0a3e50b7b..d70a36347 100644 --- a/packages/core/ui/core/view/index.android.ts +++ b/packages/core/ui/core/view/index.android.ts @@ -76,6 +76,7 @@ interface DialogOptions { animated: boolean; stretched: boolean; cancelable: boolean; + windowSoftInputMode: number; shownCallback: () => void; dismissCallback: () => void; } @@ -168,6 +169,7 @@ function initializeDialogFragment() { class DialogFragmentImpl extends androidx.fragment.app.DialogFragment { public owner: View; private _fullscreen: boolean; + private _windowSoftInputMode: number; private _animated: boolean; private _stretched: boolean; private _cancelable: boolean; @@ -192,6 +194,7 @@ function initializeDialogFragment() { this._stretched = options.stretched; this._dismissCallback = options.dismissCallback; this._shownCallback = options.shownCallback; + this._windowSoftInputMode = options.windowSoftInputMode; this.setStyle(androidx.fragment.app.DialogFragment.STYLE_NO_TITLE, 0); let theme = this.getTheme(); @@ -243,8 +246,20 @@ function initializeDialogFragment() { } const owner = this.owner; - if (owner && !owner.isLoaded) { - owner.callLoaded(); + if (owner) { + if (!owner.isLoaded) { + owner.callLoaded(); + } + + + const window = this.getDialog().getWindow(); + if (this._windowSoftInputMode !== undefined) { + window.setSoftInputMode(this._windowSoftInputMode); + } else { + // the dialog seems to not follow the default activity softinputmode, + // thus set we set it here. + window.setSoftInputMode((owner._context).getWindow().getAttributes().softInputMode); + } } this._shownCallback(); @@ -672,10 +687,14 @@ export class View extends ViewCommon { df.setArguments(args); let cancelable = true; + let windowSoftInputMode: number; - if (options.android && (options).android.cancelable !== undefined) { - cancelable = !!(options).android.cancelable; - console.log('ShowModalOptions.android.cancelable is deprecated. Use ShowModalOptions.cancelable instead.'); + if (options.android) { + if ((options).android.cancelable !== undefined) { + cancelable = !!(options).android.cancelable; + console.log('ShowModalOptions.android.cancelable is deprecated. Use ShowModalOptions.cancelable instead.'); + } + windowSoftInputMode = (options).android.windowSoftInputMode; } cancelable = options.cancelable !== undefined ? !!options.cancelable : cancelable; @@ -686,6 +705,7 @@ export class View extends ViewCommon { animated: !!options.animated, stretched: !!options.stretched, cancelable: cancelable, + windowSoftInputMode: windowSoftInputMode, shownCallback: () => this._raiseShownModallyEvent(), dismissCallback: () => this.closeModal(), }; From 99a11e832c752fe524a1ae4212698d407e2e833d Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Mon, 16 Nov 2020 09:44:58 +0100 Subject: [PATCH 2/2] fix softInputMode set too soon --- packages/core/ui/core/view/index.android.ts | 26 ++++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/core/ui/core/view/index.android.ts b/packages/core/ui/core/view/index.android.ts index d70a36347..bc238a98a 100644 --- a/packages/core/ui/core/view/index.android.ts +++ b/packages/core/ui/core/view/index.android.ts @@ -232,6 +232,16 @@ function initializeDialogFragment() { owner._setupAsRootView(this.getActivity()); owner._isAddedToNativeVisualTree = true; + // we need to set the window SoftInputMode here. + // it wont work is set in onStart + const window = this.getDialog().getWindow(); + if (this._windowSoftInputMode !== undefined) { + window.setSoftInputMode(this._windowSoftInputMode); + } else { + // the dialog seems to not follow the default activity softinputmode, + // thus set we set it here. + window.setSoftInputMode((owner._context).getWindow().getAttributes().softInputMode); + } return owner.nativeViewProtected; } @@ -246,20 +256,8 @@ function initializeDialogFragment() { } const owner = this.owner; - if (owner) { - if (!owner.isLoaded) { - owner.callLoaded(); - } - - - const window = this.getDialog().getWindow(); - if (this._windowSoftInputMode !== undefined) { - window.setSoftInputMode(this._windowSoftInputMode); - } else { - // the dialog seems to not follow the default activity softinputmode, - // thus set we set it here. - window.setSoftInputMode((owner._context).getWindow().getAttributes().softInputMode); - } + if (owner && !owner.isLoaded) { + owner.callLoaded(); } this._shownCallback();