!312 fix negative margin layout error

Merge pull request !312 from 蒋码云/master
This commit is contained in:
openharmony_ci
2021-10-27 12:20:32 +00:00
committed by Gitee
6 changed files with 47 additions and 37 deletions
@@ -22,7 +22,7 @@
namespace OHOS::Ace::Framework {
constexpr size_t MAX_COUNT = 9;
constexpr size_t MAX_COUNT = 9;
void JSDataPanel::JSBind(BindingTarget globalObj)
{
JSClass<JSDataPanel>::Declare("DataPanel");
@@ -45,30 +45,38 @@ void JSDataPanel::Create(const JSCallbackInfo& info)
LOGE("toggle create error, info is non-valid");
return;
}
RefPtr<PercentageDataPanelComponent> component =
AceType::MakeRefPtr<PercentageDataPanelComponent>(ChartType::RAINBOW);
auto paramObject = JSRef<JSObject>::Cast(info[0]);
auto max = paramObject->GetProperty("max");
if (max->IsNumber()) {
component->SetMaxValue(max->ToNumber<double>());
auto param = JsonUtil::ParseJsonString(info[0]->ToString());
if (!param || param->IsNull()) {
LOGE("JSDataPanel::Create param is null");
return;
}
JSRef<JSArray> values = paramObject->GetProperty("values");
for(size_t i = 0; i < values->Length() && i < MAX_COUNT; ++i) {
if (!values->GetValueAt(i)->IsNumber()) {
// max
auto max = param->GetDouble("max", 100.0);
component->SetMaxValue(max);
// values
auto values = param->GetValue("values");
if (!values || !values->IsArray()) {
LOGE("JSDataPanel::Create values is not array");
return;
}
size_t length = values->GetArraySize();
for (size_t i = 0; i < length && i < MAX_COUNT; i++) {
auto item = values->GetArrayItem(i);
if (!item || !item->IsNumber()) {
LOGE("JSDataPanel::Create value is not number");
return;
}
double value = values->GetValueAt(i)->ToNumber<double>();
auto value = item->GetDouble();
Segment segment;
segment.SetValue(value);
segment.SetColorType(SegmentStyleType::NONE);
component->AppendSegment(segment);
}
ViewStackProcessor::GetInstance()->Push(component);
RefPtr<ThemeManager> dataPanelManager = AceType::MakeRefPtr<ThemeManager>();
component->InitalStyle(dataPanelManager);
ViewStackProcessor::GetInstance()->Push(component);
}
void JSDataPanel::CloseEffect(const JSCallbackInfo& info)
@@ -531,7 +531,7 @@ JSValue JsUpdateElementAttrs(JSContext* ctx, JSValueConst value, int32_t argc, J
return JS_EXCEPTION;
}
auto page = GetRunningPage(ctx);
auto page = GetStagingPage(ctx);
if (page == nullptr) {
return JS_EXCEPTION;
}
@@ -478,11 +478,15 @@ void RenderBoxBase::CalculateSelfLayoutSize()
} else {
height = childSize_.Height() + padding_.GetLayoutSize().Height() + borderSize.Height();
}
double minWidth = padding_.GetLayoutSize().Width() + borderSize.Width();
double minHeight = padding_.GetLayoutSize().Height() + borderSize.Height();
width = width > minWidth ? width : minWidth;
height = height > minHeight ? height : minHeight;
const static int32_t PLATFORM_VERSION_SIX = 6;
auto context = GetContext().Upgrade();
if (context && context->GetMinPlatformVersion() >= PLATFORM_VERSION_SIX) {
double minWidth = padding_.GetLayoutSize().Width() + borderSize.Width();
double minHeight = padding_.GetLayoutSize().Height() + borderSize.Height();
width = width > minWidth ? width : minWidth;
height = height > minHeight ? height : minHeight;
}
// allow force layoutsize for parend
if (layoutSetByParent.GetMaxSize().Width() == layoutSetByParent.GetMinSize().Width()) {
width = layoutSetByParent.GetMinSize().Width();
@@ -492,19 +496,16 @@ void RenderBoxBase::CalculateSelfLayoutSize()
}
paintSize_ = Size(width, height);
// box layout size = paint size + margin size
if (LessNotEqual(margin_.LeftPx(), 0.0)) {
positionParam_.left = std::make_pair(margin_.Left(), true);
margin_.SetLeft(Dimension(0.0, margin_.Left().Unit()));
}
if (LessNotEqual(margin_.TopPx(), 0.0)) {
positionParam_.top = std::make_pair(margin_.Top(), true);
margin_.SetTop(Dimension(0.0, margin_.Top().Unit()));
}
auto context = context_.Upgrade();
if (context->GetIsDeclarative()) {
if (context && context->GetIsDeclarative()) {
// box layout size = paint size + margin size
if (LessNotEqual(margin_.LeftPx(), 0.0)) {
positionParam_.left = std::make_pair(margin_.Left(), true);
margin_.SetLeft(Dimension(0.0, margin_.Left().Unit()));
}
if (LessNotEqual(margin_.TopPx(), 0.0)) {
positionParam_.top = std::make_pair(margin_.Top(), true);
margin_.SetTop(Dimension(0.0, margin_.Top().Unit()));
}
selfLayoutSize_ = paintSize_ + margin_.GetLayoutSize();
} else {
selfLayoutSize_ = GetLayoutParam().Constrain(paintSize_ + margin_.GetLayoutSize());
@@ -115,10 +115,11 @@ void FlutterRenderChart::Paint(RenderContext& context, const Offset& offset)
return;
}
paintWidth_ = dataRegion.GetSize().Width();
auto piplelineContext = GetContext().Upgrade();
if (piplelineContext && (piplelineContext->GetMinPlatformVersion() >= MIN_SDK_VERSION) && layer_) {
layer_->SetClip(dataRegion.Left(), dataRegion.Right(), dataRegion.Top(), dataRegion.Bottom(),
Flutter::Clip::HARD_EDGE);
auto pipelineContext = GetContext().Upgrade();
if (pipelineContext && pipelineContext->UseLiteStyle() &&
(pipelineContext->GetMinPlatformVersion() >= MIN_SDK_VERSION) && layer_) {
layer_->SetClip(
dataRegion.Left(), dataRegion.Right(), dataRegion.Top(), dataRegion.Bottom(), Flutter::Clip::HARD_EDGE);
}
PaintDatas(context, dataRegion);
}
@@ -536,7 +536,7 @@ void FlutterRenderPercentageDataPanel::Paint(RenderContext& context, const Offse
arcData.endColor = segment.GetEndColor();
arcData.progress = totalValue * animationPercent_;
auto context = context_.Upgrade();
if (context->GetIsDeclarative()) {
if (context && context->GetIsDeclarative()) {
if (useEffect_) {
PaintProgress(canvas, arcData);
}
@@ -564,7 +564,7 @@ HWTEST_F(RenderBoxTest, RenderBoxTest012, TestSize.Level1)
renderRoot->PerformLayout();
ASSERT_FALSE(renderBox->GetLayoutSize() == Size(BOX_WIDTH, BOX_HEIGHT));
const RefPtr<RenderNode>& child = renderBox->GetChildren().front();
ASSERT_TRUE(child->GetPosition() == OFFSET_CENTER);
ASSERT_FALSE(child->GetPosition() == OFFSET_CENTER);
ASSERT_TRUE(child->GetLayoutSize() == Size(ITEM_WIDTH, ITEM_HEIGHT));
}
@@ -1925,7 +1925,7 @@ HWTEST_F(RenderBoxTest, RenderBoxTest045, TestSize.Level1)
renderRoot->PerformLayout();
ASSERT_FALSE(renderBoxBase->GetLayoutSize() == Size(BOX_WIDTH, BOX_HEIGHT));
const RefPtr<RenderNode>& child = renderBoxBase->GetChildren().front();
ASSERT_TRUE(child->GetPosition() == OFFSET_CENTER);
ASSERT_FALSE(child->GetPosition() == OFFSET_CENTER);
ASSERT_TRUE(child->GetLayoutSize() == Size(ITEM_WIDTH, ITEM_HEIGHT));
}