• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_STAGE_PAGE_TRANSITION_EFFECT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_STAGE_PAGE_TRANSITION_EFFECT_H
18 
19 #include <memory>
20 #include <optional>
21 
22 #include "core/animation/page_transition_common.h"
23 #include "core/components_ng/property/transition_property.h"
24 
25 namespace OHOS::Ace::NG {
26 using PageTransitionEventFunc = std::function<void(RouteType, const float&)>;
27 
28 class PageTransitionEffect : public AceType {
29     DECLARE_ACE_TYPE(PageTransitionEffect, AceType);
30 
31 public:
PageTransitionEffect(PageTransitionType type,const PageTransitionOption & option)32     PageTransitionEffect(PageTransitionType type, const PageTransitionOption& option)
33         : animationOption_(option), type_(type)
34     {}
35     ~PageTransitionEffect() override = default;
36 
SetPageTransitionOption(const PageTransitionOption & animationOption)37     void SetPageTransitionOption(const PageTransitionOption& animationOption)
38     {
39         animationOption_ = animationOption;
40     }
41 
SetTranslateEffect(const TranslateOptions & translate)42     void SetTranslateEffect(const TranslateOptions& translate)
43     {
44         translate_ = translate;
45     }
46 
GetTranslateEffect()47     const std::optional<TranslateOptions>& GetTranslateEffect() const
48     {
49         return translate_;
50     }
51 
SetSlideEffect(const SlideEffect & slide)52     void SetSlideEffect(const SlideEffect& slide)
53     {
54         slide_ = slide;
55     }
56 
SetUserCallback(PageTransitionEventFunc && callback)57     void SetUserCallback(PageTransitionEventFunc&& callback)
58     {
59         userCallback_ = callback;
60     }
61 
GetSlideEffect()62     const std::optional<SlideEffect>& GetSlideEffect() const
63     {
64         return slide_;
65     }
66 
SetScaleEffect(const ScaleOptions & scale)67     void SetScaleEffect(const ScaleOptions& scale)
68     {
69         scale_ = scale;
70     }
71 
GetScaleEffect()72     const std::optional<ScaleOptions>& GetScaleEffect() const
73     {
74         return scale_;
75     }
76 
SetOpacityEffect(float opacity)77     void SetOpacityEffect(float opacity)
78     {
79         opacity_ = opacity;
80     }
81 
GetOpacityEffect()82     const std::optional<float>& GetOpacityEffect() const
83     {
84         return opacity_;
85     }
86 
87     // test whether this effect can match the pageTransitionType
CanFit(PageTransitionType type)88     bool CanFit(PageTransitionType type) const
89     {
90         switch (type) {
91             case PageTransitionType::ENTER_PUSH:
92                 return type_ == PageTransitionType::ENTER && animationOption_.routeType != RouteType::POP;
93             case PageTransitionType::ENTER_POP:
94                 return type_ == PageTransitionType::ENTER && animationOption_.routeType != RouteType::PUSH;
95             case PageTransitionType::EXIT_PUSH:
96                 return type_ == PageTransitionType::EXIT && animationOption_.routeType != RouteType::POP;
97             case PageTransitionType::EXIT_POP:
98                 return type_ == PageTransitionType::EXIT && animationOption_.routeType != RouteType::PUSH;
99             default:
100                 return false;
101         }
102     }
103 
GetDuration()104     int32_t GetDuration() const
105     {
106         return animationOption_.duration;
107     }
108 
GetDelay()109     int32_t GetDelay() const
110     {
111         return animationOption_.delay;
112     }
113 
GetCurve()114     const RefPtr<Curve>& GetCurve() const
115     {
116         return animationOption_.curve;
117     }
118 
GetUserCallback()119     const PageTransitionEventFunc& GetUserCallback() const
120     {
121         return userCallback_;
122     }
123 
GetPageTransitionType()124     PageTransitionType GetPageTransitionType() const
125     {
126         return type_;
127     }
128 
GetPageTransitionOption()129     PageTransitionOption GetPageTransitionOption() const
130     {
131         return animationOption_;
132     }
133 
134 private:
135     std::optional<TranslateOptions> translate_;
136     std::optional<ScaleOptions> scale_;
137     std::optional<SlideEffect> slide_;
138     std::optional<float> opacity_;
139     PageTransitionOption animationOption_;
140     // user defined onEnter or onExit callback;
141     PageTransitionEventFunc userCallback_;
142     PageTransitionType type_ = PageTransitionType::ENTER;
143 };
144 } // namespace OHOS::Ace::NG
145 
146 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_STAGE_PAGE_TRANSITION_EFFECT_H
147