新框架输入框拉起输入法部分情况不抬起

Signed-off-by: xiexiyun <xiexiyun@huawei.com>
Change-Id: I34943d01bcaefb4bc02b6b49bb46a79c678b7815
This commit is contained in:
xiexiyun 2022-11-22 21:30:50 +08:00
parent 1339553517
commit f5e96450bc
7 changed files with 39 additions and 5 deletions

View File

@ -60,6 +60,16 @@ void TextFieldManager::MovePage(int32_t pageId, const Offset& rootRect, double o
}
}
void TextFieldManager::SetHeight(float height)
{
height_ = height;
}
float TextFieldManager::GetHeight() const
{
return height_;
}
void TextFieldManager::RemovePageId(int32_t pageId)
{
scrollMap_.erase(pageId);

View File

@ -53,10 +53,14 @@ public:
bool ResetSlidingPanelParentHeight();
bool UpdatePanelForVirtualKeyboard(double offsetY, double fullHeight);
void SetHeight(float height);
float GetHeight() const;
private:
bool hasMove_ = false;
Offset position_;
float height_ = 0.0f;
std::unordered_map<int32_t, WeakPtr<ScrollElement>> scrollMap_;
WeakPtr<RenderTextField> onFocusTextField_;
};

View File

@ -22,6 +22,16 @@ void TextFieldManager::SetClickPosition(const Offset& position)
position_ = position;
}
void TextFieldManager::SetHeight(float height)
{
height_ = height;
}
float TextFieldManager::GetHeight() const
{
return height_;
}
const Offset& TextFieldManager::GetClickPosition()
{
return position_;

View File

@ -48,10 +48,14 @@ public:
bool ResetSlidingPanelParentHeight();
bool UpdatePanelForVirtualKeyboard(double offsetY, double fullHeight);
void SetHeight(float height);
float GetHeight() const;
private:
bool hasMove_ = false;
Offset position_;
float height_ = 0.0f;
WeakPtr<TextFieldPattern> onFocusTextField_;
};

View File

@ -880,7 +880,7 @@ void TextFieldPattern::HandleTouchEvent(const TouchEventInfo& info)
auto touchType = info.GetTouches().front().GetTouchType();
if (touchType == TouchType::DOWN) {
HandleTouchDown(info.GetTouches().front().GetLocalLocation());
UpdateTextFieldManager(info.GetTouches().front().GetGlobalLocation());
UpdateTextFieldManager(info.GetTouches().front().GetGlobalLocation(), frameRect_.Height());
} else if (touchType == TouchType::UP) {
HandleTouchUp();
}
@ -958,7 +958,7 @@ void TextFieldPattern::InitClickEvent()
void TextFieldPattern::HandleClickEvent(GestureEvent& info)
{
UpdateTextFieldManager(info.GetGlobalLocation());
UpdateTextFieldManager(info.GetGlobalLocation(), frameRect_.Height());
auto focusHub = GetHost()->GetOrCreateFocusHub();
if (!focusHub->IsFocusable()) {
return;
@ -1128,13 +1128,14 @@ void TextFieldPattern::UpdatePositionOfParagraph(int32_t position)
textEditingValue_.CursorMoveToPosition(position);
}
void TextFieldPattern::UpdateTextFieldManager(const Offset& offset)
void TextFieldPattern::UpdateTextFieldManager(const Offset& offset, float height)
{
auto context = GetHost()->GetContext();
CHECK_NULL_VOID(context);
auto textFieldManager = DynamicCast<TextFieldManager>(context->GetTextFieldManager());
CHECK_NULL_VOID(textFieldManager);
textFieldManager->SetClickPosition(offset);
textFieldManager->SetHeight(height);
textFieldManager->SetOnFocusTextField(WeakClaim(this));
}

View File

@ -342,7 +342,7 @@ private:
void StopTwinkling();
void SetCaretOffsetXForEmptyText();
void UpdateTextFieldManager(const Offset& offset);
void UpdateTextFieldManager(const Offset& offset, float height);
void OnTextInputActionUpdate(TextInputAction value);
std::u16string GetTextForDisplay() const;

View File

@ -514,8 +514,10 @@ void PipelineContext::OnVirtualKeyboardHeightChange(float keyboardHeight)
{
CHECK_RUN_ON(UI);
float positionY = 0;
auto manager = PipelineBase::GetTextFieldManager();
auto manager = DynamicCast<TextFieldManager>(PipelineBase::GetTextFieldManager());
float height = 0.0f;
if (manager) {
height = manager->GetHeight();
positionY = static_cast<float>(manager->GetClickPosition().GetY());
}
auto rootSize = rootNode_->GetGeometryNode()->GetFrameSize();
@ -527,6 +529,9 @@ void PipelineContext::OnVirtualKeyboardHeightChange(float keyboardHeight)
SetRootRect(rootSize.Width(), rootSize.Height(), 0);
} else if (positionY > (rootSize.Height() - keyboardHeight) && offsetFix > 0.0) {
SetRootRect(rootSize.Width(), rootSize.Height(), -offsetFix);
} else if (positionY + height > rootSize.Height() - keyboardHeight &&
positionY < rootSize.Height() - keyboardHeight && height < keyboardHeight / 2.0f) {
SetRootRect(rootSize.Width(), rootSize.Height(), -height - offsetFix / 2.0f);
}
}