!43132 【收编】1、 rating没有点亮任何一颗星星时,获焦后第一颗星星颜色单独处理,2、用户设置rating宽高后,获焦后背板和焦框不是圆形的问题

Merge pull request !43132 from zhangwenbin00001/rating_0910
This commit is contained in:
openharmony_ci 2024-09-24 03:02:58 +00:00 committed by Gitee
commit 0168213339
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 150 additions and 42 deletions

View File

@ -74,11 +74,12 @@ public:
theme->borderRadius_ = pattern->GetAttr<Dimension>("hover_radius_size", BORDER_RADIUS);
theme->hoverAnimationDuration_ = pattern->GetAttr<double>("hover_animation_duration", 0.0);
theme->pressAnimationDuration_ = pattern->GetAttr<double>("press_animation_duration", 0.0);
theme->iconSubSize_ = pattern->GetAttr<double>("rating_icon_sub_size", 0.0);
theme->iconBoardDistance_ = pattern->GetAttr<double>("rating_icon_board_distance", 0.0);
theme->iconBoardDistance_ = pattern->GetAttr<Dimension>("rating_icon_board_distance", 0.0_vp);
theme->focusColor_ = pattern->GetAttr<Color>("rating_focus_bgcolor", Color());
theme->focusSpace_ = pattern->GetAttr<Dimension>("rating_focus_space", 0.0_vp);
theme->cancelAnimation_ = pattern->GetAttr<double>("rating_focus_blur_cancel_animation", 0.0);
theme->isCircleRadius_ = static_cast<bool>(pattern->GetAttr<double>("rating_apply_circle_radius", 0.0));
theme->unlitStarFocusColor_ = pattern->GetAttr<Color>("rating_unlit_star_focus_color", Color());
} else {
LOGW("find pattern of rating fail");
}
@ -93,14 +94,14 @@ public:
return starNum_;
}
double GetIconBoardDistance() const
const Dimension& GetIconBoardDistance() const
{
return iconBoardDistance_;
}
double GetIconSubSize() const
Color GetUnlitStarFocusColor() const
{
return iconSubSize_;
return unlitStarFocusColor_;
}
const Dimension& GetRatingWidth() const
@ -233,6 +234,11 @@ public:
return pressAnimationDuration_;
}
bool GetIsCircleRadius() const
{
return isCircleRadius_;
}
protected:
RatingTheme() = default;
@ -244,8 +250,7 @@ private:
Dimension ratingMiniHeight_;
Dimension paddingVertical_;
Dimension focusSpace_;
double iconSubSize_ = 0.0;
double iconBoardDistance_ = 0.0;
Dimension iconBoardDistance_;
double stepSize_ = 0.0;
double ratingScore_ = 0.0;
double ratingMiniScore_ = 0.0;
@ -265,9 +270,11 @@ private:
Color starColorActive_;
Color starColorInactive_;
Color focusColor_;
Color unlitStarFocusColor_;
Dimension focusBorderWidth_;
Dimension borderRadius_;
double cancelAnimation_ = 0.0;
bool isCircleRadius_ = false;
};
} // namespace OHOS::Ace

View File

@ -95,6 +95,7 @@ void RatingLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper)
foregroundLoadingCtx_->MakeCanvasImage(singleStarSize, true, ImageFit::FILL);
secondaryLoadingCtx_->MakeCanvasImage(singleStarSize, true, ImageFit::FILL);
backgroundLoadingCtx_->MakeCanvasImage(singleStarSize, true, ImageFit::FILL);
backgroundFocusLoadingCtx_->MakeCanvasImage(singleStarSize, true, ImageFit::FILL);
}
} // namespace OHOS::Ace::NG

View File

@ -29,9 +29,10 @@ class ACE_EXPORT RatingLayoutAlgorithm : public BoxLayoutAlgorithm {
public:
RatingLayoutAlgorithm();
RatingLayoutAlgorithm(const RefPtr<ImageLoadingContext>& foregroundLoadingCtx,
const RefPtr<ImageLoadingContext>& secondaryLoadingCtx, const RefPtr<ImageLoadingContext>& backgroundLoadingCtx)
const RefPtr<ImageLoadingContext>& secondaryLoadingCtx, const RefPtr<ImageLoadingContext>& backgroundLoadingCtx,
const RefPtr<ImageLoadingContext>& backgroundFocusLoadingCtx)
: foregroundLoadingCtx_(foregroundLoadingCtx), secondaryLoadingCtx_(secondaryLoadingCtx),
backgroundLoadingCtx_(backgroundLoadingCtx)
backgroundLoadingCtx_(backgroundLoadingCtx), backgroundFocusLoadingCtx_(backgroundFocusLoadingCtx)
{}
~RatingLayoutAlgorithm() override = default;
@ -41,6 +42,7 @@ public:
foregroundLoadingCtx_ = nullptr;
secondaryLoadingCtx_ = nullptr;
backgroundLoadingCtx_ = nullptr;
backgroundFocusLoadingCtx_ = nullptr;
}
std::optional<SizeF> MeasureContent(
@ -52,6 +54,7 @@ private:
RefPtr<ImageLoadingContext> foregroundLoadingCtx_;
RefPtr<ImageLoadingContext> secondaryLoadingCtx_;
RefPtr<ImageLoadingContext> backgroundLoadingCtx_;
RefPtr<ImageLoadingContext> backgroundFocusLoadingCtx_;
ACE_DISALLOW_COPY_AND_MOVE(RatingLayoutAlgorithm);
};

View File

@ -19,6 +19,7 @@
#include "core/components/rating/rating_theme.h"
#include "core/components_ng/render/drawing_prop_convertor.h"
#include "core/components_ng/render/image_painter.h"
#include "core/components/theme/icon_theme.h"
namespace OHOS::Ace::NG {
RatingModifier::RatingModifier()
@ -72,13 +73,20 @@ void RatingModifier::PaintBoard(DrawingContext& context)
CHECK_NULL_VOID(ratingTheme);
// animate color
LinearColor bgColor = boardColor_->Get();
auto pressBorderRadius = ratingTheme->GetFocusBorderRadius();
auto& canvas = context.canvas;
auto starNum = starNum_->Get();
CHECK_EQUAL_VOID(starNum, 0);
auto singleStarImagePaintConfig = foregroundImageCanvas_->GetPaintConfig();
const float singleStarWidth = contentSize_->Get().Width() / static_cast<float>(starNum);
const float singleStarHeight = contentSize_->Get().Height();
float pressBorderRadius = 0.0f;
if (!ratingTheme->GetIsCircleRadius()) {
pressBorderRadius = ratingTheme->GetFocusBorderRadius().ConvertToPx();
} else {
auto isSquare = singleStarWidth == singleStarHeight;
pressBorderRadius = isSquare ? singleStarHeight / NUMBER_TWO + ratingTheme->GetFocusSpace().ConvertToPx()
: ratingTheme->GetFocusBorderRadius().ConvertToPx();
}
auto offset = contentOffset_->Get();
auto touchStar = touchStar_->Get();
if (touchStar >= 0 && touchStar < starNum) {
@ -86,8 +94,8 @@ void RatingModifier::PaintBoard(DrawingContext& context)
rsBrush.SetAntiAlias(true);
const RSRect rsRect(offset.GetX() + singleStarWidth * static_cast<float>(touchStar), offset.GetY(),
offset.GetX() + singleStarWidth * static_cast<float>((touchStar + 1)), offset.GetY() + singleStarHeight);
const RSRoundRect rsRoundRect(rsRect, static_cast<float>(pressBorderRadius.ConvertToPx()),
static_cast<float>(pressBorderRadius.ConvertToPx()));
const RSRoundRect rsRoundRect(rsRect, static_cast<float>(pressBorderRadius),
static_cast<float>(pressBorderRadius));
canvas.Save();
canvas.ClipRoundRect(rsRoundRect, RSClipOp::INTERSECT);
canvas.DrawBackground(rsBrush);
@ -100,6 +108,7 @@ void RatingModifier::PaintStar(DrawingContext& context)
const ImagePainter foregroundImagePainter(foregroundImageCanvas_);
const ImagePainter secondaryImagePainter(secondaryImageCanvas_);
const ImagePainter backgroundPainter(backgroundImageCanvas_);
const ImagePainter backgroundFocusPainter(backgroundImageFocusCanvas_);
auto& canvas = context.canvas;
auto offset = contentOffset_->Get();
@ -117,10 +126,10 @@ void RatingModifier::PaintStar(DrawingContext& context)
canvas.Save();
auto offsetTemp = offset;
CHECK_NULL_VOID(ratingTheme_);
auto distance = ratingTheme_->GetIconBoardDistance();
auto distance = ratingTheme_->GetIconBoardDistance().ConvertToPx();
offsetTemp.SetX((static_cast<float>(offsetTemp.GetX() + distance)));
offsetTemp.SetY((static_cast<float>(offsetTemp.GetY() + distance)));
auto size = ratingTheme_->GetIconSubSize();
auto size = distance * 2;
auto contentSize = SizeF(singleStarWidth - size, singleStarHeight - size);
// step2.1: calculate the clip area in order to display the secondary image.
@ -142,13 +151,19 @@ void RatingModifier::PaintStar(DrawingContext& context)
// step3.1: calculate the clip area which already occupied by the foreground image.
canvas.ClipRect(clipRect2, RSClipOp::INTERSECT);
offsetTemp.SetX(static_cast<float>(offsetTemp.GetX() - singleStarWidth));
secondaryImagePainter.DrawImage(canvas, offsetTemp, contentSize);
isFocus_ ? backgroundFocusPainter.DrawImage(canvas, offsetTemp, contentSize) :
secondaryImagePainter.DrawImage(canvas, offsetTemp, contentSize);
offsetTemp.SetX(offsetTemp.GetX() + singleStarWidth);
canvas.Restore();
}
// step4: draw background image.
for (int32_t i = 0; i < backgroundImageRepeatNum; i++) {
if (i == 0 && foregroundImageRepeatNum == 0 && isFocus_) {
backgroundFocusPainter.DrawImage(canvas, offsetTemp, contentSize);
offsetTemp.SetX(static_cast<float>(offsetTemp.GetX() + singleStarWidth));
continue;
}
backgroundPainter.DrawImage(canvas, offsetTemp, contentSize);
if (i < backgroundImageRepeatNum - 1) {
offsetTemp.SetX(offsetTemp.GetX() + singleStarWidth);

View File

@ -50,16 +50,19 @@ public:
void UpdateCanvasImage(const RefPtr<CanvasImage>& foregroundImageCanvas,
const RefPtr<CanvasImage>& secondaryImageCanvas, const RefPtr<CanvasImage>& backgroundImageCanvas,
const RefPtr<CanvasImage>& backgroundImageFocusCanvas,
const ImagePaintConfig& foregroundConfig, const ImagePaintConfig& secondaryConfig,
const ImagePaintConfig& backgroundConfig)
const ImagePaintConfig& backgroundConfig, const ImagePaintConfig& backgroundFocusConfig)
{
SetNeedDraw(true);
foregroundImageCanvas_ = foregroundImageCanvas;
secondaryImageCanvas_ = secondaryImageCanvas;
backgroundImageCanvas_ = backgroundImageCanvas;
backgroundImageFocusCanvas_ = backgroundImageFocusCanvas;
foregroundImageCanvas_->SetPaintConfig(foregroundConfig);
secondaryImageCanvas_->SetPaintConfig(secondaryConfig);
backgroundImageCanvas_->SetPaintConfig(backgroundConfig);
backgroundImageFocusCanvas_->SetPaintConfig(backgroundFocusConfig);
}
void UpdateImageSourceInfo(
@ -132,6 +135,11 @@ public:
}
}
RefPtr<PropertySizeF> GetContentSize()
{
return contentSize_;
}
void SetDrawScore(double drawScore)
{
if (drawScore_) {
@ -226,6 +234,7 @@ private:
RefPtr<CanvasImage> foregroundImageCanvas_;
RefPtr<CanvasImage> secondaryImageCanvas_;
RefPtr<CanvasImage> backgroundImageCanvas_;
RefPtr<CanvasImage> backgroundImageFocusCanvas_;
ImageSourceInfo foreground_;
ImageSourceInfo secondary_;
ImageSourceInfo background_;
@ -242,6 +251,7 @@ private:
RefPtr<AnimatablePropertyColor> boardColor_;
RefPtr<PropertyBool> reverse_;
RefPtr<RatingTheme> ratingTheme_;
static constexpr int32_t NUMBER_TWO = 2;
ACE_DISALLOW_COPY_AND_MOVE(RatingModifier);
};
} // namespace OHOS::Ace::NG

View File

@ -34,8 +34,9 @@
#include "core/pipeline_ng/pipeline_context.h"
namespace OHOS::Ace::NG {
constexpr int32_t RATING_IMAGE_SUCCESS_CODE = 0b111;
constexpr int32_t RATING_IMAGE_SUCCESS_CODE = 0b1111;
constexpr int32_t DEFAULT_RATING_TOUCH_STAR_NUMBER = 0;
constexpr int32_t NUMBER_TWO = 2;
void RatingPattern::OnAttachToFrameNode()
{
@ -143,6 +144,12 @@ void RatingPattern::OnImageLoadSuccess(int32_t imageFlag)
backgroundConfig_.dstRect_ = backgroundImageLoadingCtx_->GetDstRect();
imageSuccessStateCode_ |= static_cast<uint32_t>(imageFlag);
}
if (imageFlag == 0b1000) {
backgroundImageFocusCanvas_ = backgroundImageFocusLoadingCtx_->MoveCanvasImage();
backgroundFocusConfig_.srcRect_ = backgroundImageFocusLoadingCtx_->GetSrcRect();
backgroundFocusConfig_.dstRect_ = backgroundImageFocusLoadingCtx_->GetDstRect();
imageSuccessStateCode_ |= static_cast<uint32_t>(imageFlag);
}
// only when foreground, secondary and background image are all loaded successfully, mark dirty to update rendering.
if (imageSuccessStateCode_ == RATING_IMAGE_SUCCESS_CODE) {
MarkDirtyNode(PROPERTY_UPDATE_RENDER);
@ -174,12 +181,15 @@ void RatingPattern::UpdatePaintConfig()
foregroundConfig_.imageFit_ = ImageFit::FILL;
secondaryConfig_.imageFit_ = ImageFit::FILL;
backgroundConfig_.imageFit_ = ImageFit::FILL;
backgroundFocusConfig_.imageFit_ = ImageFit::FILL;
foregroundConfig_.scaleX_ = contentSize.Width() / frameSize.Width() / static_cast<float>(starsNum);
foregroundConfig_.scaleY_ = contentSize.Height() / frameSize.Height();
secondaryConfig_.scaleX_ = contentSize.Width() / frameSize.Width() / static_cast<float>(starsNum);
secondaryConfig_.scaleY_ = contentSize.Height() / frameSize.Height();
backgroundConfig_.scaleX_ = contentSize.Width() / frameSize.Width() / static_cast<float>(starsNum);
backgroundConfig_.scaleY_ = contentSize.Height() / frameSize.Height();
backgroundFocusConfig_.scaleX_ = contentSize.Width() / frameSize.Width() / static_cast<float>(starsNum);
backgroundFocusConfig_.scaleY_ = contentSize.Height() / frameSize.Height();
}
RefPtr<NodePaintMethod> RatingPattern::CreateNodePaintMethod()
@ -195,13 +205,16 @@ RefPtr<NodePaintMethod> RatingPattern::CreateNodePaintMethod()
CHECK_NULL_RETURN(foregroundImageCanvas_, defaultPaintMethod);
CHECK_NULL_RETURN(secondaryImageCanvas_, defaultPaintMethod);
CHECK_NULL_RETURN(backgroundImageCanvas_, defaultPaintMethod);
CHECK_NULL_RETURN(backgroundImageFocusCanvas_, defaultPaintMethod);
CHECK_NULL_RETURN(foregroundImageLoadingCtx_, defaultPaintMethod);
CHECK_NULL_RETURN(secondaryImageLoadingCtx_, defaultPaintMethod);
CHECK_NULL_RETURN(backgroundImageLoadingCtx_, defaultPaintMethod);
CHECK_NULL_RETURN(backgroundImageFocusLoadingCtx_, defaultPaintMethod);
UpdatePaintConfig();
PrepareAnimation(foregroundImageCanvas_);
PrepareAnimation(secondaryImageCanvas_);
PrepareAnimation(backgroundImageCanvas_);
PrepareAnimation(backgroundImageFocusCanvas_);
// when frameNode mark dirty to update rendering, only when 3 images are all loaded successfully and
// JudgeImageSourceInfo is true, pattern will update ratingModifier's CanvasImage.
if (ratingModifier_->JudgeImageSourceInfo(foregroundImageLoadingCtx_->GetSourceInfo(),
@ -211,7 +224,8 @@ RefPtr<NodePaintMethod> RatingPattern::CreateNodePaintMethod()
ratingModifier_->UpdateImageSourceInfo(foregroundImageLoadingCtx_->GetSourceInfo(),
secondaryImageLoadingCtx_->GetSourceInfo(), backgroundImageLoadingCtx_->GetSourceInfo());
ratingModifier_->UpdateCanvasImage(foregroundImageCanvas_, secondaryImageCanvas_, backgroundImageCanvas_,
foregroundConfig_, secondaryConfig_, backgroundConfig_);
backgroundImageFocusCanvas_, foregroundConfig_, secondaryConfig_,
backgroundConfig_, backgroundFocusConfig_);
}
if (!(foregroundImageCanvas_->IsStatic() && secondaryImageCanvas_->IsStatic() &&
backgroundImageCanvas_->IsStatic())) {
@ -524,30 +538,45 @@ void RatingPattern::GetInnerFocusPaintRect(RoundRect& paintRect)
auto ratingRenderProperty = GetPaintProperty<RatingRenderProperty>();
CHECK_NULL_VOID(ratingRenderProperty);
ratingRenderProperty->UpdateTouchStar(wholeStarNum);
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto ratingTheme = pipeline->GetTheme<RatingTheme>();
CHECK_NULL_VOID(ratingTheme);
auto radius = ratingTheme->GetFocusBorderRadius();
float focusSpace = 0.0f;
float radius = GetFocusRectRadius(property, focusSpace);
auto focusButtonRect = RectF(static_cast<float>(wholeStarNum) * singleStarWidth_ + offsetLeft, offsetTop,
singleStarWidth_, singleStarHeight);
auto focusSpace = ratingTheme->GetFocusSpace().ConvertToPx();
focusButtonRect -= OffsetF(focusSpace, focusSpace);
focusButtonRect += SizeF(focusSpace + focusSpace, focusSpace + focusSpace);
PaintFocusRect(paintRect, focusButtonRect, radius);
paintRect.SetRect(focusButtonRect);
paintRect.SetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS, static_cast<RSScalar>(radius),
static_cast<RSScalar>(radius));
paintRect.SetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS, static_cast<RSScalar>(radius),
static_cast<RSScalar>(radius));
paintRect.SetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS, static_cast<RSScalar>(radius),
static_cast<RSScalar>(radius));
paintRect.SetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS, static_cast<RSScalar>(radius),
static_cast<RSScalar>(radius));
}
void RatingPattern::PaintFocusRect(RoundRect& paintRect, RectF& focusButtonRect, Dimension& radius)
float RatingPattern::GetFocusRectRadius(const RefPtr<RatingLayoutProperty>& property, float& focusSpace)
{
paintRect.SetRect(focusButtonRect);
paintRect.SetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS, static_cast<RSScalar>(radius.ConvertToPx()),
static_cast<RSScalar>(radius.ConvertToPx()));
paintRect.SetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS, static_cast<RSScalar>(radius.ConvertToPx()),
static_cast<RSScalar>(radius.ConvertToPx()));
paintRect.SetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS, static_cast<RSScalar>(radius.ConvertToPx()),
static_cast<RSScalar>(radius.ConvertToPx()));
paintRect.SetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS, static_cast<RSScalar>(radius.ConvertToPx()),
static_cast<RSScalar>(radius.ConvertToPx()));
CHECK_NULL_RETURN(ratingModifier_, 0.0);
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_RETURN(pipeline, 0.0);
auto ratingTheme = pipeline->GetTheme<RatingTheme>();
CHECK_NULL_RETURN(ratingTheme, 0.0);
focusSpace = ratingTheme->GetFocusSpace().ConvertToPx();
float radius = 0.0f;
if (!ratingTheme->GetIsCircleRadius()) {
radius = ratingTheme->GetFocusBorderRadius().ConvertToPx();
} else {
double starNum = property->GetStarsValue(themeStarNum_);
if (starNum != 0) {
auto contentSize = ratingModifier_->GetContentSize();
CHECK_NULL_RETURN(contentSize, 0.0);
auto isSquare = contentSize->Get().Width() / starNum == contentSize->Get().Height();
radius = isSquare ? contentSize->Get().Height() / NUMBER_TWO + ratingTheme->GetFocusSpace().ConvertToPx()
: ratingTheme->GetFocusBorderRadius().ConvertToPx();
}
}
return radius;
}
void RatingPattern::PaintFocusState(double ratingScore)
@ -644,6 +673,7 @@ void RatingPattern::SetModifierFocus(bool isFocus)
ratingModifier_->SetFocusOrBlurColor(isfocus_ ? ratingTheme->GetFocusColor() : Color::TRANSPARENT);
}
ratingModifier_->SetIsFocus(isFocus);
ratingModifier_->SetNeedDraw(true);
MarkDirtyNode(PROPERTY_UPDATE_RENDER);
}
@ -859,6 +889,34 @@ void RatingPattern::LoadBackground(const RefPtr<RatingLayoutProperty>& layoutPro
}
}
void RatingPattern::LoadFocusBackground(const RefPtr<RatingLayoutProperty>& layoutProperty,
const RefPtr<RatingTheme>& ratingTheme, const RefPtr<IconTheme>& iconTheme)
{
backgroundFocusConfig_.isSvg_ = false;
ImageSourceInfo sourceInfo;
if (!layoutProperty->HasBackgroundImageSourceInfo()) {
isBackgroundImageInfoFromTheme_ = true;
sourceInfo.SetResourceId(ratingTheme->GetBackgroundResourceId());
layoutProperty->UpdateBackgroundImageSourceInfo(sourceInfo);
} else {
sourceInfo = layoutProperty->GetBackgroundImageSourceInfo().value();
}
auto iconPath = iconTheme->GetIconPath(sourceInfo.GetResourceId());
if (!iconPath.empty()) {
sourceInfo.SetSrc(iconPath, ratingTheme->GetUnlitStarFocusColor());
}
if (sourceInfo.IsSvg()) {
backgroundFocusConfig_.isSvg_ = true;
}
if (!backgroundImageFocusLoadingCtx_ || backgroundImageFocusLoadingCtx_->GetSourceInfo() != sourceInfo) {
LoadNotifier loadNotifierBackgroundImage(
CreateDataReadyCallback(0b1000), CreateLoadSuccessCallback(0b1000), CreateLoadFailCallback(0b1000));
backgroundImageFocusLoadingCtx_ =
AceType::MakeRefPtr<ImageLoadingContext>(sourceInfo, std::move(loadNotifierBackgroundImage));
backgroundImageFocusLoadingCtx_->LoadImageData();
}
}
void RatingPattern::OnModifyDone()
{
Pattern::OnModifyDone();
@ -882,6 +940,7 @@ void RatingPattern::OnModifyDone()
LoadForeground(layoutProperty, ratingTheme, iconTheme);
LoadSecondary(layoutProperty, ratingTheme, iconTheme);
LoadBackground(layoutProperty, ratingTheme, iconTheme);
LoadFocusBackground(layoutProperty, ratingTheme, iconTheme);
auto hub = host->GetEventHub<EventHub>();
CHECK_NULL_VOID(hub);
auto gestureHub = hub->GetOrCreateGestureEventHub();

View File

@ -52,8 +52,8 @@ public:
RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
{
return MakeRefPtr<RatingLayoutAlgorithm>(
foregroundImageLoadingCtx_, secondaryImageLoadingCtx_, backgroundImageLoadingCtx_);
return MakeRefPtr<RatingLayoutAlgorithm>(foregroundImageLoadingCtx_,
secondaryImageLoadingCtx_, backgroundImageLoadingCtx_, backgroundImageFocusLoadingCtx_);
}
RefPtr<PaintProperty> CreatePaintProperty() override
@ -116,6 +116,8 @@ private:
const RefPtr<IconTheme>& iconTheme);
void LoadBackground(const RefPtr<RatingLayoutProperty>& layoutProperty, const RefPtr<RatingTheme>& ratingTheme,
const RefPtr<IconTheme>& iconTheme);
void LoadFocusBackground(const RefPtr<RatingLayoutProperty>& layoutProperty, const RefPtr<RatingTheme>& ratingTheme,
const RefPtr<IconTheme>& iconTheme);
void UpdatePaintConfig();
void PrepareAnimation(const RefPtr<CanvasImage>& image);
void SetRedrawCallback(const RefPtr<CanvasImage>& image);
@ -123,7 +125,7 @@ private:
void OnImageLoadSuccess(int32_t imageFlag);
void CheckImageInfoHasChangedOrNot(
int32_t imageFlag, const ImageSourceInfo& sourceInfo, const std::string& lifeCycleTag);
void PaintFocusRect(RoundRect& paintRect, RectF& focusButtonRect, Dimension& radius);
float GetFocusRectRadius(const RefPtr<RatingLayoutProperty>& property, float& focusSpace);
// Init pan recognizer to update render when drag updates, fire change event when drag ends.
void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub);
@ -178,14 +180,17 @@ private:
RefPtr<ImageLoadingContext> foregroundImageLoadingCtx_;
RefPtr<ImageLoadingContext> secondaryImageLoadingCtx_;
RefPtr<ImageLoadingContext> backgroundImageLoadingCtx_;
RefPtr<ImageLoadingContext> backgroundImageFocusLoadingCtx_;
RefPtr<RatingModifier> ratingModifier_;
RefPtr<CanvasImage> foregroundImageCanvas_;
RefPtr<CanvasImage> secondaryImageCanvas_;
RefPtr<CanvasImage> backgroundImageCanvas_;
RefPtr<CanvasImage> backgroundImageFocusCanvas_;
ImagePaintConfig foregroundConfig_;
ImagePaintConfig secondaryConfig_;
ImagePaintConfig backgroundConfig_;
ImagePaintConfig backgroundFocusConfig_;
uint32_t imageReadyStateCode_ = 0;
uint32_t imageSuccessStateCode_ = 0;
bool hasInit_ = false;

View File

@ -92,6 +92,7 @@ const std::string IMAGE_SOURCE_INFO_STRING = "empty source";
const int32_t RATING_FOREGROUND_FLAG = 0b001;
const int32_t RATING_SECONDARY_FLAG = 0b010;
const int32_t RATING_BACKGROUND_FLAG = 0b100;
const int32_t RATING_BACKGROUNDFOCUS_FLAG = 0b1000;
const int32_t INVALID_IMAGE_FLAG = 0b111;
const std::string RATING_IMAGE_LOAD_FAILED = "ImageDataFailed";
const std::string RATING_IMAGE_LOAD_SUCCESS = "ImageDataSuccess";
@ -583,15 +584,18 @@ HWTEST_F(RatingTestNg, RatingPatternTest011, TestSize.Level1)
ratingPattern->LoadForeground(ratingLayoutProperty, ratingTheme, iconTheme);
ratingPattern->LoadSecondary(ratingLayoutProperty, ratingTheme, iconTheme);
ratingPattern->LoadBackground(ratingLayoutProperty, ratingTheme, iconTheme);
ratingPattern->LoadFocusBackground(ratingLayoutProperty, ratingTheme, iconTheme);
ASSERT_NE(ratingPattern->foregroundImageLoadingCtx_, nullptr);
ASSERT_NE(ratingPattern->secondaryImageLoadingCtx_, nullptr);
ASSERT_NE(ratingPattern->backgroundImageLoadingCtx_, nullptr);
ASSERT_NE(ratingPattern->backgroundImageFocusLoadingCtx_, nullptr);
EXPECT_TRUE(ratingPattern->secondaryConfig_.isSvg_);
EXPECT_FALSE(ratingPattern->backgroundConfig_.isSvg_);
EXPECT_TRUE(ratingPattern->foregroundConfig_.isSvg_);
ratingPattern->foregroundImageLoadingCtx_->SuccessCallback(nullptr);
ratingPattern->secondaryImageLoadingCtx_->SuccessCallback(nullptr);
ratingPattern->backgroundImageLoadingCtx_->SuccessCallback(nullptr);
ratingPattern->backgroundImageFocusLoadingCtx_->SuccessCallback(nullptr);
/**
* @tc.steps: step4. 3 ImageLoadContexts callback successfuly, and imageSuccessStateCode_ ==
* RATING_IMAGE_SUCCESS_CODE.
@ -616,14 +620,16 @@ HWTEST_F(RatingTestNg, RatingPatternTest011, TestSize.Level1)
ratingPattern->LoadBackground(ratingLayoutProperty, ratingTheme, iconTheme);
ratingPattern->LoadForeground(ratingLayoutProperty, ratingTheme, iconTheme);
ratingPattern->LoadSecondary(ratingLayoutProperty, ratingTheme, iconTheme);
ratingPattern->LoadFocusBackground(ratingLayoutProperty, ratingTheme, iconTheme);
EXPECT_FALSE(ratingPattern->secondaryConfig_.isSvg_);
EXPECT_TRUE(ratingPattern->backgroundConfig_.isSvg_);
EXPECT_TRUE(ratingPattern->foregroundConfig_.isSvg_);
EXPECT_EQ(ratingPattern->imageSuccessStateCode_, 7);
EXPECT_EQ(ratingPattern->imageSuccessStateCode_, 15);
ratingPattern->foregroundImageLoadingCtx_->SuccessCallback(nullptr);
ratingPattern->secondaryImageLoadingCtx_->SuccessCallback(nullptr);
ratingPattern->backgroundImageLoadingCtx_->SuccessCallback(nullptr);
EXPECT_EQ(ratingPattern->imageSuccessStateCode_, 0b111);
ratingPattern->backgroundImageFocusLoadingCtx_->SuccessCallback(nullptr);
EXPECT_EQ(ratingPattern->imageSuccessStateCode_, 0b1111);
auto paintMethod3 = ratingPattern->CreateNodePaintMethod();
ASSERT_NE(paintMethod3, nullptr);
EXPECT_EQ(ratingPattern->ratingModifier_->foreground_.GetSrc(), RATING_SVG_URL);
@ -652,6 +658,7 @@ HWTEST_F(RatingTestNg, RatingPatternTest012, TestSize.Level1)
ratingPattern->foregroundImageCanvas_ = AceType::MakeRefPtr<MockCanvasImage>();
ratingPattern->secondaryImageCanvas_ = AceType::MakeRefPtr<MockCanvasImage>();
ratingPattern->backgroundImageCanvas_ = AceType::MakeRefPtr<MockCanvasImage>();
ratingPattern->backgroundImageFocusCanvas_ = AceType::MakeRefPtr<MockCanvasImage>();
auto paintMethod1 = ratingPattern->CreateNodePaintMethod();
ASSERT_NE(paintMethod1, nullptr);
ASSERT_NE(ratingPattern->ratingModifier_, nullptr);
@ -660,7 +667,7 @@ HWTEST_F(RatingTestNg, RatingPatternTest012, TestSize.Level1)
*/
frameNode->geometryNode_->SetFrameSize(SizeF(FRAME_WIDTH, FRAME_HEIGHT));
frameNode->geometryNode_->SetContentSize(CONTAINER_SIZE);
ratingPattern->imageSuccessStateCode_ = RATING_IMAGE_SUCCESS_CODE;
ratingPattern->imageSuccessStateCode_ = 0b1111;
auto paintMethod2 = ratingPattern->CreateNodePaintMethod();
ASSERT_NE(paintMethod2, nullptr);
ASSERT_NE(ratingPattern->ratingModifier_, nullptr);
@ -753,7 +760,7 @@ HWTEST_F(RatingTestNg, RatingMeasureTest013, TestSize.Level1)
ratingLayoutProperty->UpdateStars(DEFAULT_STAR_NUM);
ASSERT_NE(ratingLayoutProperty, nullptr);
LayoutWrapperNode layoutWrapper = LayoutWrapperNode(frameNode, nullptr, ratingLayoutProperty);
auto ratingLayoutAlgorithm = AceType::MakeRefPtr<RatingLayoutAlgorithm>(nullptr, nullptr, nullptr);
auto ratingLayoutAlgorithm = AceType::MakeRefPtr<RatingLayoutAlgorithm>(nullptr, nullptr, nullptr, nullptr);
ASSERT_NE(ratingLayoutAlgorithm, nullptr);
LayoutConstraintF layoutConstraint;
auto contentNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
@ -876,6 +883,7 @@ HWTEST_F(RatingTestNg, RatingPaintPropertyTest001, TestSize.Level1)
ratingPattern->OnImageLoadSuccess(RATING_FOREGROUND_FLAG);
ratingPattern->OnImageLoadSuccess(RATING_SECONDARY_FLAG);
ratingPattern->OnImageLoadSuccess(RATING_BACKGROUND_FLAG);
ratingPattern->OnImageLoadSuccess(RATING_BACKGROUNDFOCUS_FLAG);
EXPECT_NE(ratingPattern->foregroundImageCanvas_, nullptr);
EXPECT_NE(ratingPattern->secondaryImageCanvas_, nullptr);
EXPECT_NE(ratingPattern->backgroundImageCanvas_, nullptr);