Skip to content

Commit 35ebb57

Browse files
Abraham Romerofacebook-github-bot
authored andcommitted
Back out "Ship modern animated"
Summary: Changelog: [General][Removed] - Reverting concurrency-safe `Animated` to investigate some newly identified issues Reviewed By: sammy-SC Differential Revision: D41006680 fbshipit-source-id: 37b89911dfa72f5a94f9bb796d49f2b138b3f45b
1 parent 5cfb886 commit 35ebb57

File tree

7 files changed

+415
-42
lines changed

7 files changed

+415
-42
lines changed

Libraries/Animated/NativeAnimatedHelper.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ const API = {
142142
}
143143
},
144144
flushQueue: function (): void {
145-
// TODO: (T136971132)
146-
// invariant(NativeAnimatedModule, 'Native animated module is not available');
145+
invariant(NativeAnimatedModule, 'Native animated module is not available');
147146
flushQueueTimeout = null;
148147

149148
// Early returns before calling any APIs
@@ -166,17 +165,16 @@ const API = {
166165
// use RCTDeviceEventEmitter. This reduces overhead of sending lots of
167166
// JSI functions across to native code; but also, TM infrastructure currently
168167
// does not support packing a function into native arrays.
169-
NativeAnimatedModule?.queueAndExecuteBatchedOperations?.(singleOpQueue);
168+
NativeAnimatedModule.queueAndExecuteBatchedOperations?.(singleOpQueue);
170169
singleOpQueue.length = 0;
171170
} else {
172-
Platform.OS === 'android' &&
173-
NativeAnimatedModule?.startOperationBatch?.();
171+
Platform.OS === 'android' && NativeAnimatedModule.startOperationBatch?.();
174172
for (let q = 0, l = queue.length; q < l; q++) {
175173
queue[q]();
176174
}
177175
queue.length = 0;
178176
Platform.OS === 'android' &&
179-
NativeAnimatedModule?.finishOperationBatch?.();
177+
NativeAnimatedModule.finishOperationBatch?.();
180178
}
181179
},
182180
queueOperation: <Args: $ReadOnlyArray<mixed>, Fn: (...Args) => void>(

Libraries/Animated/__tests__/Animated-test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
*/
1010

1111
import * as React from 'react';
12+
import TestRenderer from 'react-test-renderer';
1213

1314
let Animated = require('../Animated').default;
1415
let AnimatedProps = require('../nodes/AnimatedProps').default;
15-
let TestRenderer = require('react-test-renderer');
1616

1717
jest.mock('../../BatchedBridge/NativeModules', () => ({
1818
NativeAnimatedModule: {},
@@ -175,13 +175,11 @@ describe('Animated tests', () => {
175175

176176
expect(testRenderer.toJSON().props.style.opacity).toEqual(0);
177177

178-
TestRenderer.act(() => {
179-
Animated.timing(opacity, {
180-
toValue: 1,
181-
duration: 0,
182-
useNativeDriver: false,
183-
}).start();
184-
});
178+
Animated.timing(opacity, {
179+
toValue: 1,
180+
duration: 0,
181+
useNativeDriver: false,
182+
}).start();
185183

186184
expect(testRenderer.toJSON().props.style.opacity).toEqual(1);
187185
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
'use strict';
13+
14+
import * as React from 'react';
15+
16+
const createAnimatedComponent = require('../createAnimatedComponent').default;
17+
const createAnimatedComponentInjection = require('../createAnimatedComponentInjection');
18+
19+
function injected<TProps: {...}, TInstance>(
20+
Component: React.AbstractComponent<TProps, TInstance>,
21+
): React.AbstractComponent<TProps, TInstance> {
22+
return createAnimatedComponent(Component);
23+
}
24+
25+
beforeEach(() => {
26+
jest.resetModules();
27+
jest.resetAllMocks();
28+
});
29+
30+
test('does nothing without injection', () => {
31+
expect(typeof createAnimatedComponent).toBe('function');
32+
expect(createAnimatedComponent).not.toBe(injected);
33+
});
34+
35+
test('injection overrides `createAnimatedComponent`', () => {
36+
createAnimatedComponentInjection.inject(injected);
37+
38+
expect(createAnimatedComponent).toBe(injected);
39+
});
40+
41+
test('injection errors if called too late', () => {
42+
jest.spyOn(console, 'error').mockReturnValue(undefined);
43+
44+
// Causes `createAnimatedComponent` to be initialized.
45+
createAnimatedComponent;
46+
47+
createAnimatedComponentInjection.inject(injected);
48+
49+
expect(createAnimatedComponent).not.toBe(injected);
50+
expect(console.error).toBeCalledWith(
51+
'createAnimatedComponentInjection: Must be called before `createAnimatedComponent`.',
52+
);
53+
});
54+
55+
test('injection errors if called more than once', () => {
56+
jest.spyOn(console, 'error').mockReturnValue(undefined);
57+
58+
createAnimatedComponentInjection.inject(injected);
59+
60+
expect(createAnimatedComponent).toBe(injected);
61+
expect(console.error).not.toBeCalled();
62+
63+
createAnimatedComponentInjection.inject(injected);
64+
65+
expect(console.error).toBeCalledWith(
66+
'createAnimatedComponentInjection: Cannot be called more than once.',
67+
);
68+
});

0 commit comments

Comments
 (0)