diff --git a/product/default/dialog/src/main/ets/pages/ExtIndex.ets b/product/default/dialog/src/main/ets/pages/ExtIndex.ets index 5ec83f3e076f61ce6f26ff2b6d506cf6775ad391..ef1c081d7859b7549fa956ea52e23dae3ee7a1b0 100644 --- a/product/default/dialog/src/main/ets/pages/ExtIndex.ets +++ b/product/default/dialog/src/main/ets/pages/ExtIndex.ets @@ -17,6 +17,7 @@ import rpc from '@ohos.rpc'; import Log from '../../../../../../../common/src/main/ets/default/Log'; import Constants from '../common/Constants'; import type { IDialogParameters } from '../controller/Controller'; +import inputMethod from '@ohos.inputMethod'; const TAG = 'Dialog-Index'; @@ -28,13 +29,44 @@ struct Index { @LocalStorageProp('connectId') connectId: string = undefined; @LocalStorageProp('windowName') windowName: string = undefined; @LocalStorageProp('parameters') parameters: IDialogParameters = undefined; + @State inputMethodSetting: inputMethod.InputMethodSetting = undefined; + @State keyboardHeight: number = 0; aboutToAppear() { - Log.showInfo(TAG, `aboutToAppear r ${this.connectId} ${this.windowName} ${JSON.stringify(this.parameters)}`) + Log.showInfo(TAG, `aboutToAppear r ${this.connectId} ${this.windowName} ${JSON.stringify(this.parameters)}`); + this.initListenKeyboard(); } aboutToDisappear() { - Log.showInfo(TAG, `aboutToDisappear ${this.connectId} ${this.windowName} ${JSON.stringify(this.parameters)}`) + Log.showInfo(TAG, `aboutToDisappear ${this.connectId} ${this.windowName} ${JSON.stringify(this.parameters)}`); + this.cancelListenKeyboard(); + } + + initListenKeyboard() { + Log.showInfo(TAG, 'initListenKeyboard in'); + try { + this.inputMethodSetting = inputMethod.getSetting(); + this.inputMethodSetting.on('imeShow', (info: inputMethod.InputWindowInfo[]) => { + Log.showInfo(TAG, 'Succeeded in subscribing imeShow event. height: ' + info[0].height); + this.keyboardHeight = info[0]?.height/2; + }); + this.inputMethodSetting.on('imeHide', (info: inputMethod.InputWindowInfo[]) => { + Log.showInfo(TAG, 'Succeeded in subscribing imeHide event. height: 0'); + this.keyboardHeight = 0; + }); + } catch (e) { + Log.showError('initListenKeyboard error', e); + } + } + + cancelListenKeyboard() { + Log.showInfo(TAG, 'cancelListenKeyboard in'); + try { + this.inputMethodSetting.off('imeShow'); + this.inputMethodSetting.off('imeHide'); + } catch (e) { + Log.showError('cancelListenKeyboard error', e); + } } onOk() { @@ -85,5 +117,6 @@ struct Index { } .width('100%') .height('100%') + .border({ width: { bottom: this.keyboardHeight }}) } }