Skip to content

Commit 4b260bb

Browse files
zeyapfacebook-github-bot
authored andcommitted
Gate logic to remove js sync at end of native animation loop (facebook#52068)
Summary: Pull Request resolved: facebook#52068 ## Changelog: [Internal] [Changed] - Gate logic to remove js sync at end of native animation loop because facebook#51264 is causing regression in some cases, and was recently reverted again in facebook#51933 . Using an extra feature flag to gate this potential optimization Reviewed By: lenaic Differential Revision: D76759441
1 parent c7649b2 commit 4b260bb

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

packages/react-native/Libraries/Animated/__tests__/Animated-itest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ test('moving box by 100 points', () => {
7373
Fantom.unstable_produceFramesForDuration(500);
7474

7575
// Animation is completed now. C++ Animated will commit the final position to the shadow tree.
76-
expect(viewElement.getBoundingClientRect().x).toBe(100);
76+
expect(viewElement.getBoundingClientRect().x).toBe(0);
7777

7878
// TODO: this shouldn't be needed but C++ Animated still schedules a React state update
7979
// for synchronisation, even though it doesn't need to.
@@ -264,7 +264,7 @@ test('moving box by 50 points with offset 10', () => {
264264
).toBeCloseTo(60, 0.001);
265265

266266
expect(root.getRenderedOutput({props: ['transform']}).toJSX()).toEqual(
267-
<rn-view transform='[{"translateX": 60.000000}]' />,
267+
<rn-view transform="[]" />,
268268
);
269269

270270
// TODO: this shouldn't be neccessary but C++ Animated still schedules a React state update.

packages/react-native/Libraries/Animated/animations/Animation.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type AnimatedNode from '../nodes/AnimatedNode';
1313
import type AnimatedValue from '../nodes/AnimatedValue';
1414

1515
import NativeAnimatedHelper from '../../../src/private/animated/NativeAnimatedHelper';
16+
import * as ReactNativeFeatureFlags from '../../../src/private/featureflags/ReactNativeFeatureFlags';
1617
import AnimatedProps from '../nodes/AnimatedProps';
1718

1819
export type EndResult = {
@@ -149,8 +150,15 @@ export default class Animation {
149150
if (value != null) {
150151
animatedValue.__onAnimatedValueUpdateReceived(value, offset);
151152

152-
if (this.__isLooping === true) {
153-
return;
153+
if (
154+
!(
155+
ReactNativeFeatureFlags.cxxNativeAnimatedEnabled() &&
156+
ReactNativeFeatureFlags.cxxNativeAnimatedRemoveJsSync()
157+
)
158+
) {
159+
if (this.__isLooping === true) {
160+
return;
161+
}
154162
}
155163

156164
// Once the JS side node is synced with the updated values, trigger an

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <folly/json.h>
1111
#include <glog/logging.h>
1212
#include <react/debug/react_native_assert.h>
13+
#include <react/featureflags/ReactNativeFeatureFlags.h>
1314
#include <react/profiling/perfetto.h>
1415
#include <react/renderer/animated/drivers/AnimationDriver.h>
1516
#include <react/renderer/animated/drivers/AnimationDriverUtils.h>
@@ -658,7 +659,9 @@ bool NativeAnimatedNodesManager::onAnimationFrame(double timestamp) {
658659

659660
if (driver->getIsComplete()) {
660661
hasFinishedAnimations = true;
661-
finishedAnimationValueNodes.insert(driver->getAnimatedValueTag());
662+
if (ReactNativeFeatureFlags::cxxNativeAnimatedRemoveJsSync()) {
663+
finishedAnimationValueNodes.insert(driver->getAnimatedValueTag());
664+
}
662665
}
663666
}
664667

packages/react-native/src/private/animated/createAnimatedPropsHook.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,13 @@ export default function createAnimatedPropsHook(
132132
if (node.__isNative) {
133133
// Check 2: this is an animation driven by native.
134134
// In native driven animations, this callback is only called once the animation completes.
135-
if (isFabricNode) {
135+
if (
136+
isFabricNode &&
137+
!(
138+
ReactNativeFeatureFlags.cxxNativeAnimatedEnabled() &&
139+
ReactNativeFeatureFlags.cxxNativeAnimatedRemoveJsSync()
140+
)
141+
) {
136142
// Call `scheduleUpdate` to synchronise Fiber and Shadow tree.
137143
// Must not be called in Paper.
138144
scheduleUpdate();

0 commit comments

Comments
 (0)