From c0122266c5aba73046fffff3c160a6f91786b9aa Mon Sep 17 00:00:00 2001 From: cheng-feiwang Date: Thu, 14 Aug 2025 20:19:42 +0800 Subject: [PATCH] fix sheet will not avoidKeyBoard when not focused Signed-off-by: cheng-feiwang Change-Id: I0c862dea2c4af601f17d0e313c0192225902e58c --- .../pattern/overlay/sheet_presentation_pattern.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp index 4f6a2d0b086..0f887c63b05 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp @@ -3122,7 +3122,9 @@ void SheetPresentationPattern::AvoidKeyboardBySheetMode(bool forceAvoid) if (keyboardHeight_ == manager->GetKeyboardInset().Length() && !forceAvoid) { return; } - keyboardHeight_ = manager->GetKeyboardInset().Length(); + CHECK_NULL_VOID(host->GetFocusHub()); + bool isCurrentFocus = host->GetFocusHub()->IsCurrentFocus(); + keyboardHeight_ = isCurrentFocus ? manager->GetKeyboardInset().Length() : 0; if (isDismissProcess_) { TAG_LOGD(AceLogTag::ACE_SHEET, "Sheet will disappear, not need to handle canceling keyboard avoidance here."); @@ -3135,7 +3137,6 @@ void SheetPresentationPattern::AvoidKeyboardBySheetMode(bool forceAvoid) } // 2.handle upward logic - CHECK_NULL_VOID(host->GetFocusHub()); // When bindSheet lift height exceed the max height, hightUp = the remaining height that needs to scroll, // otherwise, hightUp = the height to be lifted up auto heightUp = host->GetFocusHub()->IsCurrentFocus() ? GetSheetHeightChange() : 0.0f; -- Gitee