1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_INDICATOR_CONTROLLER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_INDICATOR_CONTROLLER_H 18 19 #include "core/components_ng/pattern/swiper/swiper_pattern.h" 20 21 namespace OHOS::Ace::NG { 22 using CommonFunc = std::function<void()>; 23 using ChangeIndexImpl = std::function<void(const int32_t, bool)>; 24 25 class IndicatorController : public virtual AceType { 26 DECLARE_ACE_TYPE(IndicatorController, AceType); 27 28 public: ShowPrevious()29 void ShowPrevious() const 30 { 31 if (showPrevImpl_) { 32 showPrevImpl_(); 33 } 34 } 35 SetShowPrevImpl(const CommonFunc & showPrevImpl)36 void SetShowPrevImpl(const CommonFunc& showPrevImpl) 37 { 38 showPrevImpl_ = showPrevImpl; 39 } 40 ShowNext()41 void ShowNext() const 42 { 43 if (showNextImpl_) { 44 showNextImpl_(); 45 } 46 } 47 SetShowNextImpl(const CommonFunc & showNextImpl)48 void SetShowNextImpl(const CommonFunc& showNextImpl) 49 { 50 showNextImpl_ = showNextImpl; 51 } 52 ChangeIndex(int32_t index,bool useAnimation)53 void ChangeIndex(int32_t index, bool useAnimation) 54 { 55 if (changeIndexImpl_) { 56 changeIndexImpl_(index, useAnimation); 57 } 58 } 59 SetChangeIndexImpl(const ChangeIndexImpl & changeIndexImpl)60 void SetChangeIndexImpl(const ChangeIndexImpl& changeIndexImpl) 61 { 62 changeIndexImpl_ = changeIndexImpl; 63 } 64 SetSwiperNode(const WeakPtr<NG::UINode> & swiperNode,const WeakPtr<NG::UINode> & indicatorNode)65 void SetSwiperNode(const WeakPtr<NG::UINode>& swiperNode, const WeakPtr<NG::UINode>& indicatorNode) 66 { 67 swiperNode_ = swiperNode; 68 auto refUINode = swiperNode_.Upgrade(); 69 CHECK_NULL_VOID(refUINode); 70 auto frameNode = DynamicCast<NG::FrameNode>(refUINode); 71 CHECK_NULL_VOID(frameNode); 72 auto pattern = frameNode->GetPattern<NG::SwiperPattern>(); 73 CHECK_NULL_VOID(pattern); 74 pattern->SetIndicatorNode(indicatorNode); 75 } 76 GetSwiperNode()77 const WeakPtr<NG::UINode>& GetSwiperNode() const 78 { 79 return swiperNode_; 80 } 81 ResetSwiperNode()82 void ResetSwiperNode() 83 { 84 swiperNode_ = nullptr; 85 } 86 private: 87 CommonFunc showPrevImpl_; 88 CommonFunc showNextImpl_; 89 ChangeIndexImpl changeIndexImpl_; 90 WeakPtr<NG::UINode> swiperNode_; 91 }; 92 93 } // namespace OHOS::Ace 94 95 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SWIPER_SWIPER_CONTROLLER_H 96