diff --git a/Libraries/Animated/__tests__/Animated-test.js b/Libraries/Animated/__tests__/Animated-test.js index f7a8bb05ace..d5b05cc49a6 100644 --- a/Libraries/Animated/__tests__/Animated-test.js +++ b/Libraries/Animated/__tests__/Animated-test.js @@ -11,14 +11,9 @@ import TestRenderer from 'react-test-renderer'; import * as React from 'react'; -jest.mock('../../BatchedBridge/NativeModules', () => ({ - NativeAnimatedModule: {}, - PlatformConstants: { - getConstants() { - return {}; - }, - }, -})); +jest.mock('../NativeAnimatedHelper', () => { + return jest.requireActual('../NativeAnimatedHelper'); +}); let Animated = require('../Animated'); describe('Animated tests', () => { diff --git a/Libraries/Animated/__tests__/AnimatedNative-test.js b/Libraries/Animated/__tests__/AnimatedNative-test.js index e5ecec1fb7d..8466b15483c 100644 --- a/Libraries/Animated/__tests__/AnimatedNative-test.js +++ b/Libraries/Animated/__tests__/AnimatedNative-test.js @@ -10,15 +10,9 @@ jest .clearAllMocks() - .mock('../../BatchedBridge/NativeModules', () => ({ - NativeAnimatedModule: {}, - PlatformConstants: { - getConstants() { - return {}; - }, - }, - })) - .mock('../NativeAnimatedModule') + .mock('../NativeAnimatedHelper', () => { + return jest.requireActual('../NativeAnimatedHelper'); + }) .mock('../../EventEmitter/NativeEventEmitter') // findNodeHandle is imported from ReactNative so mock that whole module. .setMock('../../Renderer/shims/ReactNative', {findNodeHandle: () => 1}); diff --git a/Libraries/Animated/createAnimatedComponent.js b/Libraries/Animated/createAnimatedComponent.js index fda18f0af80..45859bb111c 100644 --- a/Libraries/Animated/createAnimatedComponent.js +++ b/Libraries/Animated/createAnimatedComponent.js @@ -121,19 +121,15 @@ function createAnimatedComponent( }; _waitForUpdate = (): void => { - if (this._isFabric()) { - NativeAnimatedHelper.API.setWaitingForIdentifier( - this._animatedComponentId, - ); - } + NativeAnimatedHelper.API.setWaitingForIdentifier( + this._animatedComponentId, + ); }; _markUpdateComplete = (): void => { - if (this._isFabric()) { - NativeAnimatedHelper.API.unsetWaitingForIdentifier( - this._animatedComponentId, - ); - } + NativeAnimatedHelper.API.unsetWaitingForIdentifier( + this._animatedComponentId, + ); }; // The system is best designed when setNativeProps is implemented. It is diff --git a/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java b/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java index 9d6f4299db2..b12d75c86a6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java @@ -174,7 +174,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec } private void addOperation(UIThreadOperation operation) { - operation.setBatchNumber(mIsInBatch ? mCurrentBatchNumber : -1); + operation.setBatchNumber(getCurrentBatchNumber()); mOperations.add(operation); } @@ -184,7 +184,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec } private void addPreOperation(UIThreadOperation operation) { - operation.setBatchNumber(mIsInBatch ? mCurrentBatchNumber : -1); + operation.setBatchNumber(getCurrentBatchNumber()); mPreOperations.add(operation); } @@ -342,6 +342,13 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec ReactChoreographer.CallbackType.NATIVE_ANIMATED_MODULE, mAnimatedFrameCallback); } + private long getCurrentBatchNumber() { + if (mBatchingControlledByJS && !mIsInBatch) { + return -1; + } + return mCurrentBatchNumber; + } + @VisibleForTesting public void setNodesManager(NativeAnimatedNodesManager nodesManager) { mNodesManager.set(nodesManager); @@ -426,6 +433,9 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec @Override public void startOperationBatch() { + if (ANIMATED_MODULE_DEBUG) { + FLog.d(NAME, "Start JS operation batch " + mCurrentBatchNumber); + } mBatchingControlledByJS = true; mIsInBatch = true; mCurrentBatchNumber++; @@ -433,6 +443,9 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec @Override public void finishOperationBatch() { + if (ANIMATED_MODULE_DEBUG) { + FLog.d(NAME, "Finish JS operation batch " + mCurrentBatchNumber); + } mBatchingControlledByJS = true; mIsInBatch = false; mCurrentBatchNumber++; diff --git a/jest/setup.js b/jest/setup.js index c759924d23c..a37cbb3865e 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -332,6 +332,30 @@ jest doLeftAndRightSwapInRTL: true, }), }, + NativeAnimatedModule: { + startOperationBatch: jest.fn(), + finishOperationBatch: jest.fn(), + createAnimatedNode: jest.fn(), + getValue: jest.fn(), + startListeningToAnimatedNodeValue: jest.fn(), + stopListeningToAnimatedNodeValue: jest.fn(), + connectAnimatedNodes: jest.fn(), + disconnectAnimatedNodes: jest.fn(), + startAnimatingNode: jest.fn(), + stopAnimation: jest.fn(), + setAnimatedNodeValue: jest.fn(), + setAnimatedNodeOffset: jest.fn(), + flattenAnimatedNodeOffset: jest.fn(), + extractAnimatedNodeOffset: jest.fn(), + connectAnimatedNodeToView: jest.fn(), + disconnectAnimatedNodeFromView: jest.fn(), + restoreDefaultValues: jest.fn(), + dropAnimatedNode: jest.fn(), + addAnimatedEventToView: jest.fn(), + removeAnimatedEventFromView: jest.fn(), + addListener: jest.fn(), + removeListeners: jest.fn(), + }, })) .mock('../Libraries/NativeComponent/NativeComponentRegistry', () => { return { @@ -365,4 +389,13 @@ jest __esModule: true, default: Component, }; + }) + .mock('../Libraries/Animated/NativeAnimatedHelper.js', () => { + const NativeAnimatedHelper = jest.requireActual( + '../Libraries/Animated/NativeAnimatedHelper.js', + ); + return { + ...NativeAnimatedHelper, + shouldUseNativeDriver: jest.fn(false), + }; });