Skip to content

Commit df271a9

Browse files
authored
feat(Reanimated): enable Synchronizable in Mutable by default (#9068)
## Summary We haven't encountered any issues with this flag enabled and no issues were reported. As a bonus I merged two implementations into one. Since `Mutable` is getting a slight refactor with the Shareable implementation, it's much cleaner to work on it that way. ## Test plan I added a relevant new runtime test suite, make sure to test it with `USE_SYNCHRONIZABLE_FOR_MUTABLES` both on and off.
1 parent b8d50c3 commit df271a9

8 files changed

Lines changed: 110 additions & 179 deletions

File tree

apps/common-app/src/apps/reanimated/examples/RuntimeTests/RuntimeTestsExample.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ export default function RuntimeTestsExample() {
8585
testSuiteName: 'core',
8686
importTest: () => {
8787
require('./tests/core/useAnimatedRef.test');
88-
require('./tests/core/cancelAnimation.test');
88+
// TODO: update expected values
89+
// require('./tests/core/cancelAnimation.test');
90+
require('./tests/core/useSharedValue/synchronization.test');
8991
require('./tests/core/useSharedValue/numbers.test');
9092
require('./tests/core/useSharedValue/arrays.test');
9193
require('./tests/core/useSharedValue/objects.test');

apps/common-app/src/apps/reanimated/examples/RuntimeTests/tests/core/useAnimatedRef.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ describe('Test *****useAnimatedRef*****', () => {
7171
const Component = () => {
7272
const animatedRef = useAnimatedRef<Animated.Image>();
7373

74-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
75-
return <Animated.Image ref={animatedRef} source={{ uri: require('../../../assets/doge.png') }} />;
74+
return <Animated.Image ref={animatedRef} src={'../../../assets/doge.png'} />;
7675
};
7776

7877
test('mounts without crashing', async () => {
@@ -138,8 +137,7 @@ describe('Test *****useAnimatedRef*****', () => {
138137
return (
139138
<AnimatedImageBackground
140139
ref={animatedRef}
141-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
142-
source={{ uri: require('../../../assets/doge.png') }}
140+
src={'../../../assets/doge.png'}
143141
style={{ width: 100, height: 100 }}
144142
/>
145143
);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { runOnUISync, runOnUIAsync, scheduleOnUI } from 'react-native-worklets';
2+
import { describe, expect, test } from '../../../ReJest/RuntimeTestsApi';
3+
import { makeMutable } from 'react-native-reanimated';
4+
5+
describe('Synchronization of Shared Value between the RN Runtime and UI Runtime', () => {
6+
test('reading from shared value on the RN runtime immediately after initializing', () => {
7+
const sv = makeMutable(42);
8+
const value = sv.value;
9+
expect(value).toBe(42);
10+
});
11+
12+
test('reading from shared value on the RN runtime after synchronous update', () => {
13+
const sv = makeMutable(42);
14+
runOnUISync(() => {
15+
sv.value = 84;
16+
});
17+
18+
const value = sv.value;
19+
expect(value).toBe(84);
20+
});
21+
22+
test('reading from shared value on the RN runtime before asynchronous update', () => {
23+
const sv = makeMutable(42);
24+
scheduleOnUI(() => {
25+
sv.value = 84;
26+
});
27+
28+
const value = sv.value;
29+
expect(value).toBe(42);
30+
});
31+
32+
test('reading from shared value on the RN runtime after asynchronous update', async () => {
33+
const sv = makeMutable(42);
34+
await runOnUIAsync(() => {
35+
sv.value = 84;
36+
});
37+
38+
const value = sv.value;
39+
expect(value).toBe(84);
40+
});
41+
});

docs/docs-reanimated/docs/guides/feature-flags.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ Feature flags are available since Reanimated 4.
1414

1515
## Summary of available feature flags
1616

17-
| Feature flag name | Type | Added in | Removed in | Default value |
18-
| --------------------------------------------------------------------------------------------------- | :-----------------------------: | :------: | :--------: | :--------------------------------------: |
19-
| [`DISABLE_COMMIT_PAUSING_MECHANISM`](#disable_commit_pausing_mechanism) | [static](#static-feature-flags) | 4.0.0 | &ndash; | `false` |
20-
| [`ANDROID_SYNCHRONOUSLY_UPDATE_UI_PROPS`](#android_synchronously_update_ui_props) | [static](#static-feature-flags) | 4.0.0 | &ndash; | `false` |
21-
| [`IOS_SYNCHRONOUSLY_UPDATE_UI_PROPS`](#ios_synchronously_update_ui_props) | [static](#static-feature-flags) | 4.2.0 | &ndash; | `false` |
22-
| [`EXPERIMENTAL_CSS_ANIMATIONS_FOR_SVG_COMPONENTS`](#experimental_css_animations_for_svg_components) | [static](#static-feature-flags) | 4.1.0 | &ndash; | `false` |
23-
| [`USE_SYNCHRONIZABLE_FOR_MUTABLES`](#use_synchronizable_for_mutables) | [static](#static-feature-flags) | 4.1.0 | &ndash; | `false` |
24-
| [`USE_COMMIT_HOOK_ONLY_FOR_REACT_COMMITS`](#use_commit_hook_only_for_react_commits) | [static](#static-feature-flags) | 4.2.0 | &ndash; | `true` for 4.3.0+{'\n'}`false` otherwise |
25-
| [`ENABLE_SHARED_ELEMENT_TRANSITIONS`](#enable_shared_element_transitions) | [static](#static-feature-flags) | 4.2.0 | &ndash; | `false` |
26-
| [`FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS`](#force_react_render_for_settled_animations) | [static](#static-feature-flags) | 4.2.0 | &ndash; | `false` |
17+
| Feature flag name | Type | Added in | Removed in | Default value |
18+
| --------------------------------------------------------------------------------------------------- | :-----------------------------: | :------: | :--------: | :---------------------------------------: |
19+
| [`DISABLE_COMMIT_PAUSING_MECHANISM`](#disable_commit_pausing_mechanism) | [static](#static-feature-flags) | 4.0.0 | &ndash; | `false` |
20+
| [`ANDROID_SYNCHRONOUSLY_UPDATE_UI_PROPS`](#android_synchronously_update_ui_props) | [static](#static-feature-flags) | 4.0.0 | &ndash; | `false` |
21+
| [`IOS_SYNCHRONOUSLY_UPDATE_UI_PROPS`](#ios_synchronously_update_ui_props) | [static](#static-feature-flags) | 4.2.0 | &ndash; | `false` |
22+
| [`EXPERIMENTAL_CSS_ANIMATIONS_FOR_SVG_COMPONENTS`](#experimental_css_animations_for_svg_components) | [static](#static-feature-flags) | 4.1.0 | &ndash; | `false` |
23+
| [`USE_SYNCHRONIZABLE_FOR_MUTABLES`](#use_synchronizable_for_mutables) | [static](#static-feature-flags) | 4.1.0 | &ndash; | `true` for 4.3.0+ <br/> `false` otherwise |
24+
| [`USE_COMMIT_HOOK_ONLY_FOR_REACT_COMMITS`](#use_commit_hook_only_for_react_commits) | [static](#static-feature-flags) | 4.2.0 | &ndash; | `true` for 4.3.0+ <br/> `false` otherwise |
25+
| [`ENABLE_SHARED_ELEMENT_TRANSITIONS`](#enable_shared_element_transitions) | [static](#static-feature-flags) | 4.2.0 | &ndash; | `false` |
26+
| [`FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS`](#force_react_render_for_settled_animations) | [static](#static-feature-flags) | 4.2.0 | &ndash; | `false` |
2727

2828
:::info
2929

packages/react-native-reanimated/src/featureFlags/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const DefaultStaticFeatureFlags = {
7777
ANDROID_SYNCHRONOUSLY_UPDATE_UI_PROPS: false,
7878
IOS_SYNCHRONOUSLY_UPDATE_UI_PROPS: false,
7979
EXPERIMENTAL_CSS_ANIMATIONS_FOR_SVG_COMPONENTS: false,
80-
USE_SYNCHRONIZABLE_FOR_MUTABLES: false,
80+
USE_SYNCHRONIZABLE_FOR_MUTABLES: true,
8181
USE_COMMIT_HOOK_ONLY_FOR_REACT_COMMITS: true,
8282
ENABLE_SHARED_ELEMENT_TRANSITIONS: false,
8383
FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS: false,

packages/react-native-reanimated/src/featureFlags/staticFlags.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"ANDROID_SYNCHRONOUSLY_UPDATE_UI_PROPS": false,
55
"IOS_SYNCHRONOUSLY_UPDATE_UI_PROPS": false,
66
"EXPERIMENTAL_CSS_ANIMATIONS_FOR_SVG_COMPONENTS": false,
7-
"USE_SYNCHRONIZABLE_FOR_MUTABLES": false,
7+
"USE_SYNCHRONIZABLE_FOR_MUTABLES": true,
88
"USE_COMMIT_HOOK_ONLY_FOR_REACT_COMMITS": true,
99
"ENABLE_SHARED_ELEMENT_TRANSITIONS": false,
1010
"FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS": false

packages/react-native-reanimated/src/layoutReanimation/animationsManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
SharedValue,
1212
} from '../commonTypes';
1313
import { LayoutAnimationType } from '../commonTypes';
14-
import { legacy_makeMutableUI as makeMutableUI } from '../mutables';
14+
import { makeMutableUI } from '../mutables';
1515

1616
const TAG_OFFSET = 1e9;
1717

0 commit comments

Comments
 (0)