diff --git a/frameworks/core/components/rating/rating_element.h b/frameworks/core/components/rating/rating_element.h index ed6a8a1a..db64b6ce 100644 --- a/frameworks/core/components/rating/rating_element.h +++ b/frameworks/core/components/rating/rating_element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -54,7 +54,7 @@ public: bool OnKeyEvent(const KeyEvent& keyEvent) override { - if (keyEvent.action != KeyAction::UP) { + if (keyEvent.action != KeyAction::DOWN) { return false; } const auto& renderRating = AceType::DynamicCast(renderNode_); diff --git a/frameworks/core/components/rating/render_rating.h b/frameworks/core/components/rating/render_rating.h index b6d40170..8a9acc39 100644 --- a/frameworks/core/components/rating/render_rating.h +++ b/frameworks/core/components/rating/render_rating.h @@ -38,6 +38,10 @@ constexpr Dimension PRESS_BORDER_RADIUS = 4.0_vp; constexpr uint32_t PRESS_COLOR = 0x19000000; +constexpr Dimension FOCUS_BODER_PADING = 2.0_vp; + +constexpr uint32_t FOCUS_BODER_COLOR = 0xFF0A59F7; + enum class OperationEvent { RATING_TOUCH_EVENT = 0, RATING_KEY_EVENT, diff --git a/frameworks/core/components/rating/rosen_render_rating.cpp b/frameworks/core/components/rating/rosen_render_rating.cpp index 55d0ba72..a7ae83b4 100644 --- a/frameworks/core/components/rating/rosen_render_rating.cpp +++ b/frameworks/core/components/rating/rosen_render_rating.cpp @@ -44,6 +44,16 @@ void RosenRenderRating::Paint(RenderContext& context, const Offset& offset) double focusRadius = singleWidth_ - imageVerticalOffset * 2; RequestFocusAnimation(animationOffset + GetGlobalOffset(), Size(focusRadius, focusRadius), focusRadius); } + + if ((SystemProperties::GetDeviceType() == DeviceType::TABLET || SystemProperties::GetDeviceType() == + DeviceType::PHONE) && !isIndicator_ && operationEvent_ == OperationEvent::RATING_KEY_EVENT) { + Offset animationOffset = starOffset + Offset(offsetDeltaX, offsetDeltaY); + PaintFocusForTABLET(animationOffset, focusBorderRadius_.Value(), + Size(singleWidth_, ratingSize_.Height()), context); + double focusRadius = singleWidth_; + RequestFocusAnimation(animationOffset + GetGlobalOffset(), Size(focusRadius, focusRadius), focusRadius); + } + if ((IsPhone() || IsTablet()) && !isIndicator_) { PaintHoverRect(canvas); } @@ -159,6 +169,24 @@ void RosenRenderRating::PaintFocus( canvas->drawRRect(rRect, paint); } +void RosenRenderRating::PaintFocusForTABLET( + const Offset& offset, double rRectRadius, const Size& boardSize, RenderContext& context) +{ + auto canvas = static_cast(&context)->GetCanvas(); + if (!canvas) { + LOGE("Paint canvas is null"); + return; + } + SkPaint paint; + SkRRect rRect; + paint.setColor(FOCUS_BODER_COLOR); + paint.setStyle(SkPaint::Style::kStroke_Style); + paint.setStrokeWidth(NormalizeToPx(FOCUS_BODER_PADING)); + rRect.setRectXY(SkRect::MakeWH(boardSize.Width(), boardSize.Height()), rRectRadius, rRectRadius); + rRect.offset(offset.GetX(), offset.GetY()); + canvas->drawRRect(rRect, paint); +} + void RosenRenderRating::PaintPress( const Offset& offset, double rRectRadius, const Size& boardSize, RenderContext& context) { diff --git a/frameworks/core/components/rating/rosen_render_rating.h b/frameworks/core/components/rating/rosen_render_rating.h index d2d00e79..fd05cd89 100644 --- a/frameworks/core/components/rating/rosen_render_rating.h +++ b/frameworks/core/components/rating/rosen_render_rating.h @@ -30,6 +30,7 @@ public: void Paint(RenderContext& context, const Offset& offset) override; void PaintFocus(const Offset& offset, double rrectRadius, const Size& boardSize, RenderContext& context) override; + void PaintFocusForTABLET(const Offset& offset, double rrectRadius, const Size& boardSize, RenderContext& context); void PaintPress( const Offset& offset, double rrectRadius, const Size& boardSize, RenderContext& context); void PaintRatingBar(RenderContext& context, SkCanvas* canvas);