From dc8c8ebc5b7b6315b3c8e79028a80611a796ea7e Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Wed, 24 Jul 2024 06:09:45 -0700 Subject: [PATCH] Disable JS batching when animation batch is finished on Android (#45563) Summary: When an animation using the native driver [is started](https://github.com/facebook/react-native/blob/c82edec62e2149a746627c6b474d4d413f545128/packages/react-native/Libraries/Animated/animations/Animation.js#L89), all animated operations are [queued](https://github.com/facebook/react-native/blob/c82edec62e2149a746627c6b474d4d413f545128/packages/react-native/Libraries/Animated/NativeAnimatedHelper.js#L115). The queue is then flushed as part of [a single batch](https://github.com/facebook/react-native/blob/c82edec62e2149a746627c6b474d4d413f545128/packages/react-native/Libraries/Animated/NativeAnimatedHelper.js#L173-L181). The problem here is that when a batch is executed, on the native side a [flag is flipped](https://github.com/facebook/react-native/blob/c82edec62e2149a746627c6b474d4d413f545128/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java#L543) and it assumes that JS will take control of the batching operation from that point onward, which is not the case. Operations are queued with the current batch number but are never executed, since the new "batch" is never finished. The case which let to figuring it out is the creation of `AnimatedInterpolation` in the [sticky header component](https://github.com/facebook/react-native/blob/c82edec62e2149a746627c6b474d4d413f545128/packages/react-native/Libraries/Components/ScrollView/ScrollViewStickyHeader.js#L215). This PR changes this by returning to the default behavior when the batch is completed. Fixes https://github.com/facebook/react-native/issues/45229 ## Changelog: [ANDROID] [FIXED] - Fix scheduled animated operations not being executed in some cases Pull Request resolved: https://github.com/facebook/react-native/pull/45563 Test Plan: Tested on Animated examples in RNTester and on the reproducer app from the issue Reviewed By: cipolleschi Differential Revision: D60108049 Pulled By: dmytrorykun fbshipit-source-id: 9c14d116b0df2c78fbbb00cf7224bddd09ae5796 --- .../java/com/facebook/react/animated/NativeAnimatedModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java index 572eacffe4a..0f5043d1906 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java @@ -546,7 +546,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec @Override public void finishOperationBatch() { - mBatchingControlledByJS = true; + mBatchingControlledByJS = false; mCurrentBatchNumber++; }