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