Skip to content

Commit 219c2b8

Browse files
Bartlomiej Bloniarzmeta-codesync[bot]
authored andcommitted
Make android frame updates work with AnimationBackend (#54425)
Summary: Pull Request resolved: #54425 Animation frames on Android are tiggered from UIManagerNativeAnimatedDelegate::runAnimationFrame, so we implement that for the backend # Changelog [General] [Added] - UIManagerNativeAnimatedDelegateBackendImpl for running animation frame updates on android Reviewed By: zeyap Differential Revision: D84055754 fbshipit-source-id: 57dcf2aa62daf2f72c266228f2adecc4a0085bff
1 parent 8b95fce commit 219c2b8

4 files changed

Lines changed: 46 additions & 12 deletions

File tree

packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ AnimationMutations NativeAnimatedNodesManager::pullAnimationMutations() {
992992
AnimationMutation{tag, nullptr, propsBuilder.get()});
993993
containsChange = true;
994994
}
995+
updateViewPropsDirect_.clear();
995996
}
996997

997998
if (!containsChange) {

packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManagerProvider.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,27 @@ NativeAnimatedNodesManagerProvider::getOrCreate(
8080
std::move(directManipulationCallback),
8181
std::move(fabricCommitCallback),
8282
uiManager);
83-
#endif
8483

8584
nativeAnimatedNodesManager_ =
8685
std::make_shared<NativeAnimatedNodesManager>(animationBackend_);
8786

87+
nativeAnimatedDelegate_ =
88+
std::make_shared<UIManagerNativeAnimatedDelegateBackendImpl>(
89+
animationBackend_);
90+
8891
uiManager->unstable_setAnimationBackend(animationBackend_);
92+
#endif
8993
} else {
9094
nativeAnimatedNodesManager_ =
9195
std::make_shared<NativeAnimatedNodesManager>(
9296
std::move(directManipulationCallback),
9397
std::move(fabricCommitCallback),
9498
std::move(startOnRenderCallback_),
9599
std::move(stopOnRenderCallback_));
100+
101+
nativeAnimatedDelegate_ =
102+
std::make_shared<UIManagerNativeAnimatedDelegateImpl>(
103+
nativeAnimatedNodesManager_);
96104
}
97105

98106
addEventEmitterListener(
@@ -117,10 +125,6 @@ NativeAnimatedNodesManagerProvider::getOrCreate(
117125
return false;
118126
}));
119127

120-
nativeAnimatedDelegate_ =
121-
std::make_shared<UIManagerNativeAnimatedDelegateImpl>(
122-
nativeAnimatedNodesManager_);
123-
124128
uiManager->setNativeAnimatedDelegate(nativeAnimatedDelegate_);
125129

126130
// TODO: remove force casting.

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010

1111
namespace facebook::react {
1212

13+
UIManagerNativeAnimatedDelegateBackendImpl::
14+
UIManagerNativeAnimatedDelegateBackendImpl(
15+
std::weak_ptr<UIManagerAnimationBackend> animationBackend)
16+
: animationBackend_(std::move(animationBackend)) {}
17+
18+
void UIManagerNativeAnimatedDelegateBackendImpl::runAnimationFrame() {
19+
if (auto animationBackendStrong = animationBackend_.lock()) {
20+
animationBackendStrong->onAnimationFrame(
21+
std::chrono::steady_clock::now().time_since_epoch().count() / 1000);
22+
}
23+
}
24+
1325
static inline Props::Shared cloneProps(
1426
AnimatedProps& animatedProps,
1527
const ShadowNode& shadowNode) {
@@ -108,15 +120,20 @@ void AnimationBackend::onAnimationFrame(double timestamp) {
108120
void AnimationBackend::start(const Callback& callback, bool isAsync) {
109121
callbacks.push_back(callback);
110122
// TODO: startOnRenderCallback_ should provide the timestamp from the platform
111-
startOnRenderCallback_(
112-
[this]() {
113-
onAnimationFrame(
114-
std::chrono::steady_clock::now().time_since_epoch().count() / 1000);
115-
},
116-
isAsync);
123+
if (startOnRenderCallback_) {
124+
startOnRenderCallback_(
125+
[this]() {
126+
onAnimationFrame(
127+
std::chrono::steady_clock::now().time_since_epoch().count() /
128+
1000);
129+
},
130+
isAsync);
131+
}
117132
}
118133
void AnimationBackend::stop(bool isAsync) {
119-
stopOnRenderCallback_(isAsync);
134+
if (stopOnRenderCallback_) {
135+
stopOnRenderCallback_(isAsync);
136+
}
120137
callbacks.clear();
121138
}
122139

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818

1919
namespace facebook::react {
2020

21+
class AnimationBackend;
22+
23+
class UIManagerNativeAnimatedDelegateBackendImpl : public UIManagerNativeAnimatedDelegate {
24+
public:
25+
explicit UIManagerNativeAnimatedDelegateBackendImpl(std::weak_ptr<UIManagerAnimationBackend> animationBackend);
26+
27+
void runAnimationFrame() override;
28+
29+
private:
30+
std::weak_ptr<UIManagerAnimationBackend> animationBackend_;
31+
};
32+
2133
struct AnimationMutation {
2234
Tag tag;
2335
const ShadowNodeFamily *family;

0 commit comments

Comments
 (0)