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 4f6a2d0b0863b10f35f8ddb89ff5511966553219..0f887c63b05233df751054b7cd61e13d2a0a2140 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;