mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-30 18:52:04 +00:00
修复了GridItem重复设置disabled透明度变化的bug
Signed-off-by: tomkl123 <wangyansong11@huawei.com> Change-Id: I23441e169fec5b4ff04d8236930a778de8e3e6e1
This commit is contained in:
parent
2612bee6ae
commit
908d8cbbd0
@ -232,18 +232,11 @@ void GridItemPattern::InitDisableStyle()
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
auto theme = pipeline->GetTheme<GridItemTheme>();
|
||||
CHECK_NULL_VOID(theme);
|
||||
auto userDefineOpacity = renderContext->GetOpacityValue(1.0);
|
||||
|
||||
float opacity = 1.0f;
|
||||
if (!eventHub->IsDeveloperEnabled()) {
|
||||
enableOpacity_ = renderContext->GetOpacityValue(1.0);
|
||||
lastOpacity_ = enableOpacity_.value() * theme->GetGridItemDisabledAlpha();
|
||||
} else if (enableOpacity_.has_value() && userDefineOpacity == lastOpacity_) {
|
||||
lastOpacity_ = enableOpacity_.value();
|
||||
enableOpacity_.reset();
|
||||
} else {
|
||||
lastOpacity_ = userDefineOpacity;
|
||||
opacity = theme->GetGridItemDisabledAlpha();
|
||||
}
|
||||
renderContext->UpdateOpacity(lastOpacity_);
|
||||
renderContext->SetOpacityMultiplier(opacity);
|
||||
}
|
||||
|
||||
void GridItemPattern::InitFocusPaintRect(const RefPtr<FocusHub>& focusHub)
|
||||
@ -310,9 +303,6 @@ void GridItemPattern::DumpAdvanceInfo()
|
||||
property->GetColumnEnd().has_value()
|
||||
? DumpLog::GetInstance().AddDesc("ColumnEnd:" + std::to_string(property->GetColumnEnd().value()))
|
||||
: DumpLog::GetInstance().AddDesc("ColumnEnd:null");
|
||||
enableOpacity_.has_value()
|
||||
? DumpLog::GetInstance().AddDesc("enableOpacity:" + std::to_string(enableOpacity_.value()))
|
||||
: DumpLog::GetInstance().AddDesc("enableOpacity:null");
|
||||
selectable_ ? DumpLog::GetInstance().AddDesc("selectable:true")
|
||||
: DumpLog::GetInstance().AddDesc("selectable:false");
|
||||
isSelected_ ? DumpLog::GetInstance().AddDesc("isSelected:true")
|
||||
|
@ -163,8 +163,6 @@ private:
|
||||
bool isHover_ = false;
|
||||
bool isPressed_ = false;
|
||||
GridItemStyle gridItemStyle_ = GridItemStyle::NONE;
|
||||
std::optional<double> enableOpacity_;
|
||||
double lastOpacity_ = 0.0;
|
||||
std::optional<GridItemIndexInfo> irregularItemInfo_;
|
||||
|
||||
ACE_DISALLOW_COPY_AND_MOVE(GridItemPattern);
|
||||
|
@ -6012,6 +6012,12 @@ void RosenRenderContext::SetOpacity(float opacity)
|
||||
rsNode_->SetAlpha(opacity);
|
||||
}
|
||||
|
||||
void RosenRenderContext::SetOpacityMultiplier(float opacity)
|
||||
{
|
||||
CHECK_NULL_VOID(rsNode_);
|
||||
SetAnimatableProperty<Rosen::RSAlphaModifier, float>(alphaModifier_, opacity);
|
||||
}
|
||||
|
||||
void RosenRenderContext::SetTranslate(float translateX, float translateY, float translateZ)
|
||||
{
|
||||
CHECK_NULL_VOID(rsNode_);
|
||||
|
@ -392,6 +392,7 @@ public:
|
||||
void UpdatePaintRect(const RectF& paintRect) override;
|
||||
Matrix4 GetRevertMatrix() override;
|
||||
void SuggestOpIncNode(bool isOpincNode, bool isNeedCalculate) override;
|
||||
void SetOpacityMultiplier(float opacity) override;
|
||||
|
||||
private:
|
||||
void OnBackgroundImageUpdate(const ImageSourceInfo& src) override;
|
||||
@ -665,6 +666,7 @@ private:
|
||||
std::shared_ptr<Rosen::RSScaleModifier> scaleXYUserModifier_;
|
||||
std::shared_ptr<Rosen::RectF> drawRegionRects_[DRAW_REGION_RECT_COUNT] = { nullptr };
|
||||
RefPtr<FocusAnimationModifier> focusAnimationModifier_;
|
||||
std::shared_ptr<Rosen::RSAlphaModifier> alphaModifier_;
|
||||
|
||||
// translate modifiers for interruption
|
||||
std::shared_ptr<Rosen::RSTranslateModifier> translateXY_;
|
||||
|
@ -699,6 +699,9 @@ public:
|
||||
|
||||
virtual void SuggestOpIncNode(bool isOpincNode, bool isNeedCalculate) {}
|
||||
|
||||
// The additional opacity will be multiplied with the base opacity.
|
||||
virtual void SetOpacityMultiplier(float opacity) {}
|
||||
|
||||
protected:
|
||||
RenderContext() = default;
|
||||
std::shared_ptr<SharedTransitionOption> sharedTransitionOption_;
|
||||
|
@ -100,11 +100,17 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SetOpacityMultiplier(float opacity)
|
||||
{
|
||||
opacityMultiplier_ = opacity;
|
||||
}
|
||||
|
||||
bool isVisible_ = true;
|
||||
RectF rect_;
|
||||
RectF paintRect_;
|
||||
Color blendColor_ = Color::TRANSPARENT;
|
||||
std::vector<double> transInfo_ = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
float opacityMultiplier_ = 1.0f;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_CONTEXT_H
|
||||
|
@ -413,12 +413,16 @@ HWTEST_F(GridLayoutTestNg, GridItemDisableEventTest001, TestSize.Level1)
|
||||
*/
|
||||
auto gridItemPattern = GetChildPattern<GridItemPattern>(frameNode_, 0);
|
||||
auto gridItemEventHub = GetChildEventHub<GridItemEventHub>(frameNode_, 0);
|
||||
EXPECT_FALSE(gridItemPattern->enableOpacity_.has_value());
|
||||
auto gridItemFrameNode = GetChildFrameNode(frameNode_, 0);
|
||||
auto renderContext = gridItemFrameNode->renderContext_;
|
||||
auto mockRenderContext = AceType::DynamicCast<MockRenderContext>(renderContext);
|
||||
EXPECT_EQ(mockRenderContext->opacityMultiplier_, 1.0f);
|
||||
gridItemEventHub->SetEnabled(false);
|
||||
gridItemPattern->InitDisableStyle();
|
||||
EXPECT_EQ(mockRenderContext->opacityMultiplier_, 0.4f);
|
||||
gridItemEventHub->SetEnabled(true);
|
||||
gridItemPattern->InitDisableStyle();
|
||||
EXPECT_FALSE(gridItemPattern->enableOpacity_.has_value());
|
||||
EXPECT_EQ(mockRenderContext->opacityMultiplier_, 1.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1670,4 +1674,32 @@ HWTEST_F(GridLayoutTestNg, LayoutWithAutoStretch003, TestSize.Level1)
|
||||
EXPECT_TRUE(IsEqual(childRect, expectRect)) << "index: " << index;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GridItemDisableEventTest002
|
||||
* @tc.desc: GirdItem disable event test.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(GridLayoutTestNg, GridItemDisableEventTest002, TestSize.Level1)
|
||||
{
|
||||
GridModelNG model = CreateGrid();
|
||||
CreateFixedItems(10, GridItemStyle::PLAIN);
|
||||
CreateDone(frameNode_);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Get girdItem frameNode and pattern, set callback function.
|
||||
* @tc.expected: Related function is called.
|
||||
*/
|
||||
auto gridItemPattern = GetChildPattern<GridItemPattern>(frameNode_, 0);
|
||||
auto gridItemEventHub = GetChildEventHub<GridItemEventHub>(frameNode_, 0);
|
||||
auto gridItemFrameNode = GetChildFrameNode(frameNode_, 0);
|
||||
auto renderContext = gridItemFrameNode->renderContext_;
|
||||
auto mockRenderContext = AceType::DynamicCast<MockRenderContext>(renderContext);
|
||||
EXPECT_EQ(mockRenderContext->opacityMultiplier_, 1.0f);
|
||||
gridItemEventHub->SetEnabled(false);
|
||||
gridItemPattern->InitDisableStyle();
|
||||
EXPECT_EQ(mockRenderContext->opacityMultiplier_, 0.4f);
|
||||
gridItemPattern->InitDisableStyle();
|
||||
EXPECT_EQ(mockRenderContext->opacityMultiplier_, 0.4f);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
Loading…
Reference in New Issue
Block a user