Skip to content

Commit 325c681

Browse files
Bartlomiej Bloniarzfacebook-github-bot
authored andcommitted
boostrap shared animation backend (#53994)
Summary: Pull Request resolved: #53994 # Summary This diff introduces the Shared Animation Backend - a class that can be used by animation frameworks to schedule and run animation updates. ## Changelog: [GENERAL] [ADDED] - AnimationBackend-itest.js AnimationBackend BUCK/CmakeLists [GENERAL] [ADDED] - useSharedAnimationBackend feature flag [GENERAL] [CHANGED] - make AnimatedNodesManager use the backend behind the flag Reviewed By: zeyap, sammy-SC Differential Revision: D80809364 fbshipit-source-id: dbfe273362410cdf2f9fc37d78adac7faf4cd118
1 parent 33bc271 commit 325c681

29 files changed

+475
-25
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
* @fantom_flags useSharedAnimatedBackend:true
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
13+
14+
import type {HostInstance} from 'react-native';
15+
16+
import ensureInstance from '../../../src/private/__tests__/utilities/ensureInstance';
17+
import * as Fantom from '@react-native/fantom';
18+
import {createRef} from 'react';
19+
import {Animated, useAnimatedValue} from 'react-native';
20+
import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement';
21+
22+
test('animated opacity', () => {
23+
let _opacity;
24+
let _opacityAnimation;
25+
const viewRef = createRef<HostInstance>();
26+
27+
function MyApp() {
28+
const opacity = useAnimatedValue(1);
29+
_opacity = opacity;
30+
return (
31+
<Animated.View
32+
ref={viewRef}
33+
style={[
34+
{
35+
width: 100,
36+
height: 100,
37+
opacity: opacity,
38+
},
39+
]}
40+
/>
41+
);
42+
}
43+
44+
const root = Fantom.createRoot();
45+
46+
Fantom.runTask(() => {
47+
root.render(<MyApp />);
48+
});
49+
50+
const viewElement = ensureInstance(viewRef.current, ReactNativeElement);
51+
52+
expect(viewElement.getBoundingClientRect().x).toBe(0);
53+
54+
Fantom.runTask(() => {
55+
_opacityAnimation = Animated.timing(_opacity, {
56+
toValue: 0,
57+
duration: 30,
58+
useNativeDriver: true,
59+
}).start();
60+
});
61+
62+
Fantom.unstable_produceFramesForDuration(30);
63+
expect(Fantom.unstable_getDirectManipulationProps(viewElement).opacity).toBe(
64+
0,
65+
);
66+
67+
// TODO: this shouldn't be neccessary since animation should be stopped after duration
68+
Fantom.runTask(() => {
69+
_opacityAnimation?.stop();
70+
});
71+
72+
expect(root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual(
73+
<rn-view opacity="0" />,
74+
);
75+
});

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<f707e26d09b6f7962ec97296a1a215b6>>
7+
* @generated SignedSource<<8af0aea8bbf4cffaad7d312032bef0e4>>
88
*/
99

1010
/**
@@ -456,6 +456,12 @@ public object ReactNativeFeatureFlags {
456456
@JvmStatic
457457
public fun useShadowNodeStateOnClone(): Boolean = accessor.useShadowNodeStateOnClone()
458458

459+
/**
460+
* Use shared animation backend in C++ Animated
461+
*/
462+
@JvmStatic
463+
public fun useSharedAnimatedBackend(): Boolean = accessor.useSharedAnimatedBackend()
464+
459465
/**
460466
* In Bridgeless mode, should legacy NativeModules use the TurboModule system?
461467
*/

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<e7cfc5135c7b3c731324297e92e41e3f>>
7+
* @generated SignedSource<<5c2aa1e15e7fbe129b8f774d2dc7be70>>
88
*/
99

1010
/**
@@ -91,6 +91,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
9191
private var useOptimizedEventBatchingOnAndroidCache: Boolean? = null
9292
private var useRawPropsJsiValueCache: Boolean? = null
9393
private var useShadowNodeStateOnCloneCache: Boolean? = null
94+
private var useSharedAnimatedBackendCache: Boolean? = null
9495
private var useTurboModuleInteropCache: Boolean? = null
9596
private var useTurboModulesCache: Boolean? = null
9697
private var viewCullingOutsetRatioCache: Double? = null
@@ -736,6 +737,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
736737
return cached
737738
}
738739

740+
override fun useSharedAnimatedBackend(): Boolean {
741+
var cached = useSharedAnimatedBackendCache
742+
if (cached == null) {
743+
cached = ReactNativeFeatureFlagsCxxInterop.useSharedAnimatedBackend()
744+
useSharedAnimatedBackendCache = cached
745+
}
746+
return cached
747+
}
748+
739749
override fun useTurboModuleInterop(): Boolean {
740750
var cached = useTurboModuleInteropCache
741751
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<3254fef626b10ef21d8d9ee1bdbb1880>>
7+
* @generated SignedSource<<0bd8796f4580322a78690ec4469c07ce>>
88
*/
99

1010
/**
@@ -170,6 +170,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
170170

171171
@DoNotStrip @JvmStatic public external fun useShadowNodeStateOnClone(): Boolean
172172

173+
@DoNotStrip @JvmStatic public external fun useSharedAnimatedBackend(): Boolean
174+
173175
@DoNotStrip @JvmStatic public external fun useTurboModuleInterop(): Boolean
174176

175177
@DoNotStrip @JvmStatic public external fun useTurboModules(): Boolean

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<9f7eb1bb5e24fd8ee87accf60209cce3>>
7+
* @generated SignedSource<<7c7796cbe2722f0f6e5b2cc4ed43a0d5>>
88
*/
99

1010
/**
@@ -165,6 +165,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
165165

166166
override fun useShadowNodeStateOnClone(): Boolean = false
167167

168+
override fun useSharedAnimatedBackend(): Boolean = false
169+
168170
override fun useTurboModuleInterop(): Boolean = false
169171

170172
override fun useTurboModules(): Boolean = false

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<9e6e04ca37edd1ad9265b74e251ff4de>>
7+
* @generated SignedSource<<f3420de2307aab53b885fa491183d84b>>
88
*/
99

1010
/**
@@ -95,6 +95,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
9595
private var useOptimizedEventBatchingOnAndroidCache: Boolean? = null
9696
private var useRawPropsJsiValueCache: Boolean? = null
9797
private var useShadowNodeStateOnCloneCache: Boolean? = null
98+
private var useSharedAnimatedBackendCache: Boolean? = null
9899
private var useTurboModuleInteropCache: Boolean? = null
99100
private var useTurboModulesCache: Boolean? = null
100101
private var viewCullingOutsetRatioCache: Double? = null
@@ -811,6 +812,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
811812
return cached
812813
}
813814

815+
override fun useSharedAnimatedBackend(): Boolean {
816+
var cached = useSharedAnimatedBackendCache
817+
if (cached == null) {
818+
cached = currentProvider.useSharedAnimatedBackend()
819+
accessedFeatureFlags.add("useSharedAnimatedBackend")
820+
useSharedAnimatedBackendCache = cached
821+
}
822+
return cached
823+
}
824+
814825
override fun useTurboModuleInterop(): Boolean {
815826
var cached = useTurboModuleInteropCache
816827
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<65e895433fc609bd7c2b5d7faa507f46>>
7+
* @generated SignedSource<<d4370bcde97d3c2b0b8d2a77e42a6031>>
88
*/
99

1010
/**
@@ -165,6 +165,8 @@ public interface ReactNativeFeatureFlagsProvider {
165165

166166
@DoNotStrip public fun useShadowNodeStateOnClone(): Boolean
167167

168+
@DoNotStrip public fun useSharedAnimatedBackend(): Boolean
169+
168170
@DoNotStrip public fun useTurboModuleInterop(): Boolean
169171

170172
@DoNotStrip public fun useTurboModules(): Boolean

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<7a0a26494846d6b4881bea01beabb9d6>>
7+
* @generated SignedSource<<740fec2589997816f17778f57b1d4abf>>
88
*/
99

1010
/**
@@ -465,6 +465,12 @@ class ReactNativeFeatureFlagsJavaProvider
465465
return method(javaProvider_);
466466
}
467467

468+
bool useSharedAnimatedBackend() override {
469+
static const auto method =
470+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useSharedAnimatedBackend");
471+
return method(javaProvider_);
472+
}
473+
468474
bool useTurboModuleInterop() override {
469475
static const auto method =
470476
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useTurboModuleInterop");
@@ -854,6 +860,11 @@ bool JReactNativeFeatureFlagsCxxInterop::useShadowNodeStateOnClone(
854860
return ReactNativeFeatureFlags::useShadowNodeStateOnClone();
855861
}
856862

863+
bool JReactNativeFeatureFlagsCxxInterop::useSharedAnimatedBackend(
864+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
865+
return ReactNativeFeatureFlags::useSharedAnimatedBackend();
866+
}
867+
857868
bool JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop(
858869
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
859870
return ReactNativeFeatureFlags::useTurboModuleInterop();
@@ -1123,6 +1134,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
11231134
makeNativeMethod(
11241135
"useShadowNodeStateOnClone",
11251136
JReactNativeFeatureFlagsCxxInterop::useShadowNodeStateOnClone),
1137+
makeNativeMethod(
1138+
"useSharedAnimatedBackend",
1139+
JReactNativeFeatureFlagsCxxInterop::useSharedAnimatedBackend),
11261140
makeNativeMethod(
11271141
"useTurboModuleInterop",
11281142
JReactNativeFeatureFlagsCxxInterop::useTurboModuleInterop),

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<ad2e322ef177ced7eb07412552596a5b>>
7+
* @generated SignedSource<<2d4ccbeed5ffafd40715357ff98d83b1>>
88
*/
99

1010
/**
@@ -243,6 +243,9 @@ class JReactNativeFeatureFlagsCxxInterop
243243
static bool useShadowNodeStateOnClone(
244244
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
245245

246+
static bool useSharedAnimatedBackend(
247+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
248+
246249
static bool useTurboModuleInterop(
247250
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
248251

packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<f01f3d1a08880a7fa9d3490e6bd9c61a>>
7+
* @generated SignedSource<<287689f62d05f2d27c146856b7857010>>
88
*/
99

1010
/**
@@ -310,6 +310,10 @@ bool ReactNativeFeatureFlags::useShadowNodeStateOnClone() {
310310
return getAccessor().useShadowNodeStateOnClone();
311311
}
312312

313+
bool ReactNativeFeatureFlags::useSharedAnimatedBackend() {
314+
return getAccessor().useSharedAnimatedBackend();
315+
}
316+
313317
bool ReactNativeFeatureFlags::useTurboModuleInterop() {
314318
return getAccessor().useTurboModuleInterop();
315319
}

0 commit comments

Comments
 (0)