!36151 修复输入框动态切换padding非法值未走默认值

Merge pull request !36151 from 李娟/textinput
This commit is contained in:
openharmony_ci 2024-06-25 06:43:41 +00:00 committed by Gitee
commit 1d1e8abb25
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 24 additions and 47 deletions

View File

@ -708,6 +708,7 @@ void JSTextField::JsPadding(const JSCallbackInfo& info)
CalcDimension length;
ParseJsDimensionVp(jsValue, length);
if (length.IsNegative()) {
TextFieldModel::GetInstance()->SetPadding(NG::PaddingProperty(), Edge(), true);
return;
}
bool tmp = !jsValue->IsString() && !jsValue->IsNumber() && !jsValue->IsObject();

View File

@ -466,7 +466,7 @@ void TextFieldModelImpl::SetHeight(const Dimension& value)
textInputComponent->SetHeight(value);
}
void TextFieldModelImpl::SetPadding(NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp)
void TextFieldModelImpl::SetPadding(const NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp)
{
if (tmp) {
return;

View File

@ -76,7 +76,7 @@ public:
void SetOnChangeEvent(std::function<void(const std::string&)>&& func) override {};
void SetBackgroundColor(const Color& color, bool tmp) override;
void SetHeight(const Dimension& value) override;
void SetPadding(NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) override;
void SetPadding(const NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) override;
void SetBackBorder() override;
void SetHoverEffect(HoverEffectType value) override;
void SetOnClick(std::function<void(const ClickInfo&)>&& func) override;

View File

@ -304,7 +304,7 @@ public:
virtual void SetForegroundColor(const Color& value) = 0;
virtual void SetBackgroundColor(const Color& color, bool tmp) = 0;
virtual void SetHeight(const Dimension& value) = 0;
virtual void SetPadding(NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) = 0;
virtual void SetPadding(const NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) = 0;
virtual void SetMargin() {};
virtual void SetBackBorder() {};
virtual void SetHoverEffect(HoverEffectType hoverEffect) = 0;

View File

@ -690,57 +690,32 @@ void TextFieldModelNG::SetMargin()
ACE_UPDATE_PAINT_PROPERTY(TextFieldPaintProperty, MarginByUser, userMargin);
}
void TextFieldModelNG::SetPadding(NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp)
void TextFieldModelNG::SetPadding(const NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp)
{
if (tmp) {
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto theme = pipeline->GetThemeManager()->GetTheme<TextFieldTheme>();
CHECK_NULL_VOID(theme);
auto textFieldPadding = theme->GetPadding();
auto top = textFieldPadding.Top();
auto bottom = textFieldPadding.Bottom();
auto left = textFieldPadding.Left();
auto right = textFieldPadding.Right();
NG::PaddingProperty paddings;
if (top.Value()) {
if (top.Unit() == DimensionUnit::CALC) {
paddings.top = NG::CalcLength(top.IsNonNegative() ? top.CalcValue() : CalcDimension().CalcValue());
} else {
paddings.top = NG::CalcLength(top.IsNonNegative() ? top : CalcDimension());
}
}
if (bottom.Value()) {
if (bottom.Unit() == DimensionUnit::CALC) {
paddings.bottom =
NG::CalcLength(bottom.IsNonNegative() ? bottom.CalcValue() : CalcDimension().CalcValue());
} else {
paddings.bottom = NG::CalcLength(bottom.IsNonNegative() ? bottom : CalcDimension());
}
}
if (left.Value()) {
if (left.Unit() == DimensionUnit::CALC) {
paddings.left = NG::CalcLength(left.IsNonNegative() ? left.CalcValue() : CalcDimension().CalcValue());
} else {
paddings.left = NG::CalcLength(left.IsNonNegative() ? left : CalcDimension());
}
}
if (right.Value()) {
if (right.Unit() == DimensionUnit::CALC) {
paddings.right =
NG::CalcLength(right.IsNonNegative() ? right.CalcValue() : CalcDimension().CalcValue());
} else {
paddings.right = NG::CalcLength(right.IsNonNegative() ? right : CalcDimension());
}
}
ViewAbstract::SetPadding(paddings);
SetDefaultPadding();
return;
}
NG::ViewAbstract::SetPadding(newPadding);
ACE_UPDATE_PAINT_PROPERTY(TextFieldPaintProperty, PaddingByUser, newPadding);
}
void TextFieldModelNG::SetDefaultPadding()
{
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto theme = pipeline->GetThemeManager()->GetTheme<TextFieldTheme>();
CHECK_NULL_VOID(theme);
auto themePadding = theme->GetPadding();
PaddingProperty paddings;
paddings.top = NG::CalcLength(themePadding.Top().ConvertToPx());
paddings.bottom = NG::CalcLength(themePadding.Bottom().ConvertToPx());
paddings.left = NG::CalcLength(themePadding.Left().ConvertToPx());
paddings.right = NG::CalcLength(themePadding.Right().ConvertToPx());
ViewAbstract::SetPadding(paddings);
ACE_UPDATE_PAINT_PROPERTY(TextFieldPaintProperty, PaddingByUser, paddings);
}
void TextFieldModelNG::SetHoverEffect(HoverEffectType hoverEffect)
{
NG::ViewAbstract::SetHoverEffect(hoverEffect);

View File

@ -89,7 +89,7 @@ public:
void SetOnChangeEvent(std::function<void(const std::string&)>&& func) override;
void SetBackgroundColor(const Color& color, bool tmp) override;
void SetHeight(const Dimension& value) override;
void SetPadding(NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) override;
void SetPadding(const NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) override;
void SetMargin() override;
void SetHoverEffect(HoverEffectType hoverEffect) override;
void SetSelectionMenuHidden(bool contextMenuHidden) override;
@ -275,6 +275,7 @@ private:
void AddDragFrameNodeToManager() const;
void SetDraggable(bool draggable);
void SetTextRectWillChange();
void SetDefaultPadding();
};
} // namespace OHOS::Ace::NG