Skip to content

Commit

Permalink
Disable JS batching when animation batch is finished on Android (#45563)
Browse files Browse the repository at this point in the history
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 #45229

## Changelog:

[ANDROID] [FIXED] - Fix scheduled animated operations not being executed in some cases

Pull Request resolved: #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
  • Loading branch information
j-piasecki authored and facebook-github-bot committed Jul 24, 2024
1 parent 19cffab commit dc8c8eb
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public void startOperationBatch() {

@Override
public void finishOperationBatch() {
mBatchingControlledByJS = true;
mBatchingControlledByJS = false;
mCurrentBatchNumber++;
}

Expand Down

0 comments on commit dc8c8eb

Please sign in to comment.