diff --git a/frameworks/core/components_ng/base/multithread.h b/frameworks/core/components_ng/base/multithread.h new file mode 100644 index 0000000000000000000000000000000000000000..5fc4f3e03dd8925b5086b81e6645f1a4837d7330 --- /dev/null +++ b/frameworks/core/components_ng/base/multithread.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MULTITHREAD_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MULTITHREAD_H + +#define FREE_NODE_CHECK(node, func, ...) \ + if (node && node->IsFree()) { \ + return func##MultiThread(__VA_ARGS__); \ + } \ + +#define THREAD_SAFE_NODE_CHECK(node, func, ...) \ + if (node && node->IsThreadSafeNode()) { \ + return func##MultiThread(__VA_ARGS__); \ + } \ + + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MULTITHREAD_H \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_model_ng.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_model_ng.cpp index 0831d89a3ac0b4cda4dc63f20e49850d06b60db3..b197b0a9090e2a13f52b079a6840ccc105f4c603 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/swiper/swiper_model_ng.cpp @@ -25,6 +25,7 @@ #include "base/utils/utils.h" #include "core/components/swiper/swiper_component.h" #include "core/components_ng/base/frame_node.h" +#include "core/components_ng/base/mutilthread.h" #include "core/components_ng/base/view_stack_processor.h" #include "core/components_ng/pattern/swiper/arc_swiper_pattern.h" #include "core/components_ng/pattern/swiper/swiper_pattern.h" @@ -620,6 +621,7 @@ void SwiperModelNG::SetDuration(FrameNode* frameNode, uint32_t duration) void SwiperModelNG::SetCachedCount(FrameNode* frameNode, int32_t cachedCount) { + FREE_NODE_CHECK(SetCachedCount, frameNode, frameNode, cachedCount); CHECK_NULL_VOID(frameNode); auto pattern = frameNode->GetPattern(); CHECK_NULL_VOID(pattern); diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_model_ng.h b/frameworks/core/components_ng/pattern/swiper/swiper_model_ng.h index b4c5be791d0b25d5ed3b5c02c447d8414c868043..95a57589ed62c333cfa7e4fc34ac5ae7ba8c97b6 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_model_ng.h +++ b/frameworks/core/components_ng/pattern/swiper/swiper_model_ng.h @@ -95,6 +95,7 @@ public: static void SetAutoPlayInterval(FrameNode* frameNode, uint32_t interval); static void SetDuration(FrameNode* frameNode, uint32_t duration); static void SetCachedCount(FrameNode* frameNode, int32_t cachedCount); + static void SetCachedCount_MultiThread(FrameNode* frameNode, int32_t cachedCount); static int32_t GetCachedCount(FrameNode* frameNode); static void SetCachedIsShown(FrameNode* frameNode, bool isShown); static bool GetCachedIsShown(FrameNode* frameNode); diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_model_ng_multithread.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_model_ng_multithread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c69cd887da30452f403226c6faa6e2eff0185e77 --- /dev/null +++ b/frameworks/core/components_ng/pattern/swiper/swiper_model_ng_multithread.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/components_ng/pattern/swiper/swiper_model_ng.h" + +#include +#include +#include + +#include "base/error/error_code.h" +#include "base/geometry/axis.h" +#include "base/memory/referenced.h" +#include "base/utils/utils.h" +#include "core/components/swiper/swiper_component.h" +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/base/mutilthread.h" +#include "core/components_ng/base/view_stack_processor.h" +#include "core/components_ng/pattern/swiper/arc_swiper_pattern.h" +#include "core/components_ng/pattern/swiper/swiper_pattern.h" +#include "core/components_ng/pattern/swiper/swiper_node.h" +#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_utils.h" + + +namespace OHOS::Ace::NG { +void SwiperModelNG::SetCachedCount_MultiThread(FrameNode* frameNode, int32_t cachedCount) +{ + CHECK_NULL_VOID(frameNode); + auto setCachedTask = [weakNode = AceType::WeakClaim(frameNode), cachedCount]() { + auto frameNode = weakNode.Upgrade(); + CHECK_NULL_VOID(frameNode); + auto pattern = frameNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->SetCachedCount(cachedCount); + ACE_UPDATE_NODE_LAYOUT_PROPERTY(SwiperLayoutProperty, CachedCount, cachedCount, frameNode); + }; + frameNode->PostAfterAttachMainTreeTask(std::move(setCachedTask)); +} +} \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp index 1ace58949e6f848be966a582f0e13f0720eff00a..25c5d0fbff19a85125165d2e3cc785b54717b19a 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp @@ -37,6 +37,7 @@ #include "core/common/container_scope.h" #include "core/common/recorder/node_data_cache.h" #include "core/components/common/layout/constants.h" +#include "core/components_ng/base/multithread.h" #include "core/components_ng/pattern/navrouter/navdestination_pattern.h" #include "core/components_ng/pattern/scrollable/scrollable_properties.h" #include "core/components_ng/pattern/swiper/swiper_helper.h" @@ -112,6 +113,7 @@ void SwiperPattern::OnAttachToFrameNode() { auto host = GetHost(); CHECK_NULL_VOID(host); + FREE_NODE_CHECK(OnAttachToFrameNode, host); auto renderContext = host->GetRenderContext(); CHECK_NULL_VOID(renderContext); renderContext->SetClipToFrame(true); @@ -126,6 +128,7 @@ void SwiperPattern::OnAttachToFrameNode() void SwiperPattern::OnDetachFromFrameNode(FrameNode* node) { + FREE_NODE_CHECK(OnDetachFromFrameNode, node, node); auto pipeline = GetContext(); CHECK_NULL_VOID(pipeline); if (HasSurfaceChangedCallback()) { @@ -136,6 +139,8 @@ void SwiperPattern::OnDetachFromFrameNode(FrameNode* node) void SwiperPattern::OnAttachToMainTree() { + auto host = GetHost(); + FREE_NODE_CHECK(OnAttachToMainTree, host); if (!isInit_) { SetOnHiddenChangeForParent(); } @@ -143,6 +148,8 @@ void SwiperPattern::OnAttachToMainTree() void SwiperPattern::OnDetachFromMainTree() { + auto host = GetHost(); + FREE_NODE_CHECK(OnDetachFromMainTree, host); RemoveOnHiddenChange(); } diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h index 2269d93b8983bcab2ab7b3e829b0af5818c18acd..44ff1484f4f140de6ba7d8c8b9b3e8d5fa29209c 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h @@ -880,6 +880,10 @@ private: void OnDetachFromFrameNode(FrameNode* node) override; void OnAttachToMainTree() override; void OnDetachFromMainTree() override; + void OnAttachToFrameNode_MultiThread(); + void OnDetachFromFrameNode_MultiThread(FrameNode* node); + void OnAttachToMainTree_MultiThread(FrameNode* node); + void OnDetachFromMainTree_MultiThread(FrameNode* node); void InitSurfaceChangedCallback(); bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; void HandleTargetIndex(const RefPtr& dirty, const RefPtr& algo); diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern_multithread.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_pattern_multithread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5d8815c88b2a955500ae689e8c5614873707fd4c --- /dev/null +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern_multithread.cpp @@ -0,0 +1,85 @@ +#include "core/components_ng/pattern/swiper/swiper_pattern.h" + +#include +#include +#include +#include + +#include "base/error/error_code.h" +#include "base/geometry/axis.h" +#include "base/geometry/dimension.h" +#include "base/geometry/ng/offset_t.h" +#include "base/log/ace_trace.h" +#include "base/log/event_report.h" +#include "base/log/log_wrapper.h" +#include "base/perfmonitor/perf_constants.h" +#include "base/perfmonitor/perf_monitor.h" +#include "base/ressched/ressched_report.h" +#include "base/utils/utils.h" +#include "core/animation/curve.h" +#include "core/animation/curves.h" +#include "core/animation/spring_curve.h" +#include "core/common/container_scope.h" +#include "core/common/recorder/node_data_cache.h" +#include "core/components/common/layout/constants.h" +#include "core/components_ng/pattern/navrouter/navdestination_pattern.h" +#include "core/components_ng/pattern/scrollable/scrollable_properties.h" +#include "core/components_ng/pattern/swiper/swiper_helper.h" +#include "core/components_ng/pattern/swiper/swiper_node.h" +#include "core/components_ng/pattern/swiper/swiper_paint_method.h" +#include "core/components_ng/pattern/swiper/swiper_theme.h" +#include "core/components_ng/pattern/swiper_indicator/indicator_common/arc_swiper_indicator_pattern.h" +#include "core/components_ng/pattern/swiper_indicator/indicator_common/indicator_pattern.h" +#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_arrow_pattern.h" +#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h" +#include "core/components_ng/pattern/tabs/tab_content_node.h" +#include "core/components_ng/pattern/tabs/tab_content_pattern.h" +#include "core/components_ng/pattern/tabs/tabs_node.h" +#include "core/components_ng/render/adapter/component_snapshot.h" +#include "core/components_ng/syntax/for_each_node.h" +#include "core/components_ng/syntax/lazy_for_each_node.h" +#include "core/components_ng/syntax/repeat_virtual_scroll_node.h" +#include "core/components_ng/syntax/repeat_virtual_scroll_2_node.h" + +namespace OHOS::Ace::NG { + +void SwiperPattern::OnAttachToFrameNode_MultiThread() +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto renderContext = host->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + renderContext->SetClipToFrame(true); + renderContext->SetClipToBounds(true); +} + +void SwiperPattern::OnDetachFromFrameNode_MultiThread(FrameNode* node) +{ + //if node is free, execute when OnDetachFromMainTree. +} + +void SwiperPattern::OnAttachToMainTree_MultiThread(FrameNode* node) +{ + CHECK_NULL_VOID(node); + auto renderContext = node->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + auto pipeline = node->GetContext(); + CHECK_NULL_VOID(pipeline); + auto indicatorTheme = pipeline->GetTheme(); + CHECK_NULL_VOID(indicatorTheme); + renderContext->UpdateClipEdge(indicatorTheme->GetClipEdge()); + InitSurfaceChangedCallback(); +} + +void SwiperPattern::OnDetachFromMainTree_MultiThread(FrameNode* node) +{ + CHECK_NULL_VOID(node); + auto pipeline = node->GetContext(); + CHECK_NULL_VOID(pipeline); + if (HasSurfaceChangedCallback()) { + pipeline->UnregisterSurfaceChangedCallback(surfaceChangedCallbackId_.value_or(-1)); + } + pipeline->RemoveWindowStateChangedCallback(node->GetId()); + RemoveOnHiddenChange(); +} +} \ No newline at end of file diff --git a/frameworks/core/interfaces/native/node/node_swiper_modifier.cpp b/frameworks/core/interfaces/native/node/node_swiper_modifier.cpp index 28bd8693af93687a74ecb3e767b7c7bf02ff7725..c4973ddf6970165b63cdf36ca95c7f56989c0d00 100644 --- a/frameworks/core/interfaces/native/node/node_swiper_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_swiper_modifier.cpp @@ -17,6 +17,7 @@ #include "node_model.h" #include "bridge/common/utils/utils.h" +#include "core/components_ng/base/multithread.h" #include "core/components/swiper/swiper_component.h" #include "core/components_ng/pattern/swiper/swiper_model_ng.h" #include "core/interfaces/native/node/node_adapter_impl.h" @@ -641,6 +642,7 @@ void SetSwiperDisplayArrow(ArkUINodeHandle node, ArkUI_CharPtr displayArrowStr) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + FREE_NODE_CHECK(SetSwiperDisplayArrow, frameNode, node, displayArrowStr); std::vector res; std::string displayArrowValues = std::string(displayArrowStr); StringUtils::StringSplitter(displayArrowValues, '|', res); @@ -689,6 +691,7 @@ void ResetSwiperDisplayArrow(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + FREE_NODE_CHECK(ResetSwiperDisplayArrow, frameNode, node); SwiperModelNG::ResetArrowStyle(frameNode); SwiperModelNG::SetDisplayArrow(frameNode, false); } @@ -894,6 +897,7 @@ void SetSwiperIndex(ArkUINodeHandle node, ArkUI_Int32 index, ArkUI_Int32 animati { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + FREE_NODE_CHECK(SetSwiperIndex, frameNode, node, index, animationMode); index = index < 0 ? 0 : index; if (animationMode <= static_cast(SwiperAnimationMode::NO_ANIMATION) || animationMode >= static_cast(ANIMATION_MODE.size())) { @@ -907,6 +911,7 @@ void ResetSwiperIndex(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + FREE_NODE_CHECK(ResetSwiperIndex, frameNode, node); uint32_t value = 0; SwiperModelNG::SetIndex(frameNode, value); } @@ -951,6 +956,7 @@ void ResetSwiperIndicator(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + FREE_NODE_CHECK(frameNode, node); SwiperModelNG::ResetIndicatorStyle(frameNode); SwiperModelNG::SetShowIndicator(frameNode, true); } @@ -959,6 +965,7 @@ void SetSwiperDuration(ArkUINodeHandle node, ArkUI_Float32 duration) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + FREE_NODE_CHECK(SetSwiperDuration, frameNode, node); if (duration < 0) { duration = DEFAULT_DURATION; } @@ -1236,6 +1243,7 @@ void SetSwiperToIndex(ArkUINodeHandle node, ArkUI_Int32 (*values)[2]) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + FREE_NODE_CHECK(SetSwiperToIndex, frameNode, node, values); SwiperModelNG::SetSwiperToIndex(frameNode, (*values)[0], (*values)[1]); } @@ -1273,6 +1281,7 @@ void SetSwiperIndicatorStyle(ArkUINodeHandle node, ArkUISwiperIndicator* indicat CHECK_NULL_VOID(indicator); auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + FREE_NODE_CHECK(SetSwiperIndicatorStyle, frameNode, node, indicator); if (indicator->type == ArkUISwiperIndicatorType::DOT) { SwiperModelNG::SetIndicatorIsBoolean(frameNode, false); SwiperParameters swiperParameters = GetDotIndicatorProps(frameNode, indicator); @@ -1326,6 +1335,7 @@ void SetSwiperDigitIndicatorStyle(ArkUINodeHandle node, ArkUISwiperDigitIndicato CHECK_NULL_VOID(indicator); auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); + FREE_NODE_CHECK(SetSwiperDigitIndicatorStyle, frameNode, node, indicator); if (indicator->type == ArkUISwiperIndicatorType::DIGIT) { SwiperModelNG::SetIndicatorIsBoolean(frameNode, false); SwiperDigitalParameters swiperDigitParameters = GetDigitIndicatorProps(frameNode, indicator); diff --git a/frameworks/core/interfaces/native/node/node_swiper_modifier_multithread.cpp b/frameworks/core/interfaces/native/node/node_swiper_modifier_multithread.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99d80f050056041a1f77c6963816c794fc5f8551 --- /dev/null +++ b/frameworks/core/interfaces/native/node/node_swiper_modifier_multithread.cpp @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2023 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "core/interfaces/native/node/node_swiper_modifier.h" + +#include "node_model.h" + +#include "bridge/common/utils/utils.h" +#include "core/components/swiper/swiper_component.h" +#include "core/components_ng/pattern/swiper/swiper_model_ng.h" +#include "core/interfaces/native/node/node_adapter_impl.h" + +namespace OHOS::Ace::NG { +namespace { +void SetSwiperDisplayArrow_MultiThread(ArkUINodeHandle node, ArkUI_CharPtr displayArrowStr) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + std::vector res; + std::string displayArrowValues = std::string(displayArrowStr); + StringUtils::StringSplitter(displayArrowValues, '|', res); + auto displayArrowTask = [weakNode = AceType::WeakClaim(frameNode), tempRes = std::move(res)]() mutable { + auto node = weakNode.Upgrade(); + CHECK_NULL_VOID(node); + SetSwiperDisplayArrowInner(AceType::RawPtr(node), tempRes); + }; + frameNode->PostAfterAttachMainTreeTask(std::move(displayArrowTask)); +} + +void SetSwiperDisplayArrowInner(FrameNode* frameNode, std::vector& res) +{ + CHECK_NULL_VOID(frameNode); + int32_t displayArrowValue = VectorStringToInt(res, DISPLAY_ARROW_VALUE); + int32_t displayArrowCAPI = VectorStringToInt(res, DISPLAY_ARROW_CAPI); + if (displayArrowValue == DISPLAY_ARROW_OBJECT) { + SwiperArrowParameters swiperArrowParameters; + if (!GetArrowInfo(res, swiperArrowParameters)) { + SwiperModelNG::SetDisplayArrow(frameNode, false); + return; + } + SwiperModelNG::SetArrowStyle(frameNode, swiperArrowParameters); + SwiperModelNG::SetDisplayArrow(frameNode, true); + } else if (displayArrowValue == DISPLAY_ARROW_TRUE) { + if (displayArrowCAPI == 1) { + SwiperArrowParameters swiperArrowParameters; + if (!GetArrowInfo(res, swiperArrowParameters)) { + SwiperModelNG::SetDisplayArrow(frameNode, false); + return; + } + SwiperModelNG::SetArrowStyle(frameNode, swiperArrowParameters); + SwiperModelNG::SetDisplayArrow(frameNode, true); + } else { + auto pipelineContext = frameNode->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto swiperIndicatorTheme = pipelineContext->GetTheme(); + CHECK_NULL_VOID(swiperIndicatorTheme); + SwiperArrowParameters swiperArrowParameters; + InitSwiperArrowParameters(swiperArrowParameters, swiperIndicatorTheme); + SwiperModelNG::SetArrowStyle(frameNode, swiperArrowParameters); + SwiperModelNG::SetDisplayArrow(frameNode, true); + } + } else { + SwiperModelNG::SetDisplayArrow(frameNode, false); + return; + } + int32_t isHoverShow = VectorStringToInt(res, DISPLAY_ARROW_IS_HOVER_SHOW_INDEX); + if (isHoverShow != DISPLAY_ARROW_IS_HOVER_SHOW_UNDEFINED) { + SwiperModelNG::SetHoverShow(frameNode, isHoverShow == 1 ? true : false); + } else { + SwiperModelNG::SetHoverShow(frameNode, false); + } +} + +ResetSwiperDisplayArrow_MultiThread(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + auto resetTask = [weakNode = AceType::WeakClaim(frameNode)]() { + auto node = weakNode.Upgrade(); + CHECK_NULL_VOID(node); + SwiperModelNG::ResetArrowStyle(AceType::RawPtr(node)); + SwiperModelNG::SetDisplayArrow(AceType::RawPtr(node), false); + }; + frameNode->PostAfterAttachMainTreeTask(std::move(resetTask)); +} + +void SetSwiperIndex_MultiThread(ArkUINodeHandle node, ArkUI_Int32 index, ArkUI_Int32 animationMode) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + auto indexTask = [weakNode = AceType::WeakClaim(frameNode), index, animationMode]() { + auto node = weakNode.Upgrade(); + CHECK_NULL_VOID(node); + index = index < 0 ? 0 : index; + if (animationMode <= static_cast(SwiperAnimationMode::NO_ANIMATION) || + animationMode >= static_cast(ANIMATION_MODE.size())) { + SwiperModelNG::SetIndex(frameNode, index); + return; + } + SwiperModelNG::SetSwiperToIndex(frameNode, index, static_cast(animationMode)); + }; + frameNode->PostAfterAttachMainTreeTask(std::move(indexTask)); +} + +void ResetSwiperIndex_MultiThread(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + auto indexTask = [weakNode = AceType::WeakClaim(frameNode)]() { + auto node = weakNode.Upgrade(); + CHECK_NULL_VOID(node); + SwiperModelNG::SetIndex(AceType::RawPtr(node), 0); + }; + frameNode->PostAfterAttachMainTreeTask(std::move(indexTask)); +} + +void SetSwiperIndicator_MultiThread(ArkUINodeHandle node, ArkUI_CharPtr indicatorStr) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + std::vector res; + std::string indicatorValues = std::string(indicatorStr); + StringUtils::StringSplitter(indicatorValues, '|', res); + auto setIndicatorTask = [weakNode = AceType::WeakClaim(frameNode), tempRes = std::move(res)]() mutable { + auto node = weakNode.Upgrade(); + CHECK_NULL_VOID(node); + SetSwiperIndicatorInner(AceType::RawPtr(node), tempRes); + }; + frameNode->PostAfterAttachMainTreeTask(std::move(setIndicatorTask)); +} + +void SetSwiperIndicatorInner(FrameNode* frameNode, std::vector& res) +{ + CHECK_NULL_VOID(frameNode); + std::string type = res[INDICATOR_TYPE_INDEX]; + if (type == "IndicatorComponentController") { + SwiperModelNG::SetBindIndicator(frameNode, true); + return; + } + if (type == "ArkDigitIndicator") { + SwiperModelNG::SetIndicatorIsBoolean(frameNode, false); + SwiperDigitalParameters digitalParameters = GetDigitIndicatorInfo(res); + SwiperModelNG::SetDigitIndicatorStyle(frameNode, digitalParameters); + SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DIGIT); + } else if (type == "ArkDotIndicator") { + SwiperModelNG::SetIndicatorIsBoolean(frameNode, false); + SwiperParameters swiperParameters = GetDotIndicatorInfo(frameNode, res); + SwiperModelNG::SetDotIndicatorStyle(frameNode, swiperParameters); + SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DOT); + } else { + SwiperParameters swiperParameters = GetDotIndicatorInfo(frameNode, res); + SwiperModelNG::SetDotIndicatorStyle(frameNode, swiperParameters); + SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DOT); + } + if (type == "boolean") { + int32_t indicator = StringUtils::StringToInt(res[INDICATOR_VALUE]); + bool showIndicator = indicator == 1 ? true : false; + SwiperModelNG::SetShowIndicator(frameNode, showIndicator); + } else { + SwiperModelNG::SetShowIndicator(frameNode, true); + } +} + +void ResetSwiperIndicator_MultiThread(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + auto setIndicatorTask = [weakNode = AceType::WeakClaim(frameNode)]() { + auto node = weakNode.Upgrade(); + CHECK_NULL_VOID(node); + SwiperModelNG::ResetIndicatorStyle(AceType::RawPtr(node)); + SwiperModelNG::SetShowIndicator(AceType::RawPtr(node), true); + }; + frameNode->PostAfterAttachMainTreeTask(std::move(setIndicatorTask)); +} + +void SetSwiperToIndex_MultiThread(ArkUINodeHandle node, ArkUI_Int32 (*values)[2]) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + auto setToIndexTask = [weakNode = AceType::WeakClaim(frameNode), index = (*values)[0], mode = (*values)[1]]() { + auto node = weakNode.Upgrade(); + CHECK_NULL_VOID(node); + SwiperModelNG::SetSwiperToIndex(AceType::RawPtr(node), index, static_cast(mode)); + }; + frameNode->PostAfterAttachMainTreeTask(std::move(setToIndexTask)); +} + +void SetSwiperIndicatorStyle_MultiThread(ArkUINodeHandle node, ArkUISwiperIndicator* indicator) +{ + CHECK_NULL_VOID(indicator); + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + auto indicatorStyleTask = [weakNode = AceType::WeakClaim(frameNode), indicatorCopy = *indicator]() mutable { + auto node = weakNode.Upgrade(); + CHECK_NULL_VOID(node); + SetSwiperIndicatorSytleInner(AceType::RawPtr(node), &indicatorCopy); + }; + frameNode->PostAfterAttachMainTreeTask(std::move(indicatorStyleTask)); +} + +void SetSwiperIndicatorSytleInner(FrameNode* frameNode, ArkUISwiperIndicator* indicator) +{ + CHECK_NULL_VOID(indicator); + CHECK_NULL_VOID(frameNode); + if (indicator->type == ArkUISwiperIndicatorType::DOT) { + SwiperModelNG::SetIndicatorIsBoolean(frameNode, false); + SwiperParameters swiperParameters = GetDotIndicatorProps(frameNode, indicator); + SwiperModelNG::SetDotIndicatorStyle(frameNode, swiperParameters); + SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DOT); + } + SwiperModelNG::SetShowIndicator(frameNode, true); +} + +void SetSwiperDigitIndicatorStyle_MultiThread(ArkUINodeHandle node, ArkUISwiperDigitIndicator* indicator) +{ + CHECK_NULL_VOID(indicator); + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + auto indicatorStyleTask = [weakNode = AceType::WeakClaim(frameNode), indicatorCopy = *indicator]() mutable { + auto node = weakNode.Upgrade(); + CHECK_NULL_VOID(node); + SetSwiperDigitIndicatorStyleInner(AceType::RawPtr(node), &indicatorCopy); + }; + frameNode->PostAfterAttachMainTreeTask(std::move(indicatorStyleTask)); +} + +void SetSwiperDigitIndicatorStyleInner(FrameNode* frameNode, ArkUISwiperDigitIndicator* indicator) +{ + CHECK_NULL_VOID(indicator); + CHECK_NULL_VOID(frameNode); + if (indicator->type == ArkUISwiperIndicatorType::DIGIT) { + SwiperModelNG::SetIndicatorIsBoolean(frameNode, false); + SwiperDigitalParameters swiperDigitParameters = GetDigitIndicatorProps(frameNode, indicator); + SwiperModelNG::SetDigitIndicatorStyle(frameNode, swiperDigitParameters); + SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DIGIT); + } + SwiperModelNG::SetShowIndicator(frameNode, true); +} +} // namespace OHOS::Ace::NG