mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 17:21:11 +00:00
!37636 bindSheet适配symbol
Merge pull request !37636 from duanfuqiao/master
This commit is contained in:
commit
e702d53105
@ -1080,12 +1080,20 @@ void SheetPresentationPattern::OnColorConfigurationUpdate()
|
||||
CHECK_NULL_VOID(renderContext);
|
||||
renderContext->UpdateBackgroundColor(sheetTheme->GetCloseIconColor());
|
||||
sheetCloseIcon->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
|
||||
auto imageNode = DynamicCast<FrameNode>(sheetCloseIcon->GetChildAtIndex(0));
|
||||
CHECK_NULL_VOID(imageNode);
|
||||
auto imagePaintProperty = imageNode->GetPaintProperty<ImageRenderProperty>();
|
||||
CHECK_NULL_VOID(imagePaintProperty);
|
||||
imagePaintProperty->UpdateSvgFillColor(sheetTheme->GetCloseIconImageColor());
|
||||
imageNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
|
||||
auto iconNode = DynamicCast<FrameNode>(sheetCloseIcon->GetChildAtIndex(0));
|
||||
CHECK_NULL_VOID(iconNode);
|
||||
|
||||
// when api >= 12, use symbol format image, else use image format.
|
||||
if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
|
||||
auto symbolLayoutProperty = iconNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(symbolLayoutProperty);
|
||||
symbolLayoutProperty->UpdateSymbolColorList({sheetTheme->GetCloseIconSymbolColor()});
|
||||
} else {
|
||||
auto imagePaintProperty = iconNode->GetPaintProperty<ImageRenderProperty>();
|
||||
CHECK_NULL_VOID(imagePaintProperty);
|
||||
imagePaintProperty->UpdateSvgFillColor(sheetTheme->GetCloseIconImageColor());
|
||||
}
|
||||
iconNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
|
||||
}
|
||||
|
||||
void SheetPresentationPattern::CheckSheetHeightChange()
|
||||
|
@ -99,6 +99,8 @@ public:
|
||||
theme->sheetBackgroundBlurStyle_ = sheetPattern->GetAttr<int>("sheet_background_blur_style", 0);
|
||||
theme->sheetNormalScale_ = sheetPattern->GetAttr<double>("sheet_normal_aging_scale", 1.0f);
|
||||
theme->sheetMaxAgingScale_ = sheetPattern->GetAttr<double>("sheet_max_aging_scale", 1.75f);
|
||||
theme->closeIconSource_ = themeConstants->GetSymbolByName("sys.symbol.xmark");
|
||||
theme->closeIconSymbolColor_ = sheetPattern->GetAttr<Color>("close_icon_symbol_color", Color(0xff182431));
|
||||
}
|
||||
};
|
||||
~SheetTheme() override = default;
|
||||
@ -188,6 +190,16 @@ public:
|
||||
return sheetMaxAgingScale_;
|
||||
}
|
||||
|
||||
const Color& GetCloseIconSymbolColor() const
|
||||
{
|
||||
return closeIconSymbolColor_;
|
||||
}
|
||||
|
||||
const uint32_t& GetCloseIconSource() const
|
||||
{
|
||||
return closeIconSource_;
|
||||
}
|
||||
|
||||
protected:
|
||||
SheetTheme() = default;
|
||||
|
||||
@ -204,11 +216,13 @@ private:
|
||||
Color maskColor_;
|
||||
Color closeIconColor_;
|
||||
Color closeIconImageColor_;
|
||||
Color closeIconSymbolColor_;
|
||||
std::string sheetType_;
|
||||
std::string sheetBottom_;
|
||||
int sheetBackgroundBlurStyle_;
|
||||
double sheetNormalScale_;
|
||||
double sheetMaxAgingScale_;
|
||||
uint32_t closeIconSource_ = 0;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
||||
|
@ -183,23 +183,47 @@ void SheetView::CreateCloseIconButtonNode(RefPtr<FrameNode> sheetNode, NG::Sheet
|
||||
focusHub->SetFocusDependence(FocusDependence::SELF);
|
||||
buttonNode->MarkModifyDone();
|
||||
|
||||
auto imageNode = FrameNode::CreateFrameNode(
|
||||
V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
|
||||
auto imageLayoutProperty = imageNode->GetLayoutProperty<ImageLayoutProperty>();
|
||||
CHECK_NULL_VOID(imageLayoutProperty);
|
||||
imageLayoutProperty->UpdateUserDefinedIdealSize(
|
||||
CalcSize(CalcLength(SHEET_CLOSE_ICON_IMAGE_HEIGHT), CalcLength(SHEET_CLOSE_ICON_IMAGE_HEIGHT)));
|
||||
imageLayoutProperty->UpdateImageFit(ImageFit::FILL);
|
||||
ImageSourceInfo imageSourceInfo;
|
||||
imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_CANCEL_SVG);
|
||||
imageSourceInfo.SetFillColor(sheetTheme->GetCloseIconImageColor());
|
||||
imageLayoutProperty->UpdateImageSourceInfo(imageSourceInfo);
|
||||
imageNode->MarkModifyDone();
|
||||
|
||||
buttonNode->AddChild(imageNode);
|
||||
CreateCloseIconNode(buttonNode);
|
||||
buttonNode->MountToParent(sheetNode);
|
||||
}
|
||||
|
||||
void SheetView::CreateCloseIconNode(RefPtr<FrameNode> buttonNode)
|
||||
{
|
||||
auto pipeline = buttonNode->GetContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
auto sheetTheme = pipeline->GetTheme<SheetTheme>();
|
||||
CHECK_NULL_VOID(sheetTheme);
|
||||
RefPtr<FrameNode> iconNode;
|
||||
|
||||
// when api >= 12, use symbol format image, else use image format.
|
||||
if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
|
||||
iconNode = FrameNode::CreateFrameNode(
|
||||
V2::SYMBOL_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
|
||||
CHECK_NULL_VOID(iconNode);
|
||||
auto symbolLayoutProperty = iconNode->GetLayoutProperty<TextLayoutProperty>();
|
||||
CHECK_NULL_VOID(symbolLayoutProperty);
|
||||
uint32_t symbolId = sheetTheme->GetCloseIconSource();
|
||||
symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo{symbolId});
|
||||
symbolLayoutProperty->UpdateFontSize(SHEET_CLOSE_ICON_IMAGE_HEIGHT);
|
||||
symbolLayoutProperty->UpdateSymbolColorList({sheetTheme->GetCloseIconSymbolColor()});
|
||||
} else {
|
||||
iconNode = FrameNode::CreateFrameNode(
|
||||
V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
|
||||
CHECK_NULL_VOID(iconNode);
|
||||
auto imageLayoutProperty = iconNode->GetLayoutProperty<ImageLayoutProperty>();
|
||||
CHECK_NULL_VOID(imageLayoutProperty);
|
||||
imageLayoutProperty->UpdateUserDefinedIdealSize(
|
||||
CalcSize(CalcLength(SHEET_CLOSE_ICON_IMAGE_HEIGHT), CalcLength(SHEET_CLOSE_ICON_IMAGE_HEIGHT)));
|
||||
imageLayoutProperty->UpdateImageFit(ImageFit::FILL);
|
||||
ImageSourceInfo imageSourceInfo;
|
||||
imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_CANCEL_SVG);
|
||||
imageSourceInfo.SetFillColor(sheetTheme->GetCloseIconImageColor());
|
||||
imageLayoutProperty->UpdateImageSourceInfo(imageSourceInfo);
|
||||
}
|
||||
iconNode->MarkModifyDone();
|
||||
buttonNode->AddChild(iconNode);
|
||||
}
|
||||
|
||||
RefPtr<FrameNode> SheetView::CreateScrollNode()
|
||||
{
|
||||
auto scroll = FrameNode::CreateFrameNode(
|
||||
|
@ -34,6 +34,7 @@ private:
|
||||
static void CreateDragBarNode(const RefPtr<FrameNode>& titleBuilder, const RefPtr<FrameNode>& operationColumn,
|
||||
NG::SheetStyle& sheetStyle, const RefPtr<FrameNode>& sheetNode);
|
||||
static void CreateCloseIconButtonNode(RefPtr<FrameNode> sheetNode, NG::SheetStyle& sheetStyle);
|
||||
static void CreateCloseIconNode(RefPtr<FrameNode> buttonNode);
|
||||
static void SetSheetOffset(RefPtr<FrameNode> sheetNode);
|
||||
static RefPtr<FrameNode> BuildMainTitle(RefPtr<FrameNode> sheetNode, NG::SheetStyle& sheetStyle);
|
||||
static RefPtr<FrameNode> BuildSubTitle(RefPtr<FrameNode> sheetNode, NG::SheetStyle& sheetStyle);
|
||||
|
@ -1943,4 +1943,62 @@ HWTEST_F(OverlayManagerTestUpdateNg, OnBindSheet031, TestSize.Level1)
|
||||
renderContext = sheetNode->GetRenderContext();
|
||||
EXPECT_EQ(renderContext->GetBorderStyle().value(), NEW_BORDER_STYLE_TEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnBindSheet032
|
||||
* @tc.desc: Test OverlayManager::OnBindSheet closeIcon test.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(OverlayManagerTestNg, OnBindSheet032, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create target node.
|
||||
*/
|
||||
auto targetNode = CreateTargetNode();
|
||||
auto stageNode = FrameNode::CreateFrameNode(
|
||||
V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<StagePattern>());
|
||||
auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG, 1, AceType::MakeRefPtr<RootPattern>());
|
||||
stageNode->MountToParent(rootNode);
|
||||
targetNode->MountToParent(stageNode);
|
||||
rootNode->MarkDirtyNode();
|
||||
/**
|
||||
* @tc.steps: step2. create sheetNode.
|
||||
* @tc.expected: closeIcon is Image.
|
||||
*/
|
||||
SheetStyle sheetStyle;
|
||||
bool isShow = true;
|
||||
CreateSheetBuilder();
|
||||
auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
|
||||
overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle,
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, targetNode);
|
||||
EXPECT_FALSE(overlayManager->modalStack_.empty());
|
||||
auto sheetNode = overlayManager->modalStack_.top().Upgrade();
|
||||
ASSERT_NE(sheetNode, nullptr);
|
||||
auto buttonNode = sheetNode->GetChildAtIndex(2);
|
||||
ASSERT_NE(buttonNode, nullptr);
|
||||
auto iconNode = buttonNode->GetChildAtIndex(0);
|
||||
ASSERT_NE(iconNode, nullptr);
|
||||
ASSERT_EQ(iconNode->GetTag(), V2::IMAGE_ETS_TAG);
|
||||
/**
|
||||
* @tc.steps: step3. Change SDK Version.
|
||||
* @tc.expected: closeIcon is Symbol.
|
||||
*/
|
||||
auto newTargetNode = CreateTargetNode();
|
||||
newTargetNode->MountToParent(stageNode);
|
||||
rootNode->MarkDirtyNode();
|
||||
int32_t backupApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion();
|
||||
AceApplicationInfo::GetInstance().SetApiTargetVersion(static_cast<int32_t>(PlatformVersion::VERSION_TWELVE));
|
||||
overlayManager->OnBindSheet(isShow, nullptr, std::move(builderFunc_), std::move(titleBuilderFunc_), sheetStyle,
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
newTargetNode);
|
||||
EXPECT_FALSE(overlayManager->modalStack_.empty());
|
||||
sheetNode = overlayManager->modalStack_.top().Upgrade();
|
||||
ASSERT_NE(sheetNode, nullptr);
|
||||
buttonNode = sheetNode->GetChildAtIndex(2);
|
||||
ASSERT_NE(buttonNode, nullptr);
|
||||
iconNode = buttonNode->GetChildAtIndex(0);
|
||||
ASSERT_NE(iconNode, nullptr);
|
||||
ASSERT_EQ(iconNode->GetTag(), V2::SYMBOL_ETS_TAG);
|
||||
AceApplicationInfo::GetInstance().SetApiTargetVersion(static_cast<int32_t>(backupApiVersion));
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
Loading…
Reference in New Issue
Block a user