Skip to content

Commit 8d6098a

Browse files
zeyapfacebook-github-bot
authored andcommitted
create UIManagerNativeAnimatedDelegate to drive per frame NativeAnimated update
Summary: ## Changelog: [Android] [Added] - create UIManagerNativeAnimatedDelegate to potentially drive per frame NativeAnimated update * I'm imitating the way LayoutAnimation kicks off (`UIManagerAnimationDelegate`); re-using `UIManager::animationTick` function to schedule per frame animation callback Reviewed By: rshest Differential Revision: D71419497 fbshipit-source-id: ba867e4c2ed2ad89a7c9229c1156e20aca45e0e9
1 parent a812cac commit 8d6098a

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ public class FabricUIManager
190190

191191
private boolean mDriveCxxAnimations = false;
192192

193+
private boolean mDriveCxxNativeAnimated = ReactNativeFeatureFlags.cxxNativeAnimatedEnabled();
194+
193195
private long mDispatchViewUpdatesTime = 0l;
194196
private long mCommitStartTime = 0l;
195197
private long mLayoutTime = 0l;
@@ -1373,7 +1375,7 @@ public void doFrameGuarded(long frameTimeNanos) {
13731375
// There is a race condition here between getting/setting
13741376
// `mDriveCxxAnimations` which shouldn't matter; it's safe to call
13751377
// the mBinding method, unless mBinding has gone away.
1376-
if (mDriveCxxAnimations && mBinding != null) {
1378+
if ((mDriveCxxAnimations || mDriveCxxNativeAnimated) && mBinding != null) {
13771379
mBinding.driveCxxAnimations();
13781380
}
13791381

packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,13 +664,22 @@ void UIManager::stopSurfaceForAnimationDelegate(SurfaceId surfaceId) const {
664664
}
665665
}
666666

667+
void UIManager::setNativeAnimatedDelegate(
668+
std::weak_ptr<UIManagerNativeAnimatedDelegate> delegate) {
669+
nativeAnimatedDelegate_ = delegate;
670+
}
671+
667672
void UIManager::animationTick() const {
668673
if (animationDelegate_ != nullptr &&
669674
animationDelegate_->shouldAnimateFrame()) {
670675
shadowTreeRegistry_.enumerate([](const ShadowTree& shadowTree, bool&) {
671676
shadowTree.notifyDelegatesOfUpdates();
672677
});
673678
}
679+
680+
if (auto nativeAnimatedDelegate = nativeAnimatedDelegate_.lock()) {
681+
nativeAnimatedDelegate->runAnimationFrame();
682+
}
674683
}
675684

676685
void UIManager::synchronouslyUpdateViewOnUIThread(

packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <react/renderer/mounting/ShadowTreeRegistry.h>
2626
#include <react/renderer/uimanager/UIManagerAnimationDelegate.h>
2727
#include <react/renderer/uimanager/UIManagerDelegate.h>
28+
#include <react/renderer/uimanager/UIManagerNativeAnimatedDelegate.h>
2829
#include <react/renderer/uimanager/consistency/LazyShadowTreeRevisionConsistencyManager.h>
2930
#include <react/renderer/uimanager/consistency/ShadowTreeRevisionProvider.h>
3031
#include <react/renderer/uimanager/primitives.h>
@@ -67,6 +68,9 @@ class UIManager final : public ShadowTreeDelegate {
6768
*/
6869
void stopSurfaceForAnimationDelegate(SurfaceId surfaceId) const;
6970

71+
void setNativeAnimatedDelegate(
72+
std::weak_ptr<UIManagerNativeAnimatedDelegate> delegate);
73+
7074
void animationTick() const;
7175

7276
void synchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic& props);
@@ -192,9 +196,9 @@ class UIManager final : public ShadowTreeDelegate {
192196

193197
/*
194198
* Iterates over all shadow nodes which are parts of all registered surfaces
195-
* and find the one that has given `tag`. Returns `nullptr` if the node wasn't
196-
* found. This is a temporary workaround that should not be used in any core
197-
* functionality.
199+
* and find the one that has given `tag`. Returns `nullptr` if the node
200+
* wasn't found. This is a temporary workaround that should not be used in
201+
* any core functionality.
198202
*/
199203
ShadowNode::Shared findShadowNodeByTag_DEPRECATED(Tag tag) const;
200204

@@ -234,6 +238,8 @@ class UIManager final : public ShadowTreeDelegate {
234238
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
235239
UIManagerDelegate* delegate_{};
236240
UIManagerAnimationDelegate* animationDelegate_{nullptr};
241+
std::weak_ptr<UIManagerNativeAnimatedDelegate> nativeAnimatedDelegate_;
242+
237243
const RuntimeExecutor runtimeExecutor_{};
238244
ShadowTreeRegistry shadowTreeRegistry_{};
239245
ContextContainer::Shared contextContainer_;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <jsi/jsi.h>
11+
12+
#include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
13+
#include <react/renderer/core/RawValue.h>
14+
15+
namespace facebook::react {
16+
17+
class UIManagerNativeAnimatedDelegate {
18+
public:
19+
virtual ~UIManagerNativeAnimatedDelegate() = default;
20+
21+
virtual void runAnimationFrame() = 0;
22+
};
23+
24+
} // namespace facebook::react

0 commit comments

Comments
 (0)