mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a812cac176
commit
8d6098a645
+3
-1
@@ -190,6 +190,8 @@ public class FabricUIManager
|
||||
|
||||
private boolean mDriveCxxAnimations = false;
|
||||
|
||||
private boolean mDriveCxxNativeAnimated = ReactNativeFeatureFlags.cxxNativeAnimatedEnabled();
|
||||
|
||||
private long mDispatchViewUpdatesTime = 0l;
|
||||
private long mCommitStartTime = 0l;
|
||||
private long mLayoutTime = 0l;
|
||||
@@ -1373,7 +1375,7 @@ public class FabricUIManager
|
||||
// There is a race condition here between getting/setting
|
||||
// `mDriveCxxAnimations` which shouldn't matter; it's safe to call
|
||||
// the mBinding method, unless mBinding has gone away.
|
||||
if (mDriveCxxAnimations && mBinding != null) {
|
||||
if ((mDriveCxxAnimations || mDriveCxxNativeAnimated) && mBinding != null) {
|
||||
mBinding.driveCxxAnimations();
|
||||
}
|
||||
|
||||
|
||||
@@ -664,6 +664,11 @@ void UIManager::stopSurfaceForAnimationDelegate(SurfaceId surfaceId) const {
|
||||
}
|
||||
}
|
||||
|
||||
void UIManager::setNativeAnimatedDelegate(
|
||||
std::weak_ptr<UIManagerNativeAnimatedDelegate> delegate) {
|
||||
nativeAnimatedDelegate_ = delegate;
|
||||
}
|
||||
|
||||
void UIManager::animationTick() const {
|
||||
if (animationDelegate_ != nullptr &&
|
||||
animationDelegate_->shouldAnimateFrame()) {
|
||||
@@ -671,6 +676,10 @@ void UIManager::animationTick() const {
|
||||
shadowTree.notifyDelegatesOfUpdates();
|
||||
});
|
||||
}
|
||||
|
||||
if (auto nativeAnimatedDelegate = nativeAnimatedDelegate_.lock()) {
|
||||
nativeAnimatedDelegate->runAnimationFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void UIManager::synchronouslyUpdateViewOnUIThread(
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <react/renderer/mounting/ShadowTreeRegistry.h>
|
||||
#include <react/renderer/uimanager/UIManagerAnimationDelegate.h>
|
||||
#include <react/renderer/uimanager/UIManagerDelegate.h>
|
||||
#include <react/renderer/uimanager/UIManagerNativeAnimatedDelegate.h>
|
||||
#include <react/renderer/uimanager/consistency/LazyShadowTreeRevisionConsistencyManager.h>
|
||||
#include <react/renderer/uimanager/consistency/ShadowTreeRevisionProvider.h>
|
||||
#include <react/renderer/uimanager/primitives.h>
|
||||
@@ -67,6 +68,9 @@ class UIManager final : public ShadowTreeDelegate {
|
||||
*/
|
||||
void stopSurfaceForAnimationDelegate(SurfaceId surfaceId) const;
|
||||
|
||||
void setNativeAnimatedDelegate(
|
||||
std::weak_ptr<UIManagerNativeAnimatedDelegate> delegate);
|
||||
|
||||
void animationTick() const;
|
||||
|
||||
void synchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic& props);
|
||||
@@ -192,9 +196,9 @@ class UIManager final : public ShadowTreeDelegate {
|
||||
|
||||
/*
|
||||
* Iterates over all shadow nodes which are parts of all registered surfaces
|
||||
* and find the one that has given `tag`. Returns `nullptr` if the node wasn't
|
||||
* found. This is a temporary workaround that should not be used in any core
|
||||
* functionality.
|
||||
* and find the one that has given `tag`. Returns `nullptr` if the node
|
||||
* wasn't found. This is a temporary workaround that should not be used in
|
||||
* any core functionality.
|
||||
*/
|
||||
ShadowNode::Shared findShadowNodeByTag_DEPRECATED(Tag tag) const;
|
||||
|
||||
@@ -234,6 +238,8 @@ class UIManager final : public ShadowTreeDelegate {
|
||||
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
|
||||
UIManagerDelegate* delegate_{};
|
||||
UIManagerAnimationDelegate* animationDelegate_{nullptr};
|
||||
std::weak_ptr<UIManagerNativeAnimatedDelegate> nativeAnimatedDelegate_;
|
||||
|
||||
const RuntimeExecutor runtimeExecutor_{};
|
||||
ShadowTreeRegistry shadowTreeRegistry_{};
|
||||
ContextContainer::Shared contextContainer_;
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 <jsi/jsi.h>
|
||||
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
|
||||
#include <react/renderer/core/RawValue.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
class UIManagerNativeAnimatedDelegate {
|
||||
public:
|
||||
virtual ~UIManagerNativeAnimatedDelegate() = default;
|
||||
|
||||
virtual void runAnimationFrame() = 0;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
Reference in New Issue
Block a user