From dc95b7663f59cca841db62a351acf595865d872f Mon Sep 17 00:00:00 2001 From: "DESKTOP-9FJNTIC\\gyb" <121287102@qq.com> Date: Wed, 2 Jul 2025 11:07:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E7=82=B9=E5=87=BB=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=A9=BA=E7=99=BD=E5=A4=84=E5=8F=AF=E4=BB=A5=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E9=94=AE=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/MainPage.ets | 8 +++++++- entry/src/main/ets/view/TextInputComponent.ets | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/pages/MainPage.ets b/entry/src/main/ets/pages/MainPage.ets index 0195d7a..638dc0e 100644 --- a/entry/src/main/ets/pages/MainPage.ets +++ b/entry/src/main/ets/pages/MainPage.ets @@ -22,6 +22,7 @@ import { TextInputComponent } from '../view/TextInputComponent'; @Component struct MainPage { @State bottomPadding: number = 210; + @State isKeyboardShown: boolean = false; aboutToAppear(): void { let event: emitter.InnerEvent = { @@ -49,7 +50,7 @@ struct MainPage { .borderRadius(12) .padding({ left: $r('app.float.main_page_margin'), right: $r('app.float.main_page_margin') }) - TextInputComponent() + TextInputComponent({ isKeyboardShown: this.isKeyboardShown }) // [EndExclude MainPage_start] } .padding({ bottom: this.bottomPadding }) @@ -57,6 +58,11 @@ struct MainPage { .height('100%') .justifyContent(FlexAlign.End) .expandSafeArea([SafeAreaType.KEYBOARD, SafeAreaType.SYSTEM]) + .onClick(() => { + if (this.isKeyboardShown) { + this.isKeyboardShown = false; + } + }) // [EndExclude MainPage_start] } .mode(NavigationMode.Stack) diff --git a/entry/src/main/ets/view/TextInputComponent.ets b/entry/src/main/ets/view/TextInputComponent.ets index 3e043ca..da4703a 100644 --- a/entry/src/main/ets/view/TextInputComponent.ets +++ b/entry/src/main/ets/view/TextInputComponent.ets @@ -29,6 +29,7 @@ export struct TextInputComponent { @Provide systemKeyboardHeight: number = 0; @Provide customKeyboardHeight: number = 0; @Provide bottomRectHeight: number = 0; + @Link @Watch('onChangeKeyboard') isKeyboardShown: boolean; textInputController: TextInputController = new TextInputController(); aboutToAppear(): void { @@ -47,6 +48,13 @@ export struct TextInputComponent { }) }) } + + onChangeKeyboard() { + if (this.isKeyboardShown === false) { + this.textInputController.stopEditing(); + } + } + // [EndExclude TextInputComponent_start] // [Start customKeyboard_start] build() { @@ -79,10 +87,12 @@ export struct TextInputComponent { // [StartExclude TextInput_start] .onBlur(() => { this.isTabViewShow = false; + this.isKeyboardShown = false; this.keyBoardController.changeAvoidHeight(0); }) .onFocus(() => { this.isTabViewShow = true; + this.isKeyboardShown = true; }) .onChange((value) => { this.inputText = value; -- Gitee From 6089c4f75569cc8e6246580707b32afe9c06c05e Mon Sep 17 00:00:00 2001 From: "DESKTOP-9FJNTIC\\gyb" <121287102@qq.com> Date: Wed, 2 Jul 2025 11:34:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E7=82=B9=E5=87=BB=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=A9=BA=E7=99=BD=E5=A4=84=E5=8F=AF=E4=BB=A5=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E9=94=AE=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/MainPage.ets | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/entry/src/main/ets/pages/MainPage.ets b/entry/src/main/ets/pages/MainPage.ets index 638dc0e..9c0b128 100644 --- a/entry/src/main/ets/pages/MainPage.ets +++ b/entry/src/main/ets/pages/MainPage.ets @@ -58,13 +58,13 @@ struct MainPage { .height('100%') .justifyContent(FlexAlign.End) .expandSafeArea([SafeAreaType.KEYBOARD, SafeAreaType.SYSTEM]) - .onClick(() => { - if (this.isKeyboardShown) { - this.isKeyboardShown = false; - } - }) // [EndExclude MainPage_start] } + .onClick(() => { + if (this.isKeyboardShown) { + this.isKeyboardShown = false; + } + }) .mode(NavigationMode.Stack) .titleMode(NavigationTitleMode.Full) .title($r('app.string.main_page_title')) -- Gitee