!48690 Swiper: add CreateIndicatorId function

Merge pull request !48690 from Hu_zq/CreateIndicatorId
This commit is contained in:
openharmony_ci 2024-11-18 02:15:40 +00:00 committed by Gitee
commit 8699ca7261
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 9 additions and 6 deletions

View File

@ -2090,7 +2090,7 @@ void SwiperPattern::InitIndicator()
if (!IsShowIndicator()) {
return;
}
indicatorNode = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG, GetIndicatorId(),
indicatorNode = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG, CreateIndicatorId(),
[]() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
swiperNode->AddChild(indicatorNode);
} else {
@ -2103,7 +2103,7 @@ void SwiperPattern::InitIndicator()
}
if (GetIndicatorType() == SwiperIndicatorType::DIGIT && lastSwiperIndicatorType_ == SwiperIndicatorType::DOT) {
RemoveIndicatorNode();
indicatorNode = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG, GetIndicatorId(),
indicatorNode = FrameNode::GetOrCreateFrameNode(V2::SWIPER_INDICATOR_ETS_TAG, CreateIndicatorId(),
[]() { return AceType::MakeRefPtr<SwiperIndicatorPattern>(); });
swiperNode->AddChild(indicatorNode);
}

View File

@ -310,14 +310,17 @@ public:
return rightButtonId_.has_value();
}
int32_t GetIndicatorId()
int32_t CreateIndicatorId()
{
if (!indicatorId_.has_value()) {
indicatorId_ = ElementRegister::GetInstance()->MakeUniqueId();
}
indicatorId_ = ElementRegister::GetInstance()->MakeUniqueId();
return indicatorId_.value();
}
int32_t GetIndicatorId() const
{
return indicatorId_.has_value() ? indicatorId_.value() : -1;
}
int32_t GetLeftButtonId()
{
if (!leftButtonId_.has_value()) {