1 /*
2 * Copyright (c) 2021-2023 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 "animation/rs_animation_callback.h"
17 #include "rs_trace.h"
18
19 namespace OHOS {
20 namespace Rosen {
AnimationCallback(const std::function<void ()> && callback)21 AnimationCallback::AnimationCallback(const std::function<void()>&& callback) : callback_(std::move(callback))
22 {
23 RS_TRACE_NAME_FMT("AnimationCallback %zu", std::hash<AnimationCallback*>()(this));
24 }
25
~AnimationCallback()26 AnimationCallback::~AnimationCallback()
27 {
28 RS_TRACE_NAME_FMT("~AnimationCallback %zu", std::hash<AnimationCallback*>()(this));
29 if (callback_ != nullptr) {
30 callback_();
31 }
32 }
33
AnimationFinishCallback(std::function<void ()> callback,Rosen::FinishCallbackType finishCallbackType)34 AnimationFinishCallback::AnimationFinishCallback(
35 std::function<void()> callback, Rosen::FinishCallbackType finishCallbackType)
36 : AnimationCallback(std::move(callback)), finishCallbackType_(finishCallbackType)
37 {}
38
IsValid()39 bool AnimationFinishCallback::IsValid()
40 {
41 return callback_ != nullptr;
42 }
43
Execute()44 void AnimationFinishCallback::Execute()
45 {
46 if (callback_ != nullptr) {
47 callback_();
48 // avoid callback_ being called repeatedly.
49 callback_ = nullptr;
50 }
51 }
52
Execute()53 void AnimationRepeatCallback::Execute()
54 {
55 if (callback_ != nullptr) {
56 callback_();
57 }
58 }
59
InteractiveAnimatorFinishCallback(std::function<void ()> callback)60 InteractiveAnimatorFinishCallback::InteractiveAnimatorFinishCallback(
61 std::function<void()> callback) : AnimationCallback(std::move(callback))
62 {}
63 } // namespace Rosen
64 } // namespace OHOS
65