Skip to content

Commit 9f6fea4

Browse files
Bartlomiej Bloniarzfacebook-github-bot
authored andcommitted
Add scaffolding for batched animated prop updates delegate chain
Summary: Introduces the cross-platform delegate chain for batched animated property updates without any platform implementation: - Adds `schedulerShouldSynchronouslyUpdateAnimatedPropsOnUIThread` to `SchedulerDelegate` and forwards from `Scheduler`. - Adds `uiManagerShouldSynchronouslyUpdateAnimatedPropsOnUIThread` to `UIManagerDelegate` and `synchronouslyUpdateAnimatedPropsOnUIThread` to `UIManager`. - Adds no-op stubs in iOS (`RCTScheduler.mm`), macOS (`RCTScheduler.mm`), Windows (`FabricUIManagerModule`) and CxxPlatform (`SchedulerDelegateImpl`). No behavioural impact; Android implementation lands in a follow-up. Changelog: [Internal] Differential Revision: D104672455
1 parent bc1a31f commit 9f6fea4

18 files changed

Lines changed: 105 additions & 0 deletions

File tree

packages/react-native/React/Fabric/RCTScheduler.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ void schedulerShouldSynchronouslyUpdateViewOnUIThread(facebook::react::Tag tag,
7979
[scheduler.delegate schedulerDidSynchronouslyUpdateViewOnUIThread:tag props:props];
8080
}
8181

82+
void schedulerShouldSynchronouslyUpdateAnimatedPropsOnUIThread(
83+
SurfaceId surfaceId,
84+
const std::unordered_map<Tag, AnimatedProps> &updates) override
85+
{
86+
// Not implemented on iOS yet -- filled in by a later commit.
87+
}
88+
8289
void schedulerDidUpdateShadowTree(const std::unordered_map<Tag, folly::dynamic> &tagToProps) override
8390
{
8491
// Does nothing.

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <jsi/JSIDynamic.h>
2121
#include <jsi/jsi.h>
2222
#include <react/featureflags/ReactNativeFeatureFlags.h>
23+
#include <react/renderer/animationbackend/AnimatedProps.h>
2324
#include <react/renderer/animations/LayoutAnimationDriver.h>
2425
#include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
2526
#include <react/renderer/core/EventBeat.h>
@@ -792,6 +793,13 @@ void FabricUIManagerBinding::schedulerShouldSynchronouslyUpdateViewOnUIThread(
792793
}
793794
}
794795

796+
void FabricUIManagerBinding::
797+
schedulerShouldSynchronouslyUpdateAnimatedPropsOnUIThread(
798+
SurfaceId /*surfaceId*/,
799+
const std::unordered_map<Tag, AnimatedProps>& /*updates*/) {
800+
// Implemented in a follow-up.
801+
}
802+
795803
void FabricUIManagerBinding::schedulerDidUpdateShadowTree(
796804
const std::unordered_map<Tag, folly::dynamic>& /*tagToProps*/) {
797805
// no-op

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ class FabricUIManagerBinding : public jni::HybridClass<FabricUIManagerBinding>,
115115

116116
void schedulerShouldSynchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props) override;
117117

118+
void schedulerShouldSynchronouslyUpdateAnimatedPropsOnUIThread(
119+
SurfaceId surfaceId,
120+
const std::unordered_map<Tag, AnimatedProps> &updates) override;
121+
118122
void schedulerDidUpdateShadowTree(const std::unordered_map<Tag, folly::dynamic> &tagToProps) override;
119123

120124
void schedulerDidCaptureViewSnapshot(Tag tag, SurfaceId surfaceId) override;

packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,15 @@ void Scheduler::uiManagerShouldSynchronouslyUpdateViewOnUIThread(
401401
}
402402
}
403403

404+
void Scheduler::uiManagerShouldSynchronouslyUpdateAnimatedPropsOnUIThread(
405+
SurfaceId surfaceId,
406+
const std::unordered_map<Tag, AnimatedProps>& updates) {
407+
if (delegate_ != nullptr) {
408+
delegate_->schedulerShouldSynchronouslyUpdateAnimatedPropsOnUIThread(
409+
surfaceId, updates);
410+
}
411+
}
412+
404413
void Scheduler::uiManagerDidUpdateShadowTree(
405414
const std::unordered_map<Tag, folly::dynamic>& tagToProps) {
406415
if (delegate_ != nullptr) {

packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class Scheduler final : public UIManagerDelegate {
9494
bool isJSResponder,
9595
bool blockNativeResponder) override;
9696
void uiManagerShouldSynchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props) override;
97+
void uiManagerShouldSynchronouslyUpdateAnimatedPropsOnUIThread(
98+
SurfaceId surfaceId,
99+
const std::unordered_map<Tag, AnimatedProps> &updates) override;
97100
void uiManagerDidUpdateShadowTree(const std::unordered_map<Tag, folly::dynamic> &tagToProps) override;
98101
void uiManagerDidCaptureViewSnapshot(Tag tag, SurfaceId surfaceId) override;
99102
void uiManagerDidSetViewSnapshot(Tag sourceTag, Tag targetTag, SurfaceId surfaceId) override;

packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
#pragma once
99

1010
#include <memory>
11+
#include <unordered_map>
1112

1213
#include <react/renderer/core/ReactPrimitives.h>
1314
#include <react/renderer/mounting/MountingCoordinator.h>
1415
#include <react/renderer/mounting/ShadowView.h>
1516

1617
namespace facebook::react {
1718

19+
struct AnimatedProps;
20+
1821
/*
1922
* Abstract class for Scheduler's delegate.
2023
*/
@@ -64,6 +67,17 @@ class SchedulerDelegate {
6467

6568
virtual void schedulerShouldSynchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props) = 0;
6669

70+
/**
71+
* Synchronously update animated properties for multiple views on the UI
72+
* thread. Each entry maps a Tag to the AnimatedProps that should be applied
73+
* to that view. Platform implementations translate AnimatedProps into the
74+
* native update mechanism (e.g. buffer protocol on Android, typed props on
75+
* iOS).
76+
*/
77+
virtual void schedulerShouldSynchronouslyUpdateAnimatedPropsOnUIThread(
78+
SurfaceId surfaceId,
79+
const std::unordered_map<Tag, AnimatedProps> &updates) = 0;
80+
6781
virtual void schedulerDidUpdateShadowTree(const std::unordered_map<Tag, folly::dynamic> &tagToProps) = 0;
6882

6983
// View transition bitmap snapshot capture and application.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,15 @@ void UIManager::synchronouslyUpdateViewOnUIThread(
765765
}
766766
}
767767

768+
void UIManager::synchronouslyUpdateAnimatedPropsOnUIThread(
769+
SurfaceId surfaceId,
770+
const std::unordered_map<Tag, AnimatedProps>& updates) {
771+
if (delegate_ != nullptr) {
772+
delegate_->uiManagerShouldSynchronouslyUpdateAnimatedPropsOnUIThread(
773+
surfaceId, updates);
774+
}
775+
}
776+
768777
#pragma mark ContextContainer
769778

770779
std::shared_ptr<const ContextContainer> UIManager::getContextContainer() const {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class UIManager final : public ShadowTreeDelegate {
8585

8686
void synchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props);
8787

88+
void synchronouslyUpdateAnimatedPropsOnUIThread(
89+
SurfaceId surfaceId,
90+
const std::unordered_map<Tag, AnimatedProps> &updates);
91+
8892
/*
8993
* Provides access to a UIManagerBinding.
9094
* The `callback` methods will not be called if the internal pointer to

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace facebook::react {
1717

18+
struct AnimatedProps;
1819
struct AnimationMutations;
1920

2021
using AnimationTimestamp = std::chrono::duration<double, std::milli>;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
#pragma once
99

10+
#include <unordered_map>
11+
1012
#include <react/renderer/core/ReactPrimitives.h>
1113
#include <react/renderer/core/ShadowNode.h>
1214
#include <react/renderer/mounting/MountingCoordinator.h>
1315
#include <react/renderer/mounting/ShadowTree.h>
1416

1517
namespace facebook::react {
1618

19+
struct AnimatedProps;
20+
1721
/*
1822
* Abstract class for UIManager's delegate.
1923
*/
@@ -64,6 +68,13 @@ class UIManagerDelegate {
6468
*/
6569
virtual void uiManagerShouldSynchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props) = 0;
6670

71+
/*
72+
* Synchronously update animated properties on the UI thread.
73+
*/
74+
virtual void uiManagerShouldSynchronouslyUpdateAnimatedPropsOnUIThread(
75+
SurfaceId surfaceId,
76+
const std::unordered_map<Tag, AnimatedProps> &updates) = 0;
77+
6778
/*
6879
* Called after updateShadowTree is invoked.
6980
*/

0 commit comments

Comments
 (0)