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 #include "frameworks/bridge/declarative_frontend/jsview/models/page_transition_model_impl.h"
17
18 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
19 #include "frameworks/core/components/page_transition/page_transition_info.h"
20
21 namespace OHOS::Ace::Framework {
SetSlideEffect(SlideEffect effect)22 void PageTransitionModelImpl::SetSlideEffect(SlideEffect effect)
23 {
24 const auto& pageTransition = GetPageTransition();
25 if (pageTransition) {
26 pageTransition->SetEffect(effect);
27 }
28 }
29
SetTranslateEffect(const NG::TranslateOptions & option)30 void PageTransitionModelImpl::SetTranslateEffect(const NG::TranslateOptions &option)
31 {
32 const auto& pageTransition = GetPageTransition();
33 if (pageTransition) {
34 pageTransition->AddTranslateAnimation(option.x, option.y, option.z);
35 }
36 }
37
SetScaleEffect(const NG::ScaleOptions & option)38 void PageTransitionModelImpl::SetScaleEffect(const NG::ScaleOptions &option)
39 {
40 const auto& pageTransition = GetPageTransition();
41 if (pageTransition) {
42 pageTransition->AddScaleAnimation(option.xScale, option.yScale, option.zScale, option.centerX, option.centerY);
43 }
44 }
45
SetOpacityEffect(float opacity)46 void PageTransitionModelImpl::SetOpacityEffect(float opacity)
47 {
48 const auto& pageTransition = GetPageTransition();
49 if (pageTransition) {
50 pageTransition->AddOpacityAnimation(opacity);
51 }
52 }
53
SetOnEnter(PageTransitionEventFunc && handler)54 void PageTransitionModelImpl::SetOnEnter(PageTransitionEventFunc&& handler)
55 {
56 const auto& pageTransition = GetPageTransition();
57 if (pageTransition) {
58 pageTransition->SetOnEnterHandler(std::move(handler));
59 }
60 }
61
SetOnExit(PageTransitionEventFunc && handler)62 void PageTransitionModelImpl::SetOnExit(PageTransitionEventFunc&& handler)
63 {
64 const auto& pageTransition = GetPageTransition();
65 if (pageTransition) {
66 pageTransition->SetOnExitHandler(std::move(handler));
67 }
68 }
69
Create()70 void PageTransitionModelImpl::Create()
71 {
72 // create PageTransitionComponent
73 auto pageTransitionComponent = ViewStackProcessor::GetInstance()->GetPageTransitionComponent();
74 if (pageTransitionComponent) {
75 pageTransitionComponent->ClearPageTransition();
76 }
77 }
78
Pop()79 void PageTransitionModelImpl::Pop()
80 {
81 auto pageTransitionComponent = ViewStackProcessor::GetInstance()->GetPageTransitionComponent();
82 if (pageTransitionComponent) {
83 pageTransitionComponent->ClearPageTransitionStack();
84 }
85 }
86
GetPageTransition()87 RefPtr<PageTransition> PageTransitionModelImpl::GetPageTransition()
88 {
89 auto pageTransitionComponent = ViewStackProcessor::GetInstance()->GetPageTransitionComponent();
90 if (pageTransitionComponent) {
91 return pageTransitionComponent->GetTopPageTransition();
92 }
93 return nullptr;
94 }
95
CreateTransition(PageTransitionType type,const PageTransitionOption & option)96 void PageTransitionModelImpl::CreateTransition(PageTransitionType type, const PageTransitionOption& option)
97 {
98 RefPtr<PageTransition> pageTransitionInfo = AceType::MakeRefPtr<PageTransition>(type);
99 pageTransitionInfo->SetDuration(option.duration);
100 pageTransitionInfo->SetDelay(option.delay);
101 pageTransitionInfo->SetCurve(option.curve);
102 pageTransitionInfo->SetRouteType(option.routeType);
103
104 auto pageTransitionComponent = ViewStackProcessor::GetInstance()->GetPageTransitionComponent();
105 if (pageTransitionComponent) {
106 pageTransitionComponent->PushPageTransition(pageTransitionInfo);
107 }
108 }
109 } // namespace OHOS::Ace::Framework