From 80eeddfa78bcdc68aebcba5330d48b9542f47b27 Mon Sep 17 00:00:00 2001 From: SQ Date: Sat, 13 Sep 2025 18:05:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DSwiper=E5=8F=8D=E8=89=B2?= =?UTF-8?q?=E8=BE=93=E5=85=A5undefined=E6=97=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SQ Change-Id: I60e06c96563e053bb2cbc9e326b97d833aea61ae --- .../arkts_native_swiper_bridge.cpp | 2 +- .../native/node/node_swiper_modifier.cpp | 78 +++++--- interfaces/native/node/style_modifier.cpp | 8 +- test/unittest/interfaces/native_node_test.cpp | 171 ++++++++++++++++++ 4 files changed, 233 insertions(+), 26 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_swiper_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_swiper_bridge.cpp index 4f963ccb18e..ab15523224f 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_swiper_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_swiper_bridge.cpp @@ -368,7 +368,7 @@ ArkUINativeModuleValue SwiperBridge::SetSwiperDisplayArrow(ArkUIRuntimeCallInfo* } std::string displayArrowStr = displayArrowValueStr + "|" + showBackgroundStr + "|" + isSidebarMiddleStr + "|" + backgroundSizeStr + "|" + backgroundColorStr + "|" + arrowSizeStr + "|" + - arrowColorStr + "|" + isHoverShowStr + "|"; + arrowColorStr + "|" + isHoverShowStr + "|1|1|1|1|1|1|1|1"; if (SystemProperties::ConfigChangePerform()) { GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDisplayArrowRaw(nativeNode, displayArrowStr.c_str(), static_cast(&resObjs)); diff --git a/frameworks/core/interfaces/native/node/node_swiper_modifier.cpp b/frameworks/core/interfaces/native/node/node_swiper_modifier.cpp index 4efb27ffc54..71f4515fdee 100644 --- a/frameworks/core/interfaces/native/node/node_swiper_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_swiper_modifier.cpp @@ -39,6 +39,12 @@ constexpr int32_t ARROW_BACKGROUND_SIZE = 3; constexpr int32_t ARROW_BACKGROUND_COLOR = 4; constexpr int32_t ARROW_SIZE = 5; constexpr int32_t ARROW_COLOR = 6; +constexpr int32_t ARROW_ISSET_COLOR = 10; +constexpr int32_t ARROW_ISSET_IS_SHOW_BACKGROUND = 11; +constexpr int32_t ARROW_ISSET_IS_SIDE_BAR_MIDDLE = 12; +constexpr int32_t ARROW_ISSET_BACKGROUND_SIZE = 13; +constexpr int32_t ARROW_ISSET_BACKGROUND_COLOR = 14; +constexpr int32_t ARROW_ISSET_SIZE = 15; constexpr int32_t DISPLAY_ARROW_OBJECT = 2; constexpr int32_t DISPLAY_ARROW_TRUE = 1; constexpr int32_t DISPLAY_ARROW_VALUE = 0; @@ -140,22 +146,26 @@ void SetArrowBackgroundInfo(SwiperArrowParameters& swiperArrowParameters, GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT) ? dimension : swiperIndicatorTheme->GetBigArrowBackgroundSize(); - parseOk = Color::ParseColorString(backgroundColorValue, color); - swiperArrowParameters.backgroundColor = parseOk + parseOk = Color::ParseColorString(backgroundColorValue, color) && + arrowInfo[ARROW_ISSET_BACKGROUND_COLOR] == "1"; + color = Color(std::stoul(backgroundColorValue)); + swiperArrowParameters.backgroundColor = parseOk || color == Color(0x00000000) ? (swiperArrowParameters.parametersByUser.insert("backgroundColor"), color) : swiperIndicatorTheme->GetBigArrowBackgroundColor(); if (swiperArrowParameters.isShowBackground.value()) { swiperArrowParameters.arrowSize = swiperArrowParameters.backgroundSize.value() * ARROW_SIZE_COEFFICIENT; } else { - parseOk = StringUtils::StringToCalcDimensionNG(arrowSizeValue, dimension, false, DimensionUnit::VP); + parseOk = StringUtils::StringToCalcDimensionNG(arrowSizeValue, dimension, false, DimensionUnit::VP) && + arrowInfo[ARROW_ISSET_SIZE] == "1"; swiperArrowParameters.arrowSize = parseOk && GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT) ? dimension : swiperIndicatorTheme->GetBigArrowSize(); swiperArrowParameters.backgroundSize = swiperArrowParameters.arrowSize; } - parseOk = Color::ParseColorString(arrowColorValue, color); - swiperArrowParameters.arrowColor = parseOk + parseOk = Color::ParseColorString(arrowColorValue, color) && arrowInfo[ARROW_ISSET_COLOR] == "1"; + color = Color(std::stoul(arrowColorValue)); + swiperArrowParameters.arrowColor = parseOk || color == Color(0x00000000) ? (swiperArrowParameters.parametersByUser.insert("arrowColor"), color) : swiperIndicatorTheme->GetBigArrowColor(); } else { @@ -164,22 +174,26 @@ void SetArrowBackgroundInfo(SwiperArrowParameters& swiperArrowParameters, GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT) ? dimension : swiperIndicatorTheme->GetSmallArrowBackgroundSize(); - parseOk = Color::ParseColorString(backgroundColorValue, color); - swiperArrowParameters.backgroundColor = parseOk + parseOk = Color::ParseColorString(backgroundColorValue, color) && + arrowInfo[ARROW_ISSET_BACKGROUND_COLOR] == "1"; + color = Color(std::stoul(backgroundColorValue)); + swiperArrowParameters.backgroundColor = parseOk || color == Color(0x00000000) ? (swiperArrowParameters.parametersByUser.insert("backgroundColor"), color) : swiperIndicatorTheme->GetSmallArrowBackgroundColor(); if (swiperArrowParameters.isShowBackground.value()) { swiperArrowParameters.arrowSize = swiperArrowParameters.backgroundSize.value() * ARROW_SIZE_COEFFICIENT; } else { - parseOk = StringUtils::StringToCalcDimensionNG(arrowSizeValue, dimension, false, DimensionUnit::VP); + parseOk = StringUtils::StringToCalcDimensionNG(arrowSizeValue, dimension, false, DimensionUnit::VP) && + arrowInfo[ARROW_ISSET_SIZE] == "1"; swiperArrowParameters.arrowSize = parseOk && GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT) ? dimension : swiperIndicatorTheme->GetSmallArrowSize(); swiperArrowParameters.backgroundSize = swiperArrowParameters.arrowSize; } - parseOk = Color::ParseColorString(arrowColorValue, color); - swiperArrowParameters.arrowColor = parseOk + parseOk = Color::ParseColorString(arrowColorValue, color) && arrowInfo[ARROW_ISSET_COLOR] == "1"; + color = Color(std::stoul(arrowColorValue)); + swiperArrowParameters.arrowColor = parseOk || color == Color(0x00000000) ? (swiperArrowParameters.parametersByUser.insert("arrowColor"), color) : swiperIndicatorTheme->GetSmallArrowColor(); } @@ -216,7 +230,8 @@ bool GetArrowInfo(const std::vector& arrowInfo, SwiperArrowParamete return true; } -void GetSwiperArrowResObj(FrameNode* frameNode, SwiperArrowParameters& swiperArrowParameters) +void GetSwiperArrowResObj(FrameNode* frameNode, SwiperArrowParameters& swiperArrowParameters, + const std::vector& arrowInfo) { // If the dark and light switch is not turned on, // do not need to acquire the resource object. @@ -236,7 +251,9 @@ void GetSwiperArrowResObj(FrameNode* frameNode, SwiperArrowParameters& swiperArr ? swiperIndicatorTheme->GetBigArrowBackgroundColor() : swiperIndicatorTheme->GetSmallArrowBackgroundColor()); RefPtr bgColorResObj; - ResourceParseUtils::CompleteResourceObjectFromColor(bgColorResObj, backgroundColor, frameNode->GetTag()); + if (arrowInfo[ARROW_ISSET_BACKGROUND_COLOR] == "1") { + ResourceParseUtils::CompleteResourceObjectFromColor(bgColorResObj, backgroundColor, frameNode->GetTag()); + } swiperArrowParameters.backgroundColor = backgroundColor; swiperArrowParameters.resourceBackgroundColorValueObject = bgColorResObj; @@ -247,7 +264,9 @@ void GetSwiperArrowResObj(FrameNode* frameNode, SwiperArrowParameters& swiperArr ? swiperIndicatorTheme->GetBigArrowColor() : swiperIndicatorTheme->GetSmallArrowColor()); RefPtr arrowColorResObj; - ResourceParseUtils::CompleteResourceObjectFromColor(arrowColorResObj, arrowColor, frameNode->GetTag()); + if (arrowInfo[ARROW_ISSET_COLOR] == "1") { + ResourceParseUtils::CompleteResourceObjectFromColor(arrowColorResObj, arrowColor, frameNode->GetTag()); + } swiperArrowParameters.arrowColor = arrowColor; swiperArrowParameters.resourceArrowColorValueObject = arrowColorResObj; } @@ -455,7 +474,8 @@ SwiperParameters GetDotIndicatorProps(FrameNode* frameNode, ArkUISwiperIndicator return swiperParameters; } -void GetSwiperIndicatorResObj(FrameNode* frameNode, SwiperParameters& swiperParameters) +void GetSwiperIndicatorResObj(FrameNode* frameNode, SwiperParameters& swiperParameters, + ArkUISwiperIndicator* indicator) { // If the dark and light switch is not turned on, // do not need to acquire the resource object. @@ -472,7 +492,9 @@ void GetSwiperIndicatorResObj(FrameNode* frameNode, SwiperParameters& swiperPara Color colorVal = swiperParameters.colorVal.value_or(swiperIndicatorTheme->GetColor()); RefPtr colorValResObj; - ResourceParseUtils::CompleteResourceObjectFromColor(colorValResObj, colorVal, frameNode->GetTag()); + if (indicator->colorValue.isSet) { + ResourceParseUtils::CompleteResourceObjectFromColor(colorValResObj, colorVal, frameNode->GetTag()); + } swiperParameters.colorVal = colorVal; swiperParameters.resourceColorValueObject = colorValResObj; @@ -480,7 +502,10 @@ void GetSwiperIndicatorResObj(FrameNode* frameNode, SwiperParameters& swiperPara Color selectedColorVal = swiperParameters.selectedColorVal.value_or(swiperIndicatorTheme->GetSelectedColor()); RefPtr selectedColorResObj; - ResourceParseUtils::CompleteResourceObjectFromColor(selectedColorResObj, selectedColorVal, frameNode->GetTag()); + if (indicator->selectedColorValue.isSet) { + ResourceParseUtils::CompleteResourceObjectFromColor(selectedColorResObj, + selectedColorVal, frameNode->GetTag()); + } swiperParameters.selectedColorVal = selectedColorVal; swiperParameters.resourceSelectedColorValueObject = selectedColorResObj; } @@ -526,7 +551,8 @@ SwiperDigitalParameters GetDigitIndicatorProps(FrameNode* frameNode, ArkUISwiper return swiperDigitalParameters; } -void GetSwiperDigitIndicatorResObj(FrameNode* frameNode, SwiperDigitalParameters& swiperDigitParameters) +void GetSwiperDigitIndicatorResObj(FrameNode* frameNode, + SwiperDigitalParameters& swiperDigitParameters, ArkUISwiperDigitIndicator* indicator) { // If the dark and light switch is not turned on, // do not need to acquire the resource object. @@ -544,7 +570,9 @@ void GetSwiperDigitIndicatorResObj(FrameNode* frameNode, SwiperDigitalParameters swiperDigitParameters.fontColor.value_or( swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor()); RefPtr fontColorResObj; - ResourceParseUtils::CompleteResourceObjectFromColor(fontColorResObj, fontColor, frameNode->GetTag()); + if (indicator->fontColor.isSet) { + ResourceParseUtils::CompleteResourceObjectFromColor(fontColorResObj, fontColor, frameNode->GetTag()); + } swiperDigitParameters.fontColor = fontColor; swiperDigitParameters.resourceFontColorValueObject = fontColorResObj; @@ -553,8 +581,10 @@ void GetSwiperDigitIndicatorResObj(FrameNode* frameNode, SwiperDigitalParameters swiperDigitParameters.selectedFontColor.value_or( swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor()); RefPtr selectedFontColorResObj; - ResourceParseUtils::CompleteResourceObjectFromColor(selectedFontColorResObj, - selectedFontColor, frameNode->GetTag()); + if (indicator->selectedFontColor.isSet) { + ResourceParseUtils::CompleteResourceObjectFromColor(selectedFontColorResObj, + selectedFontColor, frameNode->GetTag()); + } swiperDigitParameters.selectedFontColor = selectedFontColor; swiperDigitParameters.resourceSelectedFontColorValueObject = selectedFontColorResObj; } @@ -854,7 +884,7 @@ void SetSwiperDisplayArrow(ArkUINodeHandle node, ArkUI_CharPtr displayArrowStr) SwiperModelNG::SetDisplayArrow(frameNode, false); return; } - GetSwiperArrowResObj(frameNode, swiperArrowParameters); + GetSwiperArrowResObj(frameNode, swiperArrowParameters, res); SwiperModelNG::SetArrowStyle(frameNode, swiperArrowParameters); SwiperModelNG::SetDisplayArrow(frameNode, true); } else if (displayArrowValue == DISPLAY_ARROW_TRUE) { @@ -864,7 +894,7 @@ void SetSwiperDisplayArrow(ArkUINodeHandle node, ArkUI_CharPtr displayArrowStr) SwiperModelNG::SetDisplayArrow(frameNode, false); return; } - GetSwiperArrowResObj(frameNode, swiperArrowParameters); + GetSwiperArrowResObj(frameNode, swiperArrowParameters, res); SwiperModelNG::SetArrowStyle(frameNode, swiperArrowParameters); SwiperModelNG::SetDisplayArrow(frameNode, true); } else { @@ -1564,7 +1594,7 @@ void SetSwiperIndicatorStyle(ArkUINodeHandle node, ArkUISwiperIndicator* indicat if (indicator->type == ArkUISwiperIndicatorType::DOT) { SwiperModelNG::SetIndicatorIsBoolean(frameNode, false); SwiperParameters swiperParameters = GetDotIndicatorProps(frameNode, indicator); - GetSwiperIndicatorResObj(frameNode, swiperParameters); + GetSwiperIndicatorResObj(frameNode, swiperParameters, indicator); SwiperModelNG::SetDotIndicatorStyle(frameNode, swiperParameters); SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DOT); } @@ -1618,7 +1648,7 @@ void SetSwiperDigitIndicatorStyle(ArkUINodeHandle node, ArkUISwiperDigitIndicato if (indicator->type == ArkUISwiperIndicatorType::DIGIT) { SwiperModelNG::SetIndicatorIsBoolean(frameNode, false); SwiperDigitalParameters swiperDigitParameters = GetDigitIndicatorProps(frameNode, indicator); - GetSwiperDigitIndicatorResObj(frameNode, swiperDigitParameters); + GetSwiperDigitIndicatorResObj(frameNode, swiperDigitParameters, indicator); SwiperModelNG::SetDigitIndicatorStyle(frameNode, swiperDigitParameters); SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DIGIT); } diff --git a/interfaces/native/node/style_modifier.cpp b/interfaces/native/node/style_modifier.cpp index 6ad069afd73..c6eecc32e4a 100644 --- a/interfaces/native/node/style_modifier.cpp +++ b/interfaces/native/node/style_modifier.cpp @@ -8768,7 +8768,7 @@ int32_t SetSwiperShowDisplayArrow(ArkUI_NodeHandle node, const ArkUI_AttributeIt } auto* fullImpl = GetFullImpl(); ArkUI_SwiperArrowStyle* arrowStyle = reinterpret_cast(item->object); - double displayArrow[ALLOW_SIZE_9] = { 1, 0, 0, DEFAULT_SIZE_24, 0, DEFAULT_SIZE_18, 0, 0, 1 }; + double displayArrow[ALLOW_SIZE_16] = { 1, 0, 0, DEFAULT_SIZE_24, 0, DEFAULT_SIZE_18, 0, 0, 1 }; double showBackground = 0.0; double showSidebarMiddle = 0.0; double backgroundSize = 0.0; @@ -8799,6 +8799,12 @@ int32_t SetSwiperShowDisplayArrow(ArkUI_NodeHandle node, const ArkUI_AttributeIt displayArrow[NUM_4] = backgroundColor; displayArrow[NUM_5] = arrowSize; displayArrow[NUM_6] = arrowColor; + displayArrow[NUM_10] = arrowStyle->arrowColor.isSet; + displayArrow[NUM_11] = arrowStyle->showBackground.isSet; + displayArrow[NUM_12] = arrowStyle->showSidebarMiddle.isSet; + displayArrow[NUM_13] = arrowStyle->backgroundSize.isSet; + displayArrow[NUM_14] = arrowStyle->backgroundColor.isSet; + displayArrow[NUM_15] = arrowStyle->arrowSize.isSet; std::stringstream ss; for (const auto& str : displayArrow) { ss << std::fixed << std::setprecision(0) << str << "|"; diff --git a/test/unittest/interfaces/native_node_test.cpp b/test/unittest/interfaces/native_node_test.cpp index e73e4408e0e..19a724c0f90 100644 --- a/test/unittest/interfaces/native_node_test.cpp +++ b/test/unittest/interfaces/native_node_test.cpp @@ -9419,6 +9419,69 @@ HWTEST_F(NativeNodeTest, SwiperArrowStyleTest002, TestSize.Level1) nodeAPI->disposeNode(swiperNode); } +/** + * @tc.name: SwiperArrowStyleTest003 + * @tc.desc: Test NODE_SWIPER_SHOW_DISPLAY_ARROW function. + * @tc.type: FUNC + */ +HWTEST_F(NativeNodeTest, SwiperArrowStyleTest003, TestSize.Level1) +{ + /** + * @tc.steps: step1. Turn off the dark and light switch and initialize. + */ + g_isConfigChangePerform = false; + EXPECT_FALSE(SystemProperties::ConfigChangePerform()); + auto nodeAPI = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + ArkUI_NodeHandle swiperNode = nodeAPI->createNode(ARKUI_NODE_SWIPER); + const int size = 6; + const char* arr[size] = {"0", "1", "2", "3", "4", "5"}; + + /** + * @tc.steps: step2. Initialize the text component and mount it to the swiper. + */ + for (int i = 0; i < size; i++) { + ArkUI_NodeHandle text = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem content = { .string = arr[i] }; + nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, &content); + + ArkUI_NumberValue value[] = {0}; + ArkUI_AttributeItem item = {value, 1}; + value[0].f32 = 300; + nodeAPI->setAttribute(text, NODE_WIDTH, &item); + value[0].f32 = 150; + nodeAPI->setAttribute(text, NODE_HEIGHT, &item); + + ArkUI_AttributeItem textId = {.string = "SwiperTextId2"}; + nodeAPI->setAttribute(text, NODE_ID, &textId); + nodeAPI->addChild(swiperNode, text); + } + + /** + * @tc.steps: step3. Create an arrowStyle and configure the properties, + * then set the arrowStyle to the NODE_SWIPER_SHOW_DISPLAY_ARROW. + */ + ArkUI_SwiperArrowStyle* arrowStyle = OH_ArkUI_SwiperArrowStyle_Create(); + OH_ArkUI_SwiperArrowStyle_SetArrowSize(arrowStyle, 20); + OH_ArkUI_SwiperArrowStyle_SetBackgroundSize(arrowStyle, 30); + ArkUI_NumberValue valueTemp[1]; + ArkUI_AttributeItem itemTemp = {.value=valueTemp, .size=1, .object = arrowStyle}; + valueTemp[0].i32 = 2; + auto setResult = nodeAPI->setAttribute(swiperNode, NODE_SWIPER_SHOW_DISPLAY_ARROW, &itemTemp); + EXPECT_EQ(setResult, ERROR_CODE_NO_ERROR); + + /** + * @tc.steps: step4. Test attribute acquisition, + */ + auto getResult = nodeAPI->getAttribute(swiperNode, NODE_SWIPER_SHOW_DISPLAY_ARROW); + auto returnObject = static_cast(getResult->object); + ASSERT_NE(returnObject, nullptr); + EXPECT_EQ(OH_ArkUI_SwiperArrowStyle_GetBackgroundColor(arrowStyle), 0x19000000); + EXPECT_EQ(OH_ArkUI_SwiperArrowStyle_GetArrowColor(arrowStyle), 0xE5000000); + OH_ArkUI_SwiperArrowStyle_Destroy(arrowStyle); + nodeAPI->disposeNode(swiperNode); +} + /** * @tc.name: SwiperIndicatorTest001 * @tc.desc: Test NODE_SWIPER_INDICATOR function. @@ -9660,4 +9723,112 @@ HWTEST_F(NativeNodeTest, SwiperIndicatorTest004, TestSize.Level1) OH_ArkUI_SwiperIndicator_Dispose(swiperIndicator); nodeAPI->disposeNode(swiperNode); } + +/** + * @tc.name: SwiperIndicatorTest005 + * @tc.desc: Test NODE_SWIPER_INDICATOR function. + * @tc.type: FUNC + */ +HWTEST_F(NativeNodeTest, SwiperIndicatorTest005, TestSize.Level1) +{ + /** + * @tc.steps: step1. Turn off the dark and light switch and initialize. + */ + g_isConfigChangePerform = false; + EXPECT_FALSE(SystemProperties::ConfigChangePerform()); + auto nodeAPI = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + ArkUI_NodeHandle swiperNode = nodeAPI->createNode(ARKUI_NODE_SWIPER); + const int size = 6; + const char* arr[size] = {"a", "b", "c", "d", "e", "f"}; + + /** + * @tc.steps: step2. Initialize the text component and mount it to the swiper. + */ + for (int i = 0; i < size; i++) { + ArkUI_NodeHandle text = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem content = { .string = arr[i] }; + nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, &content); + ArkUI_NumberValue value[] = {0}; + ArkUI_AttributeItem item = {value, 1}; + value[0].f32 = 300; + nodeAPI->setAttribute(text, NODE_WIDTH, &item); + value[0].f32 = 150; + nodeAPI->setAttribute(text, NODE_HEIGHT, &item); + nodeAPI->addChild(swiperNode, text); + } + + /** + * @tc.steps: step3. Create an indicator and configure the properties, + * then set the indicator to the NODE_SWIPER_INDICATOR. + */ + auto indicator = OH_ArkUI_SwiperDigitIndicator_Create(); + OH_ArkUI_SwiperDigitIndicator_SetSelectedFontSize(indicator, 20); + OH_ArkUI_SwiperDigitIndicator_SetFontSize(indicator, 25); + ArkUI_NumberValue valueTemp[] = {{.i32 = ARKUI_SWIPER_INDICATOR_TYPE_DIGIT}}; + ArkUI_AttributeItem itemTemp = {.value=valueTemp, .size=1, .object = indicator}; + auto setResult = nodeAPI->setAttribute(swiperNode, NODE_SWIPER_INDICATOR, &itemTemp); + EXPECT_EQ(setResult, ERROR_CODE_NO_ERROR); + + /** + * @tc.steps: step4. Test attribute acquisition, + */ + EXPECT_EQ(OH_ArkUI_SwiperDigitIndicator_GetFontColor(indicator), 0xE5000000); + EXPECT_EQ(OH_ArkUI_SwiperDigitIndicator_GetSelectedFontColor(indicator), 0xE5000000); + OH_ArkUI_SwiperDigitIndicator_Destroy(indicator); + nodeAPI->disposeNode(swiperNode); +} + +/** + * @tc.name: SwiperIndicatorTest006 + * @tc.desc: Test NODE_SWIPER_INDICATOR function. + * @tc.type: FUNC + */ +HWTEST_F(NativeNodeTest, SwiperIndicatorTest006, TestSize.Level1) +{ + /** + * @tc.steps: step1. Turn off the dark and light switch and initialize. + */ + g_isConfigChangePerform = false; + EXPECT_FALSE(SystemProperties::ConfigChangePerform()); + auto nodeAPI = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + ArkUI_NodeHandle swiperNode = nodeAPI->createNode(ARKUI_NODE_SWIPER); + const int size = 7; + const char* arr[size] = {"a", "b", "c", "d", "e", "f", "g"}; + + /** + * @tc.steps: step2. Initialize the text component and mount it to the swiper. + */ + for (int i = 0; i < size; i++) { + ArkUI_NodeHandle text = nodeAPI->createNode(ARKUI_NODE_TEXT); + ArkUI_AttributeItem content = { .string = arr[i] }; + nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, &content); + ArkUI_NumberValue value[] = {0}; + ArkUI_AttributeItem item = {value, 1}; + value[0].f32 = 430; + nodeAPI->setAttribute(text, NODE_WIDTH, &item); + value[0].f32 = 170; + nodeAPI->setAttribute(text, NODE_HEIGHT, &item); + nodeAPI->addChild(swiperNode, text); + } + + /** + * @tc.steps: step3. Create an swiperIndicator and configure the properties, + * then set the swiperIndicator to the NODE_SWIPER_INDICATOR. + */ + auto swiperIndicator = OH_ArkUI_SwiperIndicator_Create(ARKUI_SWIPER_INDICATOR_TYPE_DOT); + ArkUI_NumberValue valueTemp[] = {{.i32 = ARKUI_SWIPER_INDICATOR_TYPE_DOT}}; + ArkUI_AttributeItem itemTemp = {.value=valueTemp, .size=1, .object = swiperIndicator}; + auto setResult = nodeAPI->setAttribute(swiperNode, NODE_SWIPER_INDICATOR, &itemTemp); + EXPECT_EQ(setResult, ERROR_CODE_NO_ERROR); + + /** + * @tc.steps: step4. Test attribute acquisition, + */ + EXPECT_EQ(OH_ArkUI_SwiperIndicator_GetColor(swiperIndicator), 0x19000000); + EXPECT_EQ(OH_ArkUI_SwiperIndicator_GetSelectedColor(swiperIndicator), 0xFF0A59F7); + OH_ArkUI_SwiperIndicator_Dispose(swiperIndicator); + nodeAPI->disposeNode(swiperNode); +} } // namespace OHOS::Ace -- Gitee