diff --git a/frameworks/bridge/declarative_frontend/jsview/js_column_split.cpp b/frameworks/bridge/declarative_frontend/jsview/js_column_split.cpp index b7ec0ba4050b3e809ad410f83a1f813daefa4403..8d88778381dfab8c4b23987b6399c7cba3812170 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_column_split.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_column_split.cpp @@ -47,22 +47,8 @@ void JSColumnSplit::JsDivider(const JSCallbackInfo& args) RefPtr endResObj; ConvertFromJSValue(obj->GetProperty("startMargin"), divider.startMargin, startResObj); ConvertFromJSValue(obj->GetProperty("endMargin"), divider.endMargin, endResObj); - if (SystemProperties::ConfigChangePerform() && startResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::ColumnSplitDivider& divider) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - divider.startMargin = result; - }; - divider.AddResource("columnSplit.divider.startMargin", startResObj, std::move(updateFunc)); - } - if (SystemProperties::ConfigChangePerform() && endResObj) { - auto&& updateFunc = [](const RefPtr& resObj, NG::ColumnSplitDivider& divider) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - divider.endMargin = result; - }; - divider.AddResource("columnSplit.divider.endMargin", endResObj, std::move(updateFunc)); - } + NG::LinearSplitModelNG::RegisterResObj(startResObj, divider, "columnSplit.divider.startMargin"); + NG::LinearSplitModelNG::RegisterResObj(endResObj, divider, "columnSplit.divider.endMargin"); LinearSplitModel::GetInstance()->SetDivider(NG::SplitType::COLUMN_SPLIT, divider); args.ReturnSelf(); diff --git a/frameworks/core/components_ng/pattern/linear_split/linear_split_model_ng.cpp b/frameworks/core/components_ng/pattern/linear_split/linear_split_model_ng.cpp index 7dfcf4fac1df68132f0df002ce583e16c1ff79b5..e8e1e355177d105d190f0d27ce6a98b8e07e3073 100644 --- a/frameworks/core/components_ng/pattern/linear_split/linear_split_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/linear_split/linear_split_model_ng.cpp @@ -15,6 +15,7 @@ #include "core/components_ng/pattern/linear_split/linear_split_model_ng.h" +#include "core/common/resource/resource_parse_utils.h" #include "core/components_ng/base/view_stack_processor.h" #include "core/components_ng/pattern/linear_split/linear_split_pattern.h" @@ -96,6 +97,23 @@ void LinearSplitModelNG::SetDivider(FrameNode* frameNode, NG::SplitType splitTyp ACE_UPDATE_NODE_LAYOUT_PROPERTY(LinearSplitLayoutProperty, Divider, divider, frameNode); } +void LinearSplitModelNG::RegisterResObj( + const RefPtr& resObj, NG::ColumnSplitDivider& divider, const std::string key) +{ + if (SystemProperties::ConfigChangePerform() && resObj) { + auto&& updateFunc = [key](const RefPtr& resObj, NG::ColumnSplitDivider& divider) { + CalcDimension result; + ResourceParseUtils::ParseResDimensionVp(resObj, result); + if (key == "columnSplit.divider.startMargin") { + divider.startMargin = result; + } else if (key == "columnSplit.divider.endMargin") { + divider.endMargin = result; + } + }; + divider.AddResource(key, resObj, std::move(updateFunc)); + } +} + void LinearSplitModelNG::ResetResObj(FrameNode* frameNode, const std::string& key) { if (!SystemProperties::ConfigChangePerform()) { diff --git a/frameworks/core/components_ng/pattern/linear_split/linear_split_model_ng.h b/frameworks/core/components_ng/pattern/linear_split/linear_split_model_ng.h index b907fad982dfc9dd7e3c5222a7057de461bd0783..d5160c24112695e20612ff6d7d312f3e20d2040d 100644 --- a/frameworks/core/components_ng/pattern/linear_split/linear_split_model_ng.h +++ b/frameworks/core/components_ng/pattern/linear_split/linear_split_model_ng.h @@ -30,6 +30,8 @@ public: static void SetResizable(FrameNode* frameNode, NG::SplitType splitType, bool resizable); static void SetDivider(FrameNode* frameNode, NG::SplitType splitType, const NG::ColumnSplitDivider& divider); static void ResetResObj(FrameNode* frameNode, const std::string& key); + static void RegisterResObj( + const RefPtr& resObj, NG::ColumnSplitDivider& divider, const std::string key); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/node/column_split_modifier.cpp b/frameworks/core/interfaces/native/node/column_split_modifier.cpp index 7be06b650948712be4029e75cdf801c0fb5b2404..b49124ab32f02870bc6fc5333a239a69de5712e5 100644 --- a/frameworks/core/interfaces/native/node/column_split_modifier.cpp +++ b/frameworks/core/interfaces/native/node/column_split_modifier.cpp @@ -47,22 +47,12 @@ void SetColumnSplitDivider(ArkUINodeHandle node, ArkUI_Float32 stVal, int32_t st if (SystemProperties::ConfigChangePerform() && startMarginRawPtr) { auto* start = reinterpret_cast(startMarginRawPtr); auto startResObj = AceType::Claim(start); - auto&& updateFunc = [](const RefPtr& resObj, NG::ColumnSplitDivider& divider) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - divider.startMargin = result; - }; - divider.AddResource("columnSplit.divider.startMargin", startResObj, std::move(updateFunc)); + LinearSplitModelNG::RegisterResObj(startResObj, divider, "columnSplit.divider.startMargin"); } if (SystemProperties::ConfigChangePerform() && endMarginRawPtr) { auto* end = reinterpret_cast(endMarginRawPtr); auto endResObj = AceType::Claim(end); - auto&& updateFunc = [](const RefPtr& resObj, NG::ColumnSplitDivider& divider) { - CalcDimension result; - ResourceParseUtils::ParseResDimensionVp(resObj, result); - divider.endMargin = result; - }; - divider.AddResource("columnSplit.divider.endMargin", endResObj, std::move(updateFunc)); + LinearSplitModelNG::RegisterResObj(endResObj, divider, "columnSplit.divider.endMargin"); } LinearSplitModelNG::SetDivider(frameNode, SplitType::COLUMN_SPLIT, divider); } diff --git a/test/unittest/core/pattern/linear_split/linear_split_test_ng.cpp b/test/unittest/core/pattern/linear_split/linear_split_test_ng.cpp index cbd2a67a5559a83b35aafff22672757529d86dae..a63f14627794a9f0f195ea3687833ec14d31620f 100644 --- a/test/unittest/core/pattern/linear_split/linear_split_test_ng.cpp +++ b/test/unittest/core/pattern/linear_split/linear_split_test_ng.cpp @@ -26,6 +26,7 @@ #include "core/components_ng/pattern/linear_layout/column_model_ng.h" #include "core/components_ng/pattern/linear_split/linear_split_model.h" #include "core/components_ng/pattern/linear_split/linear_split_pattern.h" +#include "test/mock/base/mock_system_properties.h" #include "test/mock/core/pipeline/mock_pipeline_context.h" #include "test/mock/core/render/mock_render_context.h" @@ -1326,4 +1327,25 @@ HWTEST_F(LinearSplitTestNg, IgnoreLayoutSafeArea002, TestSize.Level1) EXPECT_EQ(column->GetGeometryNode()->GetFrameOffset(), OffsetF(0.0f, 100.0f)) << column->GetGeometryNode()->GetFrameRect().ToString(); } + +/** + * @tc.name: RegisterResObj + * @tc.desc: Test RegisterResObj of linear_split + * @tc.type: FUNC + */ +HWTEST_F(LinearSplitTestNg, RegisterResObj, TestSize.Level1) +{ + g_isConfigChangePerform = true; + SystemProperties::ConfigChangePerform(); + std::string bundleName = "com.example.test"; + std::string moduleName = "entry"; + RefPtr resObj = AceType::MakeRefPtr(bundleName, moduleName, 0); + NG::ColumnSplitDivider divider; + LinearSplitModelNG::RegisterResObj(resObj, divider, "columnSplit.divider.startMargin"); + divider.ReloadResources(); + EXPECT_EQ(divider.resMap_.size(), 1); + LinearSplitModelNG::RegisterResObj(resObj, divider, "columnSplit.divider.endMargin"); + divider.ReloadResources(); + EXPECT_EQ(divider.resMap_.size(), 2); +} } // namespace OHOS::Ace::NG \ No newline at end of file