1 /*
2  * Copyright (c) 2021 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 "core/components/shared_transition/shared_transition_component.h"
17 
18 #include "core/components/shared_transition/shared_transition_element.h"
19 
20 namespace OHOS::Ace {
21 
SharedTransitionComponent(const ComposeId & id,const std::string & name,ShareId shareId)22 SharedTransitionComponent::SharedTransitionComponent(const ComposeId& id, const std::string& name, ShareId shareId)
23     : ComposedComponent(id, name), shareId_(std::move(shareId))
24 {
25     InitEnableStatus();
26 }
27 
SetOption(const TweenOption & option)28 void SharedTransitionComponent::SetOption(const TweenOption& option)
29 {
30     option_ = option;
31 }
32 
GetOption() const33 const TweenOption& SharedTransitionComponent::GetOption() const
34 {
35     return option_;
36 }
37 
GetShareId() const38 const ShareId& SharedTransitionComponent::GetShareId() const
39 {
40     return shareId_;
41 }
42 
CreateElement()43 RefPtr<Element> SharedTransitionComponent::CreateElement()
44 {
45     return AceType::MakeRefPtr<SharedTransitionElement>(GetId());
46 }
47 
SetEffect(RefPtr<SharedTransitionEffect> & effect)48 void SharedTransitionComponent::SetEffect(RefPtr<SharedTransitionEffect>& effect)
49 {
50     if (effect) {
51         effect_ = effect;
52     } else {
53         effect_ = SharedTransitionEffect::GetSharedTransitionEffect(
54             SharedTransitionEffectType::SHARED_EFFECT_EXCHANGE, shareId_);
55     }
56 }
57 
GetEffect() const58 const RefPtr<SharedTransitionEffect>& SharedTransitionComponent::GetEffect() const
59 {
60     return effect_;
61 }
62 
InitEnableStatus()63 void SharedTransitionComponent::InitEnableStatus()
64 {
65     // In the watch scene, drag to return to the previous page, and disable shared element transitions
66     if (SystemProperties::GetDeviceType() == DeviceType::WATCH) {
67         enablePopEnter_ = false;
68         enablePopExit_ = false;
69     }
70 }
71 
IsEnablePopEnter() const72 bool SharedTransitionComponent::IsEnablePopEnter() const
73 {
74     return enablePopEnter_;
75 }
76 
SetEnablePopEnter(bool enablePopEnter)77 void SharedTransitionComponent::SetEnablePopEnter(bool enablePopEnter)
78 {
79     enablePopEnter_ = enablePopEnter;
80 }
81 
IsEnablePushEnter() const82 bool SharedTransitionComponent::IsEnablePushEnter() const
83 {
84     return enablePushEnter_;
85 }
86 
SetEnablePushEnter(bool enablePushEnter)87 void SharedTransitionComponent::SetEnablePushEnter(bool enablePushEnter)
88 {
89     enablePushEnter_ = enablePushEnter;
90 }
91 
IsEnablePopExit() const92 bool SharedTransitionComponent::IsEnablePopExit() const
93 {
94     return enablePopExit_;
95 }
96 
SetEnablePopExit(bool enablePopExit)97 void SharedTransitionComponent::SetEnablePopExit(bool enablePopExit)
98 {
99     enablePopExit_ = enablePopExit;
100 }
101 
IsEnablePushExit() const102 bool SharedTransitionComponent::IsEnablePushExit() const
103 {
104     return enablePushExit_;
105 }
106 
SetEnablePushExit(bool enablePushExit)107 void SharedTransitionComponent::SetEnablePushExit(bool enablePushExit)
108 {
109     enablePushExit_ = enablePushExit;
110 }
111 
SetShareId(const ShareId & shareId)112 void SharedTransitionComponent::SetShareId(const ShareId& shareId)
113 {
114     shareId_ = shareId;
115 }
116 
SetOpacity(float opacity)117 void SharedTransitionComponent::SetOpacity(float opacity)
118 {
119     opacity_ = opacity;
120 }
121 
GetOpacity() const122 float SharedTransitionComponent::GetOpacity() const
123 {
124     return opacity_;
125 }
126 
SetZIndex(int32_t index)127 void SharedTransitionComponent::SetZIndex(int32_t index)
128 {
129     zIndex_ = index;
130 }
131 
GetZIndex() const132 int32_t SharedTransitionComponent::GetZIndex() const
133 {
134     return zIndex_;
135 }
136 
137 } // namespace OHOS::Ace