1 /* 2 * Copyright (c) 2023 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_PATTERNS_TABS_TAB_CONTENT_TRANSITION_PROXY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TAB_CONTENT_TRANSITION_PROXY_H 18 19 #include <functional> 20 #include "base/memory/ace_type.h" 21 #include "base/memory/referenced.h" 22 #include "base/memory/type_info_base.h" 23 24 namespace OHOS::Ace { 25 26 class TabContentTransitionProxy : public AceType { 27 DECLARE_ACE_TYPE(TabContentTransitionProxy, AceType); 28 29 public: GetFromIndex()30 int32_t GetFromIndex() const 31 { 32 return fromIndex_; 33 } SetFromIndex(int32_t fromIndex)34 void SetFromIndex(int32_t fromIndex) 35 { 36 fromIndex_ = fromIndex; 37 } 38 GetToIndex()39 int32_t GetToIndex() const 40 { 41 return toIndex_; 42 } 43 SetToIndex(int32_t toIndex)44 void SetToIndex(int32_t toIndex) 45 { 46 toIndex_ = toIndex; 47 } 48 GetHasFinished()49 bool GetHasFinished() const 50 { 51 return hasFinished_; 52 } 53 SetHasFinished(bool hasFinished)54 void SetHasFinished(bool hasFinished) 55 { 56 hasFinished_ = hasFinished; 57 } 58 GetHasOnChanged()59 bool GetHasOnChanged() const 60 { 61 return hasOnChanged_; 62 } 63 SetHasOnChanged(bool hasOnChanged)64 void SetHasOnChanged(bool hasOnChanged) 65 { 66 hasOnChanged_ = hasOnChanged; 67 } 68 FinishTransition()69 void FinishTransition() 70 { 71 if (finishTransitionEvent_ && !hasFinished_) { 72 hasFinished_ = true; 73 auto event = *finishTransitionEvent_; 74 event(hasOnChanged_); 75 } 76 } 77 SetFinishTransitionEvent(std::function<void (bool)> && event)78 void SetFinishTransitionEvent(std::function<void(bool)>&& event) 79 { 80 if (!finishTransitionEvent_) { 81 finishTransitionEvent_ = std::make_shared<std::function<void(bool)>>(event); 82 } else { 83 (*finishTransitionEvent_).swap(event); 84 } 85 } 86 87 private: 88 int32_t fromIndex_; 89 int32_t toIndex_; 90 bool hasFinished_ = false; 91 bool hasOnChanged_ = false; 92 std::shared_ptr<std::function<void(bool)>> finishTransitionEvent_; 93 }; 94 95 using TransitionFunc = std::function<void(const RefPtr<TabContentTransitionProxy>&)>; 96 struct TabContentAnimatedTransition { 97 int32_t timeout = 0; 98 TransitionFunc transition; 99 }; 100 101 } // namespace OHOS::Ace 102 103 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TAB_CONTENT_TRANSITION_PROXY_H