Skip to content

Commit

Permalink
Ship modern animated
Browse files Browse the repository at this point in the history
Summary:
changelog:
[general][Added] - Concurrent rendering safe implementation of Animated

Reviewed By: yungsters

Differential Revision: D40681265

fbshipit-source-id: b3979c69342ebd7f232f7a00f279ef0b082d4182
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Nov 3, 2022
1 parent d9ab5e8 commit 5e863fc
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 415 deletions.
10 changes: 6 additions & 4 deletions Libraries/Animated/NativeAnimatedHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ const API = {
}
},
flushQueue: function (): void {
invariant(NativeAnimatedModule, 'Native animated module is not available');
// TODO: (T136971132)
// invariant(NativeAnimatedModule, 'Native animated module is not available');
flushQueueTimeout = null;

// Early returns before calling any APIs
Expand All @@ -165,16 +166,17 @@ const API = {
// use RCTDeviceEventEmitter. This reduces overhead of sending lots of
// JSI functions across to native code; but also, TM infrastructure currently
// does not support packing a function into native arrays.
NativeAnimatedModule.queueAndExecuteBatchedOperations?.(singleOpQueue);
NativeAnimatedModule?.queueAndExecuteBatchedOperations?.(singleOpQueue);
singleOpQueue.length = 0;
} else {
Platform.OS === 'android' && NativeAnimatedModule.startOperationBatch?.();
Platform.OS === 'android' &&
NativeAnimatedModule?.startOperationBatch?.();
for (let q = 0, l = queue.length; q < l; q++) {
queue[q]();
}
queue.length = 0;
Platform.OS === 'android' &&
NativeAnimatedModule.finishOperationBatch?.();
NativeAnimatedModule?.finishOperationBatch?.();
}
},
queueOperation: <Args: $ReadOnlyArray<mixed>, Fn: (...Args) => void>(
Expand Down
14 changes: 8 additions & 6 deletions Libraries/Animated/__tests__/Animated-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
*/

import * as React from 'react';
import TestRenderer from 'react-test-renderer';

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

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

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

Animated.timing(opacity, {
toValue: 1,
duration: 0,
useNativeDriver: false,
}).start();
TestRenderer.act(() => {
Animated.timing(opacity, {
toValue: 1,
duration: 0,
useNativeDriver: false,
}).start();
});

expect(testRenderer.toJSON().props.style.opacity).toEqual(1);
});
Expand Down

This file was deleted.

Loading

0 comments on commit 5e863fc

Please sign in to comment.