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 %p", this);
24 }
25
~AnimationCallback()26 AnimationCallback::~AnimationCallback()
27 {
28 RS_TRACE_NAME_FMT("~AnimationCallback %p", 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
Execute()39 void AnimationFinishCallback::Execute()
40 {
41 if (callback_ != nullptr) {
42 callback_();
43 // avoid callback_ being called repeatedly.
44 callback_ = nullptr;
45 }
46 }
47
Execute()48 void AnimationRepeatCallback::Execute()
49 {
50 if (callback_ != nullptr) {
51 callback_();
52 }
53 }
54
InteractiveAnimatorFinishCallback(std::function<void ()> callback)55 InteractiveAnimatorFinishCallback::InteractiveAnimatorFinishCallback(
56 std::function<void()> callback) : AnimationCallback(std::move(callback))
57 {}
58 } // namespace Rosen
59 } // namespace OHOS
60