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_PATTERNS_SWIPER_SWIPER_CONTENT_TRANSITION_PROXY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_SWIPER_CONTENT_TRANSITION_PROXY_H
18 
19 #include <cstdint>
20 #include <functional>
21 
22 #include "base/memory/ace_type.h"
23 #include "base/memory/referenced.h"
24 #include "base/memory/type_info_base.h"
25 
26 namespace OHOS::Ace {
27 
28 class SwiperContentTransitionProxy : public AceType {
29     DECLARE_ACE_TYPE(SwiperContentTransitionProxy, AceType);
30 
31 public:
GetSelectedIndex()32     int32_t GetSelectedIndex() const
33     {
34         return selectedIndex_;
35     }
36 
SetSelectedIndex(int32_t selectedIndex)37     void SetSelectedIndex(int32_t selectedIndex)
38     {
39         selectedIndex_ = selectedIndex;
40     }
41 
GetIndex()42     int32_t GetIndex() const
43     {
44         return index_;
45     }
46 
SetIndex(int32_t index)47     void SetIndex(int32_t index)
48     {
49         index_ = index;
50     }
51 
GetPosition()52     float GetPosition() const
53     {
54         return position_;
55     }
56 
SetPosition(float position)57     void SetPosition(float position)
58     {
59         position_ = position;
60     }
61 
GetMainAxisLength()62     float GetMainAxisLength() const
63     {
64         return mainAxisLength_;
65     }
66 
SetMainAxisLength(float mainAxisLength)67     void SetMainAxisLength(float mainAxisLength)
68     {
69         mainAxisLength_ = mainAxisLength;
70     }
71 
FinishTransition()72     void FinishTransition()
73     {
74         if (finishTransitionEvent_) {
75             auto event = *finishTransitionEvent_;
76             event();
77         }
78     }
79 
SetFinishTransitionEvent(std::function<void ()> && event)80     void SetFinishTransitionEvent(std::function<void()>&& event)
81     {
82         if (!finishTransitionEvent_) {
83             finishTransitionEvent_ = std::make_shared<std::function<void()>>(event);
84         } else {
85             (*finishTransitionEvent_).swap(event);
86         }
87     }
88 
89 private:
90     int32_t selectedIndex_ = 0;
91     int32_t index_ = 0;
92     float position_ = 0.0f;
93     float mainAxisLength_ = 0.0f;
94     std::shared_ptr<std::function<void()>> finishTransitionEvent_;
95 };
96 
97 struct SwiperContentAnimatedTransition {
98     int32_t timeout = 0;
99     std::function<void(const RefPtr<SwiperContentTransitionProxy>&)> transition;
100 };
101 
102 } // namespace OHOS::Ace
103 
104 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SWIPER_SWIPER_CONTENT_TRANSITION_PROXY_H