-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Expand file tree
/
Copy pathAnimationBackend.h
More file actions
77 lines (64 loc) · 2.56 KB
/
AnimationBackend.h
File metadata and controls
77 lines (64 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <ReactCommon/CallInvoker.h>
#include <folly/dynamic.h>
#include <react/renderer/core/ReactPrimitives.h>
#include <react/renderer/uimanager/UIManager.h>
#include <react/renderer/uimanager/UIManagerAnimationBackend.h>
#include <functional>
#include <memory>
#include <set>
#include <vector>
#include "AnimatedProps.h"
#include "AnimatedPropsBuilder.h"
#include "AnimatedPropsRegistry.h"
#include "AnimationBackendCommitHook.h"
namespace facebook::react {
class AnimationBackend;
class UIManagerNativeAnimatedDelegateBackendImpl : public UIManagerNativeAnimatedDelegate {
public:
explicit UIManagerNativeAnimatedDelegateBackendImpl(std::weak_ptr<UIManagerAnimationBackend> animationBackend);
void runAnimationFrame() override;
private:
std::weak_ptr<UIManagerAnimationBackend> animationBackend_;
};
struct AnimationMutation {
Tag tag;
std::shared_ptr<const ShadowNodeFamily> family;
AnimatedProps props;
bool hasLayoutUpdates{false};
};
struct AnimationMutations {
std::vector<AnimationMutation> batch;
std::set<SurfaceId> asyncFlushSurfaces;
};
class AnimationBackend : public UIManagerAnimationBackend {
public:
using Callback = std::function<AnimationMutations(float)>;
using ResumeCallback = std::function<void()>;
using PauseCallback = std::function<void()>;
using DirectManipulationCallback = std::function<void(Tag, const folly::dynamic &)>;
std::vector<Callback> callbacks;
const DirectManipulationCallback directManipulationCallback_;
std::shared_ptr<AnimatedPropsRegistry> animatedPropsRegistry_;
std::shared_ptr<UIManager> uiManager_;
std::shared_ptr<CallInvoker> jsInvoker_;
AnimationBackendCommitHook commitHook_;
bool isRenderCallbackStarted_{false};
AnimationBackend(DirectManipulationCallback &&directManipulationCallback, std::shared_ptr<UIManager> uiManager);
void commitUpdates(SurfaceId surfaceId, SurfaceUpdates &surfaceUpdates);
void synchronouslyUpdateProps(const std::unordered_map<Tag, AnimatedProps> &updates);
void requestAsyncFlushForSurfaces(const std::set<SurfaceId> &surfaces);
void clearRegistry(SurfaceId surfaceId) override;
void registerJSInvoker(std::shared_ptr<CallInvoker> jsInvoker) override;
void onAnimationFrame(double timestamp) override;
void trigger() override;
void start(const Callback &callback, bool isAsync) override;
void stop(bool isAsync) override;
};
} // namespace facebook::react